Module: BreadcrumbTrail::ActionController::HelperMethods

Defined in:
lib/breadcrumb_trail/action_controller.rb

Overview

This is both included in the controller and used as a helper, so any methods defined here are usable in both the controller and in the views. These methods are the primary interface that the developer uses to define and render breadcrumbs.

Instance Method Summary collapse

Instance Method Details

This method returns an undefined value.

Define a breadcrumb with the given options. All of this information is passed directly to the Breadcrumb initializer.

Yields:

See Also:


45
46
47
# File 'lib/breadcrumb_trail/action_controller.rb', line 45

def breadcrumb(options, &block)
  breadcrumbs << Breadcrumb.new(**options, &block)
end

All of the defined breadcrumbs, in order.

Returns:


52
53
54
# File 'lib/breadcrumb_trail/action_controller.rb', line 52

def breadcrumbs
  @_breadcrumbs ||= []
end

#render_breadcrumbs(options = {}) { ... } ⇒ String

Renders the defined breadcrumbs, with the given options.

Parameters:

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

    The options that are passed to the builder to help render the breadcrumbs.

Options Hash (options):

  • :builder (Hash) — default: Builder

    The builder to use. If this isn't provided, a sensible default is used.

Yields:

Returns:

  • (String)

64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/breadcrumb_trail/action_controller.rb', line 64

def render_breadcrumbs(options = {}, &block)
  block_given = block_given?
  builder = options.fetch(:builder) do
    if block_given
      BlockBuilder
    else
      HTMLBuilder
    end
  end

  builder.new(self, breadcrumbs, options, &block).call
end