Class: Ariadne::BaseComponent
- Defined in:
- app/components/ariadne/base_component.rb
Overview
All Ariadne ViewComponents accept a standard set of options: classes, which match Tailwind CSS classes, and attributes, which match HTML attributes..
Under the hood, any-non class attributes is passed to Rails’ [tag](api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-tag) (for self-closing tags) or [content_tag](api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag).
Constant Summary collapse
- SELF_CLOSING_TAGS =
[:area, :base, :br, :col, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :wbr].freeze
Constants inherited from Component
Component::BASE_BODY_CLASSES, Component::BASE_HTML_CLASSES, Component::BASE_MAIN_CLASSES, Component::BASE_WRAPPER_CLASSES, Component::INVALID_ARIA_LABEL_TAGS
Constants included from ActionViewExtensions::FormHelper
ActionViewExtensions::FormHelper::DEFAULT_FORM_CLASSES
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::INTEGER_TYPES, FetchOrFallbackHelper::InvalidValueError, FetchOrFallbackHelper::TRUE_OR_FALSE
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(tag:, classes: "", attributes: {}) ⇒ BaseComponent
constructor
A new instance of BaseComponent.
Methods included from ActionViewExtensions::FormHelper
Methods included from ClassNameHelper
Methods included from LoggerHelper
#logger, #silence_deprecations?, #silence_warnings?
Methods included from FetchOrFallbackHelper
#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer
Constructor Details
#initialize(tag:, classes: "", attributes: {}) ⇒ BaseComponent
Returns a new instance of BaseComponent.
11 12 13 14 15 16 17 18 19 20 |
# File 'app/components/ariadne/base_component.rb', line 11 def initialize(tag:, classes: "", attributes: {}) @tag = tag @attributes = validate_attributes(tag: tag, attributes: attributes) || {} @attributes[:"data-ariadne-view-component"] = true classes = @attributes.fetch(:classes, "") if classes.blank? @classes = validate_class_names(classes) || {} @content_tag_args = {} end |
Instance Method Details
#call ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/components/ariadne/base_component.rb', line 22 def call = @attributes.merge(@classes) if SELF_CLOSING_TAGS.include?(@tag) tag(@tag, ) else content_tag(@tag, content, ) end end |