Module: Heartml::ClassMethods
- Defined in:
- lib/heartml.rb
Overview
Extends the component class
Instance Method Summary collapse
- #attribute_binding(matcher, method_name, only: nil) ⇒ Object
- #attribute_bindings ⇒ Object
- #camelcased(method_symbols) ⇒ Object
- #define(tag_name, heart_module = nil, shadow_root: true) ⇒ void
- #doc ⇒ Nokolexbor::Element
- #doc_html ⇒ String
- #heart_module(value = nil) ⇒ String
- #html_file_extensions ⇒ Object
- #output_tag_name(value = nil) ⇒ Object
- #shadow_root(value = nil) ⇒ Boolean
- #tag_name(value = nil) ⇒ String
Instance Method Details
#attribute_binding(matcher, method_name, only: nil) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/heartml.rb', line 143 def attribute_binding(matcher, method_name, only: nil) attribute_bindings << AttributeBinding.new( matcher: Regexp.new(matcher), method_name:, only_for_tag: only ) end |
#attribute_bindings ⇒ Object
141 |
# File 'lib/heartml.rb', line 141 def attribute_bindings = @attribute_bindings ||= [] |
#camelcased(method_symbols) ⇒ Object
75 76 77 78 79 |
# File 'lib/heartml.rb', line 75 def camelcased(method_symbols) Array(method_symbols).each do |method_symbol| alias_method(method_symbol.to_s.gsub(/(?!^)_[a-z0-9]/) { |match| match[1].upcase }, method_symbol) end end |
#define(tag_name, heart_module = nil, shadow_root: true) ⇒ void
This method returns an undefined value.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/heartml.rb', line 88 def define(tag_name, heart_module = nil, shadow_root: true) # rubocop:disable Metrics/AbcSize if heart_module.nil? && !respond_to?(:source_location) raise Heartml::Error, "You must either supply a file path argument or respond to `source_location'" end self.tag_name tag_name if heart_module self.heart_module heart_module else basepath = File.join(File.dirname(source_location), File.basename(source_location, ".*")) self.heart_module(html_file_extensions.lazy.filter_map do |ext| path = "#{basepath}.#{ext}" File.exist?(path) ? path : nil end.first) raise Heartml::Error, "Cannot find sidecar HTML module for `#{self}'" unless @heart_module end self.shadow_root shadow_root end |
#doc ⇒ Nokolexbor::Element
131 132 133 134 135 136 |
# File 'lib/heartml.rb', line 131 def doc @doc ||= begin @doc_html = "<#{tag_name}>#{File.read(heart_module).strip}</#{tag_name}>" Nokolexbor::DocumentFragment.parse(@doc_html).first_element_child end end |
#doc_html ⇒ String
139 |
# File 'lib/heartml.rb', line 139 def doc_html = @doc_html |
#heart_module(value = nil) ⇒ String
124 |
# File 'lib/heartml.rb', line 124 def heart_module(value = nil) = @heart_module ||= value |
#html_file_extensions ⇒ Object
81 |
# File 'lib/heartml.rb', line 81 def html_file_extensions = %w[module.html mod.html heartml].freeze |
#output_tag_name(value = nil) ⇒ Object
120 |
# File 'lib/heartml.rb', line 120 def output_tag_name(value = nil) = @output_tag_name ||= value |
#shadow_root(value = nil) ⇒ Boolean
128 |
# File 'lib/heartml.rb', line 128 def shadow_root(value = nil) = @shadow_root ||= value |
#tag_name(value = nil) ⇒ String
113 114 115 116 117 118 |
# File 'lib/heartml.rb', line 113 def tag_name(value = nil) @tag_name ||= begin Heartml.register_element self value end end |