Class: Breadcrumbs::Render::List

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

Overview

:nodoc: all

Direct Known Subclasses

OrderedList

Instance Attribute Summary

Attributes inherited from Base

#breadcrumbs, #default_options, #output_buffer

Instance Method Summary collapse

Methods inherited from Base

#initialize, #tag

Constructor Details

This class inherits a constructor from Breadcrumbs::Render::Base

Instance Method Details

#list_styleObject



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

def list_style
  :ul
end

#renderObject



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

def render
  options = {class: "breadcrumbs"}.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)
    end

    html.join.html_safe
  end
end

#render_item(item, i, size) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/breadcrumbs/render/list.rb', line 26

def render_item(item, i, size)
  css = []
  css << "first" if i.zero?
  css << "last" if i == size - 1
  css << "item-#{i}"

  text, url, options = *item
  text = wrap_item(url, text, options)
  tag(:li, text, class: css.join(" "))
end