Class: Ramenu::Menus::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/ramenu/menus.rb

Overview

The Builder class represents the abstract class for any custom Builder.

To create a custom Builder, just extend this class and implement the following abstract methods:

  • #render: Renders and returns the collection of navigation elements

Direct Known Subclasses

SimpleBuilder

Instance Method Summary collapse

Constructor Details

#initialize(context, elements, options = {}) ⇒ Builder

Initializes a new Builder with context, element and options.

Parameters:

  • context (ActionView::Base)

    The view context.

  • elements (Array<Element>)

    The collection of Elements.

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

    Hash of options to customize the rendering behavior.



21
22
23
24
25
# File 'lib/ramenu/menus.rb', line 21

def initialize(context, elements, options = {})
  @context  = context
  @elements = elements
  @options  = options
end

Instance Method Details

#flag_for(element, option = :flag) ⇒ Object

get flag associated to element



37
38
39
40
41
42
43
44
# File 'lib/ramenu/menus.rb', line 37

def flag_for(element, option = :flag)
  flag = nil
  flag_selector = element.options[option]
  unless flag_selector.nil?
    flag = @options[:flags][flag_selector] if @options[:flags].include?(flag_selector)
  end
  return flag
end

#renderString

This method is abstract.

You must implement this method in your custom Builder.

Renders Elements and returns the Breadcrumb navigation for the view.

Returns:

  • (String)

    The result of the menu rendering.

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/ramenu/menus.rb', line 32

def render
  raise NotImplementedError
end