Class: Bulmacomp::MenuComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Bulmacomp::MenuComponent
- Defined in:
- app/components/bulmacomp/menu_component.rb
Overview
Make the html strucrure for a bulma menu
Instance Method Summary collapse
-
#call ⇒ String
Generate an html safe string with full bulma menu.
-
#first_level(values = []) ⇒ String
Generate a string with all bulma menu element from ‘values` param.
-
#initialize(elements: [], **opts) ⇒ MenuComponent
constructor
A new instance of MenuComponent.
-
#map_menu(values = []) ⇒ String
Generate a string with the “real” menu elements (no title) from ‘values’ param.
-
#sub_menu(values = []) ⇒ String
Generate a string with sub-menu content from values params.
Constructor Details
#initialize(elements: [], **opts) ⇒ MenuComponent
Returns a new instance of MenuComponent.
69 70 71 |
# File 'app/components/bulmacomp/menu_component.rb', line 69 def initialize(elements: [], **opts) @opts = { class: "menu" }.merge(opts) end |
Instance Method Details
#call ⇒ String
Generate an html safe string with full bulma menu.
75 76 77 |
# File 'app/components/bulmacomp/menu_component.rb', line 75 def call tag.aside first_level(@elements) + content, **@opts end |
#first_level(values = []) ⇒ String
Generate a string with all bulma menu element from ‘values` param.
Each element in ‘values` is mapped:
-
as ‘p.menu-title` tag if is not an Array
-
as #map_menu if is an Array
90 91 92 93 94 |
# File 'app/components/bulmacomp/menu_component.rb', line 90 def first_level(values = []) safe_join( values.map { |e| e.is_a?(Array) ? (e) : tag.p(e, class: "menu-label") } ) end |
#map_menu(values = []) ⇒ String
Generate a string with the “real” menu elements (no title) from ‘values’ param. The menu elements are incapsulated in a ul tag
Each element in ‘values’ is mapped:
-
as li tag if is not an Array
-
as #sub_menu if is an Array
108 109 110 |
# File 'app/components/bulmacomp/menu_component.rb', line 108 def (values = []) tag.ul safe_join(values.map { |e| e.is_a?(Array) ? (e) : tag.li(e) }) end |
#sub_menu(values = []) ⇒ String
Generate a string with sub-menu content from values params. The first array element is used as ancescor, other element are used to make the sub menu with #map_menu method.
121 122 123 |
# File 'app/components/bulmacomp/menu_component.rb', line 121 def (values = []) tag.li safe_join([ values.shift, (values) ]) end |