Class: Breadcrumbs::Render::List

Inherits:
Base
  • Object
show all
Defined in:
lib/breadcrumbs/render/list.rb

Overview

:nodoc: all

Instance Method Summary collapse

Instance Method Details

#list_styleObject



21
22
23
# File 'lib/breadcrumbs/render/list.rb', line 21

def list_style
  :ul
end

#renderObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/breadcrumbs/render/list.rb', line 4

def render
  options = {:class => "breadcrumb", :separator => "/"}.merge(default_options)

  tag(list_style, options) do
    html = ""
    items = breadcrumbs.items
    size = items.size

    items.each_with_index do |item, i|
      html << render_item(item, i, size, options)
    end


    html
  end
end

#render_item(item, i, size, opts) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/breadcrumbs/render/list.rb', line 25

def render_item(item, i, size, opts)
  css    = "active" if i == size - 1
  length = breadcrumbs.items.length - 1

  text, url, options = *item

  # If the item is the last, doesn't wrap with <a>
  if i < length
    text = wrap_item(url, CGI.escapeHTML(text), options)
  else
    text = CGI.escapeHTML text
  end

  # If the item is not last, add divider
  if i < length
    text += tag(:span, opts[:separator], :class => "divider")
  end

  tag(:li, text, :class => css)
end