Module: Stimul8::Component::Core
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/stimul8/component/core.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#component(component_class, properties = {}, &contents) ⇒ Object
(also: #c)
standard:disable Style/ArgumentsForwarding.
- #component_class ⇒ Object
- #component_id ⇒ Object
- #contents ⇒ Object
- #context ⇒ Object
- #css_class ⇒ Object
- #expanded_attributes ⇒ Object
- #render? ⇒ Boolean
- #stylesheet ⇒ Object
- #tag_name ⇒ Object
- #template ⇒ Object
- #to_html ⇒ Object
Instance Method Details
#==(other) ⇒ Object
135 136 137 |
# File 'lib/stimul8/component/core.rb', line 135 def == other other.component_id == component_id end |
#component(component_class, properties = {}, &contents) ⇒ Object Also known as: c
standard:disable Style/ArgumentsForwarding
97 98 99 |
# File 'lib/stimul8/component/core.rb', line 97 def component(component_class, properties = {}, &contents) # standard:disable Style/ArgumentsForwarding Stimul8::Component.component(component_class, properties, &contents) # standard:disable Style/ArgumentsForwarding end |
#component_class ⇒ Object
77 78 79 |
# File 'lib/stimul8/component/core.rb', line 77 def component_class @component_class ||= self.class.name.underscore.dasherize.gsub("/", "--") end |
#component_id ⇒ Object
73 74 75 |
# File 'lib/stimul8/component/core.rb', line 73 def component_id @component_id ||= SecureRandom.uuid end |
#contents ⇒ Object
89 90 91 |
# File 'lib/stimul8/component/core.rb', line 89 def contents @contents&.call.to_s end |
#context ⇒ Object
93 94 95 |
# File 'lib/stimul8/component/core.rb', line 93 def context @context.freeze end |
#css_class ⇒ Object
81 82 83 |
# File 'lib/stimul8/component/core.rb', line 81 def css_class [component_class, @attributes[:class]].compact.join(" ") end |
#expanded_attributes ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/stimul8/component/core.rb', line 118 def return @expanded_attributes unless @expanded_attributes.nil? @expanded_attributes = @attributes.except(:class) @expanded_attributes[:data] ||= {} controller = ["stimul8", @expanded_attributes[:data][:controller]].compact.join(" ") @expanded_attributes[:data][:controller] = controller @expanded_attributes[:data][:stimul8_class_name_value] = self.class.name @expanded_attributes = @expanded_attributes.transform_keys do |key| key.to_s.dasherize.to_sym end end |
#render? ⇒ Boolean
131 132 133 |
# File 'lib/stimul8/component/core.rb', line 131 def render? self.class.render_if_block.nil? || instance_eval(&self.class.render_if_block) end |
#stylesheet ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/stimul8/component/core.rb', line 106 def stylesheet return @stylesheet unless @stylesheet.blank? @stylesheet = self.class.styles.map do |selector, rules| selection_rule = ".#{component_class} #{selector} {\n" rules.each do |rule| selection_rule += " #{rule}\n" end selection_rule += "}" selection_rule end.join("\n") end |
#tag_name ⇒ Object
102 103 104 |
# File 'lib/stimul8/component/core.rb', line 102 def tag_name @tag_name ||= self.class.tag_name || :div end |
#template ⇒ Object
85 86 87 |
# File 'lib/stimul8/component/core.rb', line 85 def template self.class.template_block end |