Module: Proscenium::UI::Breadcrumbs::Control

Extended by:
ActiveSupport::Concern
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
lib/proscenium/ui/breadcrumbs/control.rb

Overview

Include this module in your controller to add support for adding breadcrumb elements. You can then use the ‘add_breadcrumb` and `prepend_breadcrumb` class methods to append and/or prepend breadcrumb elements.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_breadcrumb(name, path = nil, options = {}) ⇒ Object

Pushes a new breadcrumb element into the collection.

Parameters:

  • name (String, Symbol, Proc, #for_breadcrumb)

    The name or content of the breadcrumb.

  • path (String, Symbol, Array, Proc, nil) (defaults to: nil)

    The path (route) to use as the HREF for the breadcrumb.

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


51
52
53
# File 'lib/proscenium/ui/breadcrumbs/control.rb', line 51

def add_breadcrumb(name, path = nil, options = {})
  breadcrumbs << Element.new(name, path, options)
end


65
66
67
# File 'lib/proscenium/ui/breadcrumbs/control.rb', line 65

def breadcrumbs
  @breadcrumbs ||= []
end


69
70
71
72
73
74
75
# File 'lib/proscenium/ui/breadcrumbs/control.rb', line 69

def breadcrumbs_as_json
  computed_breadcrumbs.map do |ele|
    path = ele.path

    { name: ele.name, path: ele.path.nil? || helpers.current_page?(path) ? nil : path }
  end
end

Parameters:

  • primary (Boolean) (defaults to: false)

    whether to return only the primary breadcrumb.



78
79
80
81
82
83
84
85
# File 'lib/proscenium/ui/breadcrumbs/control.rb', line 78

def breadcrumbs_for_title(primary: false)
  names = computed_breadcrumbs.map(&:name)
  return names.pop if primary

  out = [names.pop]
  out << names.join(': ') unless names.empty?
  strip_tags out.join(' - ')
end

#prepend_breadcrumb(name, path = nil, options = {}) ⇒ Object

Prepend a new breadcrumb element into the collection.

Parameters:

  • name (String, Symbol, Proc, #for_breadcrumb)

    The name or content of the breadcrumb.

  • path (String, Symbol, Array, Proc, nil) (defaults to: nil)

    The path (route) to use as the HREF for the breadcrumb.

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


61
62
63
# File 'lib/proscenium/ui/breadcrumbs/control.rb', line 61

def prepend_breadcrumb(name, path = nil, options = {})
  breadcrumbs.prepend Element.new(name, path, options)
end