Class: Vident::RootComponent::UsingPhlexHTML
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- Vident::RootComponent::UsingPhlexHTML
- Includes:
- Base
- Defined in:
- lib/vident/root_component/using_phlex_html.rb
Constant Summary collapse
- VALID_TAGS =
Set[*(Phlex::HTML::VOID_ELEMENTS.keys + Phlex::HTML::STANDARD_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 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
14 15 16 17 18 19 |
# File 'lib/vident/root_component/using_phlex_html.rb', line 14 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.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vident/root_component/using_phlex_html.rb', line 23 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 |