Class: Navtastic::Renderer
- Inherits:
-
Arbre::Context
- Object
- Arbre::Context
- Navtastic::Renderer
- Defined in:
- lib/navtastic/renderer.rb,
lib/navtastic/renderer/bulma.rb,
lib/navtastic/renderer/simple.rb,
lib/navtastic/renderer/bootstrap4.rb,
lib/navtastic/renderer/foundation6.rb
Overview
Generate HTML based on a menu.
This base renderer only generates a structure and no css classes.
The actual HTML generation is done using the Arbre gem.
Calling #to_s will return the HTML.
Direct Known Subclasses
Defined Under Namespace
Classes: Bootstrap4, Bulma, Foundation6, Simple
Class Method Summary collapse
-
.render(menu, options = {}) ⇒ Self
Create a new renderer.
Instance Method Summary collapse
-
#item_content(item) ⇒ Arbre::HTML::Tag
The item itself (e.g.
<a>tag for links or<span>for text). -
#item_tag(item) ⇒ Arbre::HTML::Tag
The container for every menu item (e.g.
<li>tags). -
#menu_inside_container?(item) ⇒ bool
Check if a submenu should be displayed inside the item container of after it.
-
#menu_tag(menu) ⇒ Arbre::HTML::Tag
Start a new root menu or submenu (e.g.
<ul>tag).
Class Method Details
.render(menu, options = {}) ⇒ Self
Create a new renderer
19 20 21 22 23 |
# File 'lib/navtastic/renderer.rb', line 19 def self.render(, = {}) new(root: , options: ) do (root) end end |
Instance Method Details
#item_content(item) ⇒ Arbre::HTML::Tag
The item itself (e.g. <a> tag for links or <span> for text)
45 46 47 48 49 50 51 |
# File 'lib/navtastic/renderer.rb', line 45 def item_content(item) if item.url a(href: item.url) { item.name } else span { item.name } end end |
#item_tag(item) ⇒ Arbre::HTML::Tag
The container for every menu item (e.g. <li> tags)
37 38 39 |
# File 'lib/navtastic/renderer.rb', line 37 def item_tag(item) # rubocop:disable Lint/UnusedMethodArgument li { yield } end |
#menu_inside_container?(item) ⇒ bool
Check if a submenu should be displayed inside the item container of after it.
Defaults to true.
60 61 62 |
# File 'lib/navtastic/renderer.rb', line 60 def (item) # rubocop:disable Lint/UnusedMethodArgument true end |
#menu_tag(menu) ⇒ Arbre::HTML::Tag
Start a new root menu or submenu (e.g. <ul> tag)
29 30 31 |
# File 'lib/navtastic/renderer.rb', line 29 def () # rubocop:disable Lint/UnusedMethodArgument ul { yield } end |