Module: Loaf::ViewExtensions

Includes:
CrumbFormatter, OptionsValidator
Defined in:
lib/loaf/view_extensions.rb

Overview

A mixin to define view extensions

Instance Method Summary collapse

Methods included from OptionsValidator

#valid?

Methods included from CrumbFormatter

#format_name

Instance Method Details

Adds breadcrumbs inside view.

Parameters:

  • name (String)

    the breadcrumb name

  • url (Object)

    the breadcrumb url

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

    the breadcrumb options



36
37
38
# File 'lib/loaf/view_extensions.rb', line 36

def breadcrumb(name, url, options = {})
  _breadcrumbs << Loaf::Crumb.new(name, url, options)
end

Renders breadcrumbs inside view.

Parameters:

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


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/loaf/view_extensions.rb', line 46

def breadcrumbs(options = {}, &block)
  # builder = Loaf::Builder.new(options)
  return enum_for(:breadcrumbs) unless block_given?
  valid?(options)
  options = Loaf.configuration.to_hash.merge(options)
  _breadcrumbs.each do |crumb|
    name   = format_name(crumb.name, options)
    url    = url_for(_process_url_for(crumb.url))
    styles = ''
    if current_page?(url) || crumb.force
      styles << "#{options[:style_classes]}"
    end
    block.call(name, url, styles)
  end
end

Checks to see if any breadcrumbs have been added

Returns:

  • (Boolean)


22
23
24
# File 'lib/loaf/view_extensions.rb', line 22

def breadcrumbs?
  _breadcrumbs.present?
end

#initializeObject



12
13
14
15
# File 'lib/loaf/view_extensions.rb', line 12

def initialize(*)
  @_breadcrumbs ||= []
  super
end