module Amber::Render::NavigationHelper
Public Instance Methods
child_summaries(options={})
click to toggle source
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)
# File lib/amber/render/helpers/navigation_helper.rb, line 101 def child_summaries(options={}) page = options.delete(:page) || @page unless page.is_a?(StaticPage) page = @site.find_pages(page) end return "" if page.nil? or page.children.empty? levels_max = options[:levels] || 1 level = options.delete(:level) || 1 heading = options.delete(:heading) || 2 #locale = @locals[:locale] menu = submenu_for_page(page) if menu && menu.children.any? children = menu.children elsif options[:order_by] children = page.children.order_by(*options[: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, options) if level < levels_max haml(child_summaries({ :page => child_page, :levels => levels_max, :level => level+1, :include_toc => options[:include_toc], :order_by => options[:order_by], :heading => heading+1, :summary => options[:summary] })) end end end rescue Exception => exc Amber.log_exception(exc) end
current_page_path()
click to toggle source
# 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
render_page_summary(page, heading=2, options={})
click to toggle source
# File lib/amber/render/helpers/navigation_helper.rb, line 143 def render_page_summary(page, heading=2, options={}) locale = @locals[:locale] klass = options[:class] || '.page-summary' haml ".#{klass}" do haml "h#{heading}" do haml :a, page.nav_title(locale), :href => amber_path(page) end if options[:summary] != false if summary = page.prop(locale, 'summary') haml '.summary', summary elsif preview = page.prop(locale, 'preview') haml '.preview', preview end end if options[:include_toc] toc_html = render_toc(page, :locale => locale) haml toc_html end end end
Private Instance Methods
path_active_class(page_path, menu_item)
click to toggle source
returns string 'active', 'semi-active', or ''
# File lib/amber/render/helpers/navigation_helper.rb, line 169 def path_active_class(page_path, menu_item) active = '' if menu_item.path == page_path active = 'active' elsif menu_item.path_prefix_of?(page_path) if menu_item.leaf_for_path?(page_path) active = 'active' else active = 'semi-active' end end active end
path_open?(page_path, menu_item)
click to toggle source
returns true if menu_item represents an parent of page
# File lib/amber/render/helpers/navigation_helper.rb, line 186 def path_open?(page_path, menu_item) menu_item.path == page_path || menu_item.path_prefix_of?(page_path) end