Class: BreadcrumbTrail::HTMLBuilder

Inherits:
Builder
  • Object
show all
Includes:
ActionView::Helpers
Defined in:
lib/breadcrumb_trail/builder.rb

Overview

Creates a structure of HTML elements to render the breadcrumbs.

Instance Method Summary collapse

Methods inherited from Builder

#initialize

Constructor Details

This class inherits a constructor from BreadcrumbTrail::Builder

Instance Method Details

#callString

Renders the breadcrumbs in HTML tags. If no options were provided on initialization, it uses defaults.

Parameters:

  • @options (Hash)

    a customizable set of options

Returns:

  • (String)

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/breadcrumb_trail/builder.rb', line 72

def call
  outer_tag = @options.fetch(:outer, "ol")
  inner_tag = @options.fetch(:inner, "li")
  outer = tag(outer_tag,
              @options.fetch(:outer_options, nil),
              true) if outer_tag
  inner = tag(inner_tag,
              @options.fetch(:inner_options, nil),
              true) if inner_tag

  buffer = ActiveSupport::SafeBuffer.new
  buffer.safe_concat(outer) if outer_tag

  @breadcrumbs.each do |breadcrumb|
    buffer.safe_concat(inner) if inner_tag
    buffer << link_to(breadcrumb.computed_name(@context),
                      breadcrumb.computed_path(@context),
                      breadcrumb.options)
    buffer.safe_concat("</#{inner_tag}>") if inner_tag
  end

  buffer.safe_concat("</#{outer_tag}>") if outer_tag
  buffer
end