Class: Bs5::ListGroupComponent::Item
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Bs5::ListGroupComponent::Item
- Defined in:
- app/components/bs5/list_group_component.rb
Constant Summary collapse
- CLASS_NAME_BASE =
'list-group-item'
- CLASS_NAME_ACTION =
"#{CLASS_NAME_BASE}-action"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #actionable? ⇒ Boolean
- #actionable_element ⇒ Object
- #call ⇒ Object
- #decorated_content ⇒ Object
-
#initialize(options = {}) ⇒ Item
constructor
A new instance of Item.
Constructor Details
#initialize(options = {}) ⇒ Item
Returns a new instance of Item.
60 61 62 63 64 65 66 67 68 |
# File 'app/components/bs5/list_group_component.rb', line 60 def initialize( = {}) @options = .symbolize_keys @active = @options.delete(:active) || false @disabled = @options.delete(:disabled) || false @color = @options.delete(:color) set_attributes end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
58 59 60 |
# File 'app/components/bs5/list_group_component.rb', line 58 def @options end |
Instance Method Details
#actionable? ⇒ Boolean
74 75 76 |
# File 'app/components/bs5/list_group_component.rb', line 74 def actionable? !!actionable_element end |
#actionable_element ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'app/components/bs5/list_group_component.rb', line 78 def actionable_element @actionable_element ||= begin if (elements = Nokogiri::HTML::DocumentFragment.parse(content).elements).one? && (element = elements.first).name.in?(%w[a button label]) element end end end |
#call ⇒ Object
70 71 72 |
# File 'app/components/bs5/list_group_component.rb', line 70 def call actionable? ? decorated_content : content end |
#decorated_content ⇒ Object
87 88 89 90 |
# File 'app/components/bs5/list_group_component.rb', line 87 def decorated_content set_actionable_element_attributes actionable_element.to_html.html_safe # rubocop:disable Rails/OutputSafety end |