Add root menu snippet

This commit is contained in:
Wen-Tien Chang 2009-05-22 15:16:22 +08:00
parent 32fdf99833
commit 62602940ed
6 changed files with 23 additions and 9 deletions

View File

@ -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?
"<li><a href='/#{page.name}'>#{page.name}</a></li>\n"
else
"<li><a href='#{page.external_link}'>#{page.name}</a></li>\n"
end
end
@snippet.content = "<ul>\n#{lis}</ul>"
end
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @snippets }

View File

@ -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

View File

@ -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

View File

@ -15,7 +15,7 @@
<p>
<%= 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
</p>
<p>

View File

@ -36,3 +36,4 @@
<br />
<%= 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' %>

View File

@ -16,4 +16,3 @@
<br />
<%= link_to 'New snippets', new_admin_snippet_path, :class => 'button positive' %>
<%= link_to 'New menu snippets', new_admin_snippet_path, :class => 'button positive' %>