class InsertProcessor
Public Instance Methods
call(node:nil, attribute:nil, context:nil, **_)
click to toggle source
# File lib/thymeleaf/dialects/default/processors/insert.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.dup.parent = node end end
Private Instance Methods
get_fragment_node(fragment_name, context, node)
click to toggle source
# File lib/thymeleaf/dialects/default/processors/insert.rb, line 56 def get_fragment_node(fragment_name, context, node) root_context = context.root if root_context.has_private DefaultDialect::context_fragment_var(fragment_name) root_context.get_private DefaultDialect::context_fragment_var(fragment_name) else node.at_css fragment_name end end
get_node_template(template, node, context)
click to toggle source
# File lib/thymeleaf/dialects/default/processors/insert.rb, line 32 def get_node_template(template, node, context) if is_self_template? template root_node node else subtemplate = EvalExpression.parse(context, template) load_template subtemplate do |template_file| Thymeleaf::Parser.new(template_file).call end end end
is_self_template?(template)
click to toggle source
# File lib/thymeleaf/dialects/default/processors/insert.rb, line 52 def is_self_template?(template) template.nil? || (template.eql? 'this') end
root_node(node)
click to toggle source
# File lib/thymeleaf/dialects/default/processors/insert.rb, line 44 def root_node(node) new_node = node until new_node.parent.nil? new_node = new_node.parent end new_node end