Class: NavigationPresenter
- Inherits:
-
Object
- Object
- NavigationPresenter
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/happy-nav/navigation_presenter.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #base_url ⇒ Object
- #current_item(current_item) ⇒ Object
-
#initialize(items = [], options = {}, current_items = []) ⇒ NavigationPresenter
constructor
A new instance of NavigationPresenter.
- #item_link(item, options = {}) ⇒ Object
- #item_url(text) ⇒ Object
- #nested_navigation(item) ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(items = [], options = {}, current_items = []) ⇒ NavigationPresenter
Returns a new instance of NavigationPresenter.
7 8 9 10 11 |
# File 'lib/happy-nav/navigation_presenter.rb', line 7 def initialize(items = [], = {}, current_items = []) @items = items @options = @current_items = current_items end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
5 6 7 |
# File 'lib/happy-nav/navigation_presenter.rb', line 5 def items @items end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/happy-nav/navigation_presenter.rb', line 5 def @options end |
Instance Method Details
#base_url ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/happy-nav/navigation_presenter.rb', line 76 def base_url if [:base_url] [:base_url] else admin? ? '/admin' : '' end end |
#current_item(current_item) ⇒ Object
84 85 86 |
# File 'lib/happy-nav/navigation_presenter.rb', line 84 def current_item(current_item) @current_items << current_item end |
#item_link(item, options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/happy-nav/navigation_presenter.rb', line 46 def item_link(item, = {}) item = format_item(item, ) content = item[:text] if item[:summary] item[:title] += ': '+item[:summary] content = h.content_tag(:strong, content) + ' ' + content_tag(:em, item[:summary]) end if item[:id] || @options[:id] item[:id] = item[:permalink] if @options[:id] === true || item[:id] === true item[:id] = "nav_#{item[:id]}" end h.link_to content, item[:url], { :id => item[:id], :class => (current_item?(item[:permalink]) ? 'current' : nil), :title => item[:title], } end |
#item_url(text) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/happy-nav/navigation_presenter.rb', line 68 def item_url(text) if (text == 'Home') admin? ? '/admin' : '/' else base_url + '/' + text.parameterize('-') end end |
#nested_navigation(item) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/happy-nav/navigation_presenter.rb', line 31 def (item) unless @options[:flat] item = format_item(item) if item[:items] && current_item?(item[:permalink]) = { :level => next_level, :class => 'nav-sub-' + next_level.to_s, :base_url => item[:url], :wrap => false } NavigationPresenter.new(item[:items], , @current_items[1..-1]).to_html end end end |
#to_html ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/happy-nav/navigation_presenter.rb', line 13 def to_html unless @items.empty? wrap do h.content_tag :ul, :class => @options[:class] do i=0 content = '' @items.each do |item| i=i+1 content += h.content_tag :li, :class => classes(i) do item_link(item) + (item).to_s end end content.html_safe end end else '' end end |