Class: Breadcrumbs::Render::Inline

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

Overview

:nodoc: all

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

#renderObject



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

def render
  options = {
    class: "breadcrumbs",
    separator: "»"
  }.merge(default_options)

  html = []
  items = breadcrumbs.items
  size = items.size

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

  separator = tag(:span, options[:separator], class: "separator")

  html.join(" #{separator} ").html_safe
end

#render_item(item, i, size) ⇒ Object



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

def render_item(item, i, size)
  text, url, options = *item

  css = [options[:class]].compact
  css << "first" if i.zero?
  css << "last" if i == size - 1
  css << "item-#{i}"

  options[:class] = css.join(" ")
  options[:class].gsub!(/^ *(.*?)$/, '\\1')

  wrap_item(url, text, options)
end