Class: Vident::RootComponent::UsingPhlexHTML
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- Vident::RootComponent::UsingPhlexHTML
- Includes:
- Base, UsingBetterHTML
- Defined in:
- lib/vident/root_component/using_phlex_html.rb
Constant Summary collapse
- VALID_TAGS =
Set[ *(Phlex::HTML::VoidElements::REGISTERED_ELEMENTS.keys + Phlex::HTML::StandardElements::REGISTERED_ELEMENTS.keys) ].freeze
Instance Method Summary collapse
-
#target_tag(tag_name, targets, **options, &block) ⇒ Object
Create a tag for a target with a block containing content.
-
#template(&block) ⇒ Object
Build a tag with the attributes determined by this components properties and stimulus data attributes.
Methods included from UsingBetterHTML
#as_targets, #with_actions, #with_controllers
Methods included from Base
#action, #action_data_attribute, #as_targets, #initialize, #named_classes, #target, #target_data_attribute, #with_actions, #with_controllers
Instance Method Details
#target_tag(tag_name, targets, **options, &block) ⇒ Object
Create a tag for a target with a block containing content
19 20 21 22 23 24 |
# File 'lib/vident/root_component/using_phlex_html.rb', line 19 def target_tag(tag_name, targets, **, &block) parsed = parse_targets(Array.wrap(targets)) [:data] ||= {} [:data].merge!(build_target_data_attributes(parsed)) generate_tag(tag_name, **, &block) end |
#template(&block) ⇒ Object
Build a tag with the attributes determined by this components properties and stimulus data attributes.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vident/root_component/using_phlex_html.rb', line 28 def template(&block) # Generate tag options and render tag_type = @element_tag.presence&.to_sym || :div raise ArgumentError, "Unsupported HTML tag name #{tag_type}" unless VALID_TAGS.include?(tag_type) = @html_options&.dup || {} data_attrs = tag_data_attributes data_attrs = [:data].present? ? data_attrs.merge([:data]) : data_attrs = .merge(id: @id) if @id .except!(:data) .merge!(data_attrs.transform_keys { |k| "data-#{k}" }) generate_tag(tag_type, **, &block) end |