lib/hot_module.rb in hot_module-1.0.0.alpha9 vs lib/hot_module.rb in hot_module-1.0.0.alpha10
- old
+ new
@@ -90,15 +90,21 @@
@shadow_root ||= value
end
# @return [Nokogiri::XML::Element]
def doc
- @doc ||= Nokolexbor::DocumentFragment.parse(
- "<#{tag_name}>#{File.read(html_module).strip}</#{tag_name}>"
- ).element_children.first
+ @doc ||= begin
+ @doc_html = "<#{tag_name}>#{File.read(html_module).strip}</#{tag_name}>"
+ Nokolexbor::DocumentFragment.parse(@doc_html).first_element_child
+ end
end
+ def line_number_of_node(node)
+ loc = node.source_location
+ instance_variable_get(:@doc_html)[0..loc].count("\n") + 1
+ end
+
def attribute_bindings
@attribute_bindings ||= []
end
def attribute_binding(matcher, method_name, only: nil)
@@ -216,14 +222,11 @@
# Override in component if need be, otherwise we'll use the node walker/binding pipeline
#
# @param fragment [Nokogiri::XML::Element]
# @return [void]
def process_fragment(fragment)
- Fragment.new(
- fragment, self.class.attribute_bindings.each { _1.method = method(_1.method_name) },
- html_module: self.class.html_module
- ).process
+ Fragment.new(fragment, self).process
end
def process_list(attribute:, node:, item_node:, for_in:) # rubocop:disable Metrics
_context_nodes.push(node)
@@ -245,23 +248,20 @@
@_context_locals = { **(previous_context || {}) }
_context_locals[lh[0]] = list_item
_context_locals[lh[1]] = index if lh[1]
- Fragment.new(
- new_node, self.class.attribute_bindings,
- html_module: self.class.html_module
- ).process
+ Fragment.new(new_node, self).process
end
end
end
def evaluate_attribute_expression(attribute, eval_code = attribute.value)
eval_code = eval_code.gsub(/\${(.*)}/, "\#{\\1}")
_context_locals.keys.reverse_each do |name|
eval_code = "#{name} = _context_locals[\"#{name}\"];" + eval_code
end
- instance_eval(eval_code, self.class.html_module) # , attribute.line)
+ instance_eval(eval_code, self.class.html_module, self.class.line_number_of_node(attribute))
end
def class_list_for(obj)
case obj
when Hash