class BreadcrumbsOnRails::Breadcrumbs::Builder

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:

Public Class Methods

new(context, elements, options = {}) click to toggle source

Initializes a new Builder with context, element and options.

@param [ActionView::Base] context The view context. @param [Array<Element>] elements The collection of Elements. @param [Hash] options Hash of options to customize the rendering behavior.

# File lib/breadcrumbs_on_rails/breadcrumbs.rb, line 29
def initialize(context, elements, options = {})
  @context  = context
  @elements = elements
  @options  = options
end

Public Instance Methods

render() click to toggle source

Renders Elements and returns the Breadcrumb navigation for the view.

@return [String] The result of the breadcrumb rendering.

@abstract You must implement this method in your custom Builder.

# File lib/breadcrumbs_on_rails/breadcrumbs.rb, line 40
def render
  raise NotImplementedError
end

Protected Instance Methods

compute_name(element) click to toggle source
# File lib/breadcrumbs_on_rails/breadcrumbs.rb, line 47
def compute_name(element)
  case name = element.name
  when Symbol
    @context.send(name)
  when Proc
    name.call(@context)
  else
    name.to_s
  end
end
compute_path(element) click to toggle source
# File lib/breadcrumbs_on_rails/breadcrumbs.rb, line 58
def compute_path(element)
  case path = element.path
  when Symbol
    @context.send(path)
  when Proc
    path.call(@context)
  else
    @context.url_for(path)
  end
end