Module: Well::Component Abstract
Overview
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
-
#compiled_identifier ⇒ Object
abstract
Must be implemented by composing classes.
-
#element(*args, &content) ⇒ Element
DSL method used to add a nested element in the context of self.
-
#evaluate { ... } ⇒ String
Used by the DSL to build nested BEM components.
-
#modified_identifier ⇒ String
Adds BEM modifier if provided.
-
#modifier ⇒ String
Extracts BEM modifier from options.
-
#other_classes ⇒ Array<String>
Extracts other non-BEM CSS classes from options.
-
#output_buffer ⇒ ActionView::OutputBuffer
Must be defined since many methods from ActionView::Helpers.
-
#output_classes ⇒ Array<String>
Combines all CSS classes for output.
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
11 12 13 |
# File 'lib/well/component.rb', line 11 def identifier @identifier end |
Instance Method Details
#compiled_identifier ⇒ Object
Must be implemented by composing classes.
50 51 52 |
# File 'lib/well/component.rb', line 50 def compiled_identifier raise NotImplementedError end |
#element(*args, &content) ⇒ Element
DSL method used to add a nested element in the context of self. Both block and element components may contain further nested elements.
64 65 66 |
# File 'lib/well/component.rb', line 64 def element(*args, &content) Element.new(base, *args).evaluate(&content) end |
#evaluate { ... } ⇒ String
Used by the DSL to build nested BEM components.
43 44 45 46 |
# File 'lib/well/component.rb', line 43 def evaluate(&content) result = instance_eval(&content) if block_given? content_tag(@tag_name, result, class: output_classes) end |
#modified_identifier ⇒ String
Adds BEM modifier if provided.
56 57 58 59 |
# File 'lib/well/component.rb', line 56 def modified_identifier return unless modifier "#{compiled_identifier}#{Well.config.modifier_separator}#{modifier}" end |
#modifier ⇒ String
Extracts BEM modifier from options.
22 23 24 |
# File 'lib/well/component.rb', line 22 def modifier @modifier ||= @opts[:modifier] end |
#other_classes ⇒ Array<String>
Extracts other non-BEM CSS classes from options.
28 29 30 |
# File 'lib/well/component.rb', line 28 def other_classes @other_classes ||= @opts.fetch(:class) { [] } end |
#output_buffer ⇒ ActionView::OutputBuffer
Must be defined since many methods from ActionView::Helpers. expect to be able to write to an ActionView::OutputBuffer.
16 17 18 |
# File 'lib/well/component.rb', line 16 def output_buffer @output_buffer ||= ActionView::OutputBuffer.new end |
#output_classes ⇒ Array<String>
Combines all CSS classes for output.
34 35 36 37 38 |
# File 'lib/well/component.rb', line 34 def output_classes @output_classes ||= ( (other_classes << compiled_identifier << modified_identifier).compact ) end |