lib/hot_module.rb in hot_module-1.0.0.alpha2 vs lib/hot_module.rb in hot_module-1.0.0.alpha3
- old
+ new
@@ -19,11 +19,11 @@
using JSTemplateLiterals
AttributeBinding = Struct.new(:matcher, :method_name, :method, :only_for_tag, keyword_init: true) # rubocop:disable Lint/StructNewOverride
require_relative "hot_module/fragment"
- # require_relative "hot_module/query_selection"
+ require_relative "hot_module/query_selection"
# @param klass [Class]
# @return [void]
def self.included(klass)
klass.extend ClassMethods
@@ -90,11 +90,11 @@
# @return [Nokogiri::XML::Element]
def doc
@doc ||= Nokolexbor::DocumentFragment.parse(
"<#{tag_name}>#{File.read(html_module).strip}</#{tag_name}>"
- ).children.find(&:element?)
+ ).element_children.first
end
def attribute_bindings
@attribute_bindings ||= []
end
@@ -124,21 +124,10 @@
# @param content [String, Nokogiri::XML::Element]
# @param return_node [Boolean]
def render_element(attributes: self.attributes, content: self.content, return_node: false) # rubocop:disable Metrics
doc = self.class.doc.clone
- # NOTE: have to fix cloned templates
- doc.css("template").each do |bad_tmpl|
- frag = bad_tmpl.children.last
- new_tmpl = doc.document.create_element("template")
- bad_tmpl.attributes.each do |k, v|
- new_tmpl[k] = v
- end
- new_tmpl.children[0].children = frag
- bad_tmpl.swap(new_tmpl)
- end
-
tmpl_el = doc.css("> template").find { _1.attributes.length.zero? }
unless tmpl_el
tmpl_el = doc.document.create_element("template")
immediate_children = doc.css("> :not(style):not(script)")
@@ -247,21 +236,9 @@
return unless list_items
_in_context_nodes do |previous_context|
list_items.each_with_index do |list_item, index|
new_node = item_node.clone
-
- # NOTE: have to fix cloned templates
- new_node.css("template").each do |bad_tmpl|
- frag = bad_tmpl.children.last
- new_tmpl = item_node.document.create_element("template")
- bad_tmpl.attributes.each do |k, v|
- new_tmpl[k] = v
- end
- new_tmpl.children[0].children = frag
- bad_tmpl.swap(new_tmpl)
- end
-
node.parent << new_node
new_node["hmod-added"] = ""
@_context_locals = { **(previous_context || {}) }
_context_locals[lh[0]] = list_item