Module: Amber::Render::NavigationHelper
- Included in:
- View
- Defined in:
- lib/amber/render/helpers/navigation_helper.rb
Instance Method Summary collapse
-
#child_summaries(options = {}) ⇒ Object
inserts an directory index built from the page’s children.
- #current_page_path ⇒ Object
- #has_navigation? ⇒ Boolean
- #menu_item_title(item) ⇒ Object
-
#navigation_items(menu = nil, level = 1, &block) ⇒ Object
yields each item.
- #render_page_summary(page, heading = 2, options = {}) ⇒ Object
-
#top_navigation_items(options = {}) ⇒ Object
yields each item.
Instance Method Details
#child_summaries(options = {}) ⇒ Object
inserts an directory index built from the page’s children
options:
:levels -- the max levels to descend (default 1)
:page -- StaticPage instance or nil
:include_toc -- true or false (default false)
:order_by -- arguments to PageArray#order_by
:heading -- heading level to use (default 2)
:summary -- to show summaries or not (default true)
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/amber/render/helpers/navigation_helper.rb', line 101 def child_summaries(={}) page = .delete(:page) || @page unless page.is_a?(StaticPage) page = @site.find_pages(page) end return "" if page.nil? or page.children.empty? levels_max = [:levels] || 1 level = .delete(:level) || 1 heading = .delete(:heading) || 2 #locale = @locals[:locale] = (page) if && .children.any? children = .children elsif [:order_by] children = page.children.order_by(*[:order_by]) else children = page.children end haml do children.each do |child| child_page = child.is_a?(Amber::Menu) ? page.child(child.name) : child next unless child_page render_page_summary(child_page, heading, ) if level < levels_max haml(child_summaries({ :page => child_page, :levels => levels_max, :level => level+1, :include_toc => [:include_toc], :order_by => [:order_by], :heading => heading+1, :summary => [:summary] })) end end end rescue Exception => exc Amber.log_exception(exc) end |
#current_page_path ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/amber/render/helpers/navigation_helper.rb', line 69 def current_page_path @current_page_path ||= begin if @page @page.path #elsif params[:page].is_a? String # params[:page].split('/') else [] end end end |
#has_navigation? ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/amber/render/helpers/navigation_helper.rb', line 5 def if current_page_path.empty? || @site..nil? false else = @site..(current_page_path.first) if second_level_children_count = .size if second_level_children_count.nil? false else second_level_children_count >= 1 end else false end end end |
#menu_item_title(item) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/amber/render/helpers/navigation_helper.rb', line 81 def (item) page = @site.find_page_by_path(item.path_str) || @site.find_page_by_name(item.name) if page page.nav_title(I18n.locale) else nil end end |
#navigation_items(menu = nil, level = 1, &block) ⇒ Object
yields each item
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/amber/render/helpers/navigation_helper.rb', line 47 def (=nil, level=1, &block) if .nil? = site..(current_page_path.first) end if .each do |item| title = (item) if title yield({ :href => amber_path(item.path), :level => level, :active => path_active_class(current_page_path, item), :label => title }) end if path_open?(current_page_path, item) (item., level+1, &block) end end end end |
#render_page_summary(page, heading = 2, options = {}) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/amber/render/helpers/navigation_helper.rb', line 143 def render_page_summary(page, heading=2, ={}) locale = @locals[:locale] klass = [:class] || '.page-summary' haml ".#{klass}" do haml "h#{heading}" do haml :a, page.nav_title(locale), :href => amber_path(page) end if [:summary] != false if summary = page.prop(locale, 'summary') haml '.summary', summary elsif preview = page.prop(locale, 'preview') haml '.preview', preview end end if [:include_toc] toc_html = render_toc(page, :locale => locale) haml toc_html end end end |
#top_navigation_items(options = {}) ⇒ Object
yields each item
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/amber/render/helpers/navigation_helper.rb', line 26 def (={}) if !@site. yield({}) else first = 'first' if [:include_home] active = current_page_path.empty? ? 'active' : '' yield({:class => [first, active].compact.join(' '), :href => amber_path(@site..path), :label => (@site.)}) first = nil end @site..each do |item| active = current_page_path.first == item.name ? 'active' : '' yield({:class => [first, active].compact.join(' '), :href => amber_path(item.path), :label => (item)}) first = nil end end end |