lib/heartml/fragment.rb in heartml-1.0.0.beta1 vs lib/heartml/fragment.rb in heartml-1.0.0.beta2
- old
+ new
@@ -44,22 +44,32 @@
attrs.reject! { |k| k.start_with?("server-") || k.start_with?("iso-") || k.start_with?("host-") }
attrs.transform_keys!(&:to_sym)
obj = component.new(**attrs)
render_output = if obj.respond_to?(:render_in)
- obj.render_in(@component.view_context, rendering_mode: :node) { node.children }
+ obj.render_in(@component.view_context, rendering_mode: :node) do
+ process(fragamatize(node.children))
+ end
else
- obj.render_element(content: node.children)
+ obj.render_element(content: process(fragamatize(node.children)))
end
node.replace(render_output)
end
process_attribute_bindings(node)
end
+
+ fragment
end
+ def fragamatize(node_set)
+ frag = Nokolexbor::DocumentFragment.new(@fragment.document)
+ node_set.each { |child| child.parent = frag }
+ frag
+ end
+
def process_attribute_bindings(node) # rubocop:todo Metrics
node.attributes.each do |name, attr_node|
@attribute_bindings.each do |attribute_binding|
next if attribute_binding.only_for_tag && node.name != attribute_binding.only_for_tag.to_s
next unless attribute_binding.matcher.match?(name)
@@ -67,10 +77,9 @@
break unless attribute_binding.method.(attribute: attr_node, node: node)
end
rescue Exception => e # rubocop:disable Lint/RescueException
line_segments = [@component.class.heart_module, @component.class.line_number_of_node(attr_node)]
- puts "here we go!"
raise e.class, e.message.lines.first, [line_segments.join(":"), *e.backtrace]
end
end
end
end