From aecb1d4ea95506f6afbb371ab55ec621edf90734 Mon Sep 17 00:00:00 2001 From: elijah Date: Sat, 4 May 2013 14:35:47 -0700 Subject: added child_summaries support. --- app/helpers/navigation_helper.rb | 25 +++++++++++++++++++++++++ lib/static_page.rb | 9 ++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/helpers/navigation_helper.rb b/app/helpers/navigation_helper.rb index b4ca514..30faa78 100644 --- a/app/helpers/navigation_helper.rb +++ b/app/helpers/navigation_helper.rb @@ -42,6 +42,21 @@ module NavigationHelper page_body(page) end + def child_summaries(page=@page) + return unless page + menu = submenu_for_page(page) + return unless menu + haml do + menu.children.each do |submenu| + child_page = page.child(submenu.name) + haml :h3 do + haml :a, child_page.nav_title, :href => child_page.path.join('/') + end + haml :p, child_page.props.summary + end + end + end + private def menu_item_path(item) @@ -103,4 +118,14 @@ module NavigationHelper @page && @page.path == ['home'] end + def submenu_for_page(page) + menu = site.menu + page.path.each do |segment| + menu = menu.submenu(segment) + end + return menu + rescue + return nil + end + end diff --git a/lib/static_page.rb b/lib/static_page.rb index 7ef529b..d7d6529 100644 --- a/lib/static_page.rb +++ b/lib/static_page.rb @@ -194,6 +194,13 @@ class StaticPage self.name end + # + # returns a child matching +name+, if any. + # + def child(name) + children.detect {|child| child.name == name} + end + protected def child_tree @@ -279,7 +286,7 @@ class StaticPage # def content_files if @simple_page - [[@file_path + @suffix,nil]] + [[[@file_path, @suffix].join,nil]] elsif File.directory?(@file_path) Dir.foreach(@file_path).collect { |file| if file && file =~ LOCALE_FILE_MATCH -- cgit v1.2.3