class RemoveProcessor

Constants

REMOVE_ALL
REMOVE_ALL_BUT_FIRST
REMOVE_BODY
REMOVE_NONE
REMOVE_TAG

Public Instance Methods

call(node:nil, attribute:nil, context:nil, **_) click to toggle source
# File lib/thymeleaf/dialects/default/processors/remove.rb, line 13
def call(node:nil, attribute:nil, context:nil, **_)
  attribute.unlink
  
  expr = EvalExpression.parse(context, attribute.value)
  
  method = case expr
             when REMOVE_ALL
               :remove_all
             when REMOVE_BODY
               :remove_body
             when REMOVE_TAG
               :remove_tag
             when REMOVE_ALL_BUT_FIRST
               :remove_allbutfirst
             when REMOVE_NONE
               :remove_none
             else
               if booleanize expr
                 :remove_all
               else
                 :remove_none
               end
             end
  
  send(method, node, context)
end

Private Instance Methods

empty_node?(node) click to toggle source
# File lib/thymeleaf/dialects/default/processors/remove.rb, line 71
def empty_node?(node)
  node.to_s.strip.empty?
end
remove_all(node, _) click to toggle source
# File lib/thymeleaf/dialects/default/processors/remove.rb, line 41
def remove_all(node, _)
  node.children.each do |child|
    child.unlink
  end
  node.unlink
end
remove_allbutfirst(node, _) click to toggle source
# File lib/thymeleaf/dialects/default/processors/remove.rb, line 62
def remove_allbutfirst(node, _)
  skip_first(node.children) do |child|
    child.unlink
  end
end
remove_body(node, _) click to toggle source
# File lib/thymeleaf/dialects/default/processors/remove.rb, line 48
def remove_body(node, _)
  node.children.each do |child|
    child.unlink
  end
end
remove_none(_, _) click to toggle source
# File lib/thymeleaf/dialects/default/processors/remove.rb, line 68
def remove_none(_, _)
end
remove_tag(node, context) click to toggle source
# File lib/thymeleaf/dialects/default/processors/remove.rb, line 54
def remove_tag(node, context)
  node.children.reverse.each do |child|
    subprocess_node(context, child)
    node.add_next_sibling child
  end
  node.unlink
end
skip_first(node_set) { |child| ... } click to toggle source
# File lib/thymeleaf/dialects/default/processors/remove.rb, line 75
def skip_first(node_set)
  i = 0
  node_set.each do |child|
    if i > 0
      yield child
    else
      i += 1 unless empty_node? child
    end
  end
end