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 72 73 |
# File 'app/components/bulmacomp/menu_component.rb', line 69 def initialize(elements: [], **opts) super @elements = elements @opts = { class: 'menu' }.merge(opts) end |
Instance Method Details
#call ⇒ String
Generate an html safe string with full bulma menu.
77 78 79 |
# File 'app/components/bulmacomp/menu_component.rb', line 77 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
92 93 94 95 96 |
# File 'app/components/bulmacomp/menu_component.rb', line 92 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
110 111 112 |
# File 'app/components/bulmacomp/menu_component.rb', line 110 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.
123 124 125 |
# File 'app/components/bulmacomp/menu_component.rb', line 123 def (values = []) tag.li safe_join([values.shift, (values)]) end |