Class: Bs5::Modal::ControllerComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Bs5::Modal::ControllerComponent
- Defined in:
- app/components/bs5/modal/controller_component.rb
Instance Method Summary collapse
- #actionable_element ⇒ Object
- #actionable_element? ⇒ Boolean
- #content ⇒ Object
-
#initialize(modal_id:) ⇒ ControllerComponent
constructor
A new instance of ControllerComponent.
- #set_actionable_element_attributes ⇒ Object
Constructor Details
#initialize(modal_id:) ⇒ ControllerComponent
Returns a new instance of ControllerComponent.
6 7 8 |
# File 'app/components/bs5/modal/controller_component.rb', line 6 def initialize(modal_id:) @modal_id = modal_id end |
Instance Method Details
#actionable_element ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/components/bs5/modal/controller_component.rb', line 26 def actionable_element @actionable_element ||= begin if (elements = Nokogiri::HTML::DocumentFragment.parse(@content).elements).one? && (element = elements.first).name.in?(%w[a button]) element end end end |
#actionable_element? ⇒ Boolean
35 36 37 |
# File 'app/components/bs5/modal/controller_component.rb', line 35 def actionable_element? !!actionable_element end |
#content ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'app/components/bs5/modal/controller_component.rb', line 10 def content return nil if @content.blank? if actionable_element? set_actionable_element_attributes actionable_element.to_html.html_safe # rubocop:disable Rails/OutputSafety else @content end end |
#set_actionable_element_attributes ⇒ Object
21 22 23 24 |
# File 'app/components/bs5/modal/controller_component.rb', line 21 def set_actionable_element_attributes actionable_element['data-bs-toggle'] = 'modal' actionable_element['data-bs-target'] = "##{@modal_id}" end |