lib/hot_module.rb in hot_module-1.0.0.alpha3 vs lib/hot_module.rb in hot_module-1.0.0.alpha4

- old
+ new

@@ -124,11 +124,11 @@ # @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 - tmpl_el = doc.css("> template").find { _1.attributes.length.zero? } + tmpl_el = doc.css("> template").find { _1.attributes.empty? } unless tmpl_el tmpl_el = doc.document.create_element("template") immediate_children = doc.css("> :not(style):not(script)") tmpl_el.children[0] << immediate_children @@ -298,7 +298,30 @@ def _in_context_nodes previous_context = _context_locals yield previous_context @_context_locals = previous_context + end +end + +if defined?(Bridgetown) + Bridgetown.initializer :hot_module do |config| + Bridgetown::Component.extend ActiveSupport::DescendantsTracker + + HoTModuLe.module_eval do + def render_in(*) + @attributes&.[]=("hmod:ignore", "") + super + end + end + + # Eager load all components + hook :site, :after_reset do |site| + unless site.config.eager_load_paths.find { _1.end_with?(site.config.components_dir) } + site.config.eager_load_paths << site.config.autoload_paths.find { _1.end_with?(site.config.components_dir) } + end + end + + require_relative "hot_module/component_renderer" + config.builder HoTModuLe::ComponentRenderer end end