Module: Vident::BetterHtml::RootComponent
- Defined in:
- lib/vident/better_html/root_component.rb
Instance Method Summary collapse
-
#as_targets(*targets) ⇒ Object
(also: #as_target)
Return the HTML ‘data-target` attribute for the given targets.
-
#with_actions(*actions_to_set) ⇒ Object
(also: #with_action)
Return the HTML ‘data-action` attribute for the given actions.
-
#with_controllers(*controllers_to_set) ⇒ Object
Return the HTML ‘data-controller` attribute for the given controllers.
Instance Method Details
#as_targets(*targets) ⇒ Object Also known as: as_target
Return the HTML ‘data-target` attribute for the given targets
15 16 17 18 19 20 |
# File 'lib/vident/better_html/root_component.rb', line 15 def as_targets(*targets) attrs = build_target_data_attributes(parse_targets(targets)) # For some reason better_html attributes are not considered safe buffers, to we need to mark as such to avoid # escaping the resulting HTML which should already be valid. helpers.html_attributes(attrs.transform_keys! { |k| "data-#{k}" }).to_s.html_safe end |
#with_actions(*actions_to_set) ⇒ Object Also known as: with_action
Return the HTML ‘data-action` attribute for the given actions
24 25 26 27 |
# File 'lib/vident/better_html/root_component.rb', line 24 def with_actions(*actions_to_set) actions_str = action_list(actions_to_set) actions_str.present? ? helpers.html_attributes("data-action" => actions_str).to_s.html_safe : nil end |
#with_controllers(*controllers_to_set) ⇒ Object
Return the HTML ‘data-controller` attribute for the given controllers
10 11 12 |
# File 'lib/vident/better_html/root_component.rb', line 10 def with_controllers(*controllers_to_set) helpers.html_attributes("data-controller" => controller_list(controllers_to_set)&.html_safe).to_s.html_safe end |