Class: Navtastic::Renderer

Inherits:
Arbre::Context
  • Object
show all
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

Bootstrap4, Bulma, Foundation6, Simple

Defined Under Namespace

Classes: Bootstrap4, Bulma, Foundation6, Simple

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.render(menu, options = {}) ⇒ Self

Create a new renderer

Parameters:

  • menu (Menu)
  • options (Hash) (defaults to: {})

Returns:

  • (Self)


19
20
21
22
23
# File 'lib/navtastic/renderer.rb', line 19

def self.render(menu, options = {})
  new(root: menu, options: options) do
    render_menu(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)

Parameters:

Returns:

  • (Arbre::HTML::Tag)


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)

Parameters:

Returns:

  • (Arbre::HTML::Tag)


37
38
39
# File 'lib/navtastic/renderer.rb', line 37

def item_tag(item) # rubocop:disable Lint/UnusedMethodArgument
  li { yield }
end

Check if a submenu should be displayed inside the item container of after it.

Defaults to true.

Parameters:

Returns:

  • (bool)


60
61
62
# File 'lib/navtastic/renderer.rb', line 60

def menu_inside_container?(item) # rubocop:disable Lint/UnusedMethodArgument
  true
end

Start a new root menu or submenu (e.g. <ul> tag)

Parameters:

Returns:

  • (Arbre::HTML::Tag)


29
30
31
# File 'lib/navtastic/renderer.rb', line 29

def menu_tag(menu) # rubocop:disable Lint/UnusedMethodArgument
  ul { yield }
end