module BreadcrumbsRails::ActionController::HelperMethods

Helper Methods


Public Instance Methods

render_breadcrumbs(options = {}) { |breadcrumbs_gem| ... } click to toggle source
# File lib/breadcrumbs_rails/action_controller.rb, line 84
def render_breadcrumbs(options = {}, &block)
  format = (options[:format] || :html).to_sym

  if block_given?
    yield(breadcrumbs_gem)
  else

    case format

      when :html
        content_tag(:ul) do
          breadcrumbs_gem[:breadcrumbs].map do |breadcrumb|
            concat content_tag(:li, breadcrumbs_name_or_link(breadcrumbs_gem, breadcrumb))
          end
        end

      when :bootstrap
        content_tag(:ul, class: 'pagination') do
          breadcrumbs_gem[:breadcrumbs].map do |breadcrumb|
            concat content_tag(:li, breadcrumbs_name_or_link(breadcrumbs_gem, breadcrumb))
          end
        end

      when :inspinia
        html = ''
        html << '<div class="row wrapper border-bottom white-bg page-heading">'
        html << '  <div class="col-lg-9">'
        html << (render_breadcrumbs_title ? "<h2>#{render_breadcrumbs_title}</h2>" : '<br/>')
        html << '    <ol class="breadcrumb">'

        breadcrumbs_gem[:breadcrumbs].each_with_index do |breadcrumb, index|
          if (index + 1) == breadcrumbs_gem[:breadcrumbs].length
            html << "<li class='active'><strong>#{breadcrumbs_name_or_link(breadcrumbs_gem, breadcrumb)}</strong></li>"
          else
            html << "<li>#{breadcrumbs_name_or_link(breadcrumbs_gem, breadcrumb)}</li>"
          end
        end

        html << '    </ol>'
        html << '  </div>'
        html << '</div>'
        html.html_safe

      else
        raise "Breadcrumbs-rails: unknown format '#{format.to_s}'"
    end

  end
end
render_breadcrumbs_title(default = nil) click to toggle source
# File lib/breadcrumbs_rails/action_controller.rb, line 72
def render_breadcrumbs_title(default = nil)
  return default if breadcrumbs_gem[:breadcrumbs].last[:title].nil?
  return ''      if breadcrumbs_gem[:breadcrumbs].last[:title].to_s.blank?

  if breadcrumbs_gem[:localize]
    I18n.t(breadcrumbs_gem[:breadcrumbs].last[:title])
  else
    breadcrumbs_gem[:breadcrumbs].last[:title]
  end
end

Private Instance Methods