Class: Caboose::Crumbtrail

Inherits:
Object
  • Object
show all
Defined in:
app/models/caboose/crumbtrail.rb

Instance Method Summary collapse

Instance Method Details

#add(url, text = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'app/models/caboose/crumbtrail.rb', line 6

def add(url, text = nil)
  @_crumbtrail = [] if @_crumbtrail.nil?
  if url.is_a?(Hash)
    url.each do |url2, text2|
      @_crumbtrail << [url2, text2]
    end
  else
    @_crumbtrail << [url, text]
  end
end


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/caboose/crumbtrail.rb', line 17

def print(url = nil, text = nil)
  if url
    self.add(url, text)
  end
  
  str = "<ul id='crumbtrail'>"
  count = @_crumbtrail.count
  @_crumbtrail.each_with_index do |arr, i|
    is_last = i == (count - 1)
    str << "<li#{ is_last ? " class='current'" : '' }><a href='#{ is_last ? '#' : arr[0] }'><span>#{arr[1]}</span></a></li>"
  end
  str << "</ul>"
  return str
end