added child_summaries support.
authorelijah <elijah@riseup.net>
Sat, 4 May 2013 21:35:47 +0000 (14:35 -0700)
committerelijah <elijah@riseup.net>
Sat, 4 May 2013 21:35:47 +0000 (14:35 -0700)
app/helpers/navigation_helper.rb
lib/static_page.rb

index b4ca514..30faa78 100644 (file)
@@ -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
index 7ef529b..d7d6529 100644 (file)
@@ -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