Class: ReplaceProcessor

Inherits:
InsertProcessor show all
Includes:
Thymeleaf::Processor
Defined in:
lib/thymeleaf/dialects/default/processors/replace.rb

Instance Method Summary collapse

Methods included from Thymeleaf::Processor

#evaluate_in_context, #load_template, #subprocess_node

Instance Method Details

#call(node: nil, attribute: nil, context: nil, **_) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/thymeleaf/dialects/default/processors/replace.rb', line 8

def call(node:nil, attribute:nil, context:nil, **_)

  attribute.unlink

  template, fragment = FragmentExpression.parse(context, attribute.value)

  node_subcontent = get_node_template(template, node, context)

  node.children.each {|child| child.unlink }

  if fragment.nil?
    # Avoid infinite loop when template is "this" and fragment is nil
    return nil if is_self_template? template
  else
    node_subcontent = get_fragment_node(fragment, context, node_subcontent)
  end

  unless node_subcontent.nil?
    node_subcontent = node_subcontent.dup
    subprocess_node(context, node_subcontent)

    node.replace node_subcontent
  end
end