From 62602940ed3556ae652f30d02d8c3c0242b7ecb2 Mon Sep 17 00:00:00 2001 From: Wen-Tien Chang Date: Fri, 22 May 2009 15:16:22 +0800 Subject: [PATCH] Add root menu snippet --- app/controllers/admin/snippets_controller.rb | 13 +++++++++++++ app/controllers/pages_controller.rb | 10 +++++----- app/models/page.rb | 1 + app/views/admin/pages/_form.html.erb | 2 +- app/views/admin/pages/index.html.erb | 3 ++- app/views/admin/snippets/index.html.erb | 3 +-- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/controllers/admin/snippets_controller.rb b/app/controllers/admin/snippets_controller.rb index 6baebe8a..4e94206f 100644 --- a/app/controllers/admin/snippets_controller.rb +++ b/app/controllers/admin/snippets_controller.rb @@ -26,6 +26,19 @@ class Admin::SnippetsController < ApplicationController def new @snippet = Snippet.new + if params[:menu] + @snippet.name = "#{params[:menu]}_nav" + lis = Page.find(:all, :conditions => { :parent_page_id => params[:menu], :is_published => true }, :order => "position" ).map do |page| + if page.external_link.blank? + "
  • #{page.name}
  • \n" + else + "
  • #{page.name}
  • \n" + end + end + + @snippet.content = "" + end + respond_to do |format| format.html # new.html.erb format.xml { render :xml => @snippets } diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 5b01f182..2cc43220 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -3,15 +3,15 @@ class PagesController < ApplicationController Liquid::Template.register_filter(SnippetFilter) def show - @page = Page.find_by_name(params[:page_name]) - @layout = @page.layout + @page = Page.find(:first, :conditions => { :name => params[:page_name], :is_published => true }) if @page && @page.external_link redirect_to @page.external_link elsif @page - @page_content = Liquid::Template.parse(@page.content).render - @layout_content = (@page.layout)? @layout.content : "{{page_content}}" - render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content ) + @layout = @page.layout + @page_content = Liquid::Template.parse(@page.content).render + @layout_content = (@page.layout)? @layout.content : "{{page_content}}" + render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content ) else render :text => '404 not found' end diff --git a/app/models/page.rb b/app/models/page.rb index dde0dd4e..e29f4bd9 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -5,6 +5,7 @@ class Page < CouchFoo::Base property :content, String property :layout_id, String property :layout_name, String + property :load_model, String property :external_link, String property :position, Integer property :is_published, Boolean diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index 1e733a4a..b2268de8 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -15,7 +15,7 @@

    <%= f.label :is_published, "Is Published" %> -<%= f.radio_button :is_published, true %>Yes <%= f.radio_button :is_published, false %> No +<%= f.radio_button :is_published, 1 %>Yes <%= f.radio_button :is_published, 0 %> No

    diff --git a/app/views/admin/pages/index.html.erb b/app/views/admin/pages/index.html.erb index fb13788b..ba38eaf0 100644 --- a/app/views/admin/pages/index.html.erb +++ b/app/views/admin/pages/index.html.erb @@ -35,4 +35,5 @@
    -<%= link_to 'New pages', new_admin_page_path, :class => 'button positive' %> \ No newline at end of file +<%= link_to 'New pages', new_admin_page_path, :class => 'button positive' %> +<%= link_to 'New root menu snippets', new_admin_snippet_path( :menu => 'root' ), :class => 'button positive' %> \ No newline at end of file diff --git a/app/views/admin/snippets/index.html.erb b/app/views/admin/snippets/index.html.erb index 354f0f9a..40eba30b 100644 --- a/app/views/admin/snippets/index.html.erb +++ b/app/views/admin/snippets/index.html.erb @@ -15,5 +15,4 @@
    -<%= link_to 'New snippets', new_admin_snippet_path, :class => 'button positive' %> -<%= link_to 'New menu snippets', new_admin_snippet_path, :class => 'button positive' %> \ No newline at end of file +<%= link_to 'New snippets', new_admin_snippet_path, :class => 'button positive' %> \ No newline at end of file