Add root menu snippet
This commit is contained in:
parent
32fdf99833
commit
62602940ed
|
@ -26,6 +26,19 @@ class Admin::SnippetsController < ApplicationController
|
||||||
def new
|
def new
|
||||||
@snippet = Snippet.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|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
format.xml { render :xml => @snippets }
|
format.xml { render :xml => @snippets }
|
||||||
|
|
|
@ -3,15 +3,15 @@ class PagesController < ApplicationController
|
||||||
Liquid::Template.register_filter(SnippetFilter)
|
Liquid::Template.register_filter(SnippetFilter)
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@page = Page.find_by_name(params[:page_name])
|
@page = Page.find(:first, :conditions => { :name => params[:page_name], :is_published => true })
|
||||||
@layout = @page.layout
|
|
||||||
|
|
||||||
if @page && @page.external_link
|
if @page && @page.external_link
|
||||||
redirect_to @page.external_link
|
redirect_to @page.external_link
|
||||||
elsif @page
|
elsif @page
|
||||||
@page_content = Liquid::Template.parse(@page.content).render
|
@layout = @page.layout
|
||||||
@layout_content = (@page.layout)? @layout.content : "{{page_content}}"
|
@page_content = Liquid::Template.parse(@page.content).render
|
||||||
render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content )
|
@layout_content = (@page.layout)? @layout.content : "{{page_content}}"
|
||||||
|
render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content )
|
||||||
else
|
else
|
||||||
render :text => '404 not found'
|
render :text => '404 not found'
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ class Page < CouchFoo::Base
|
||||||
property :content, String
|
property :content, String
|
||||||
property :layout_id, String
|
property :layout_id, String
|
||||||
property :layout_name, String
|
property :layout_name, String
|
||||||
|
property :load_model, String
|
||||||
property :external_link, String
|
property :external_link, String
|
||||||
property :position, Integer
|
property :position, Integer
|
||||||
property :is_published, Boolean
|
property :is_published, Boolean
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<%= f.label :is_published, "Is Published" %>
|
<%= 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>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -35,4 +35,5 @@
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<%= link_to 'New pages', new_admin_page_path, :class => 'button positive' %>
|
<%= 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' %>
|
|
@ -15,5 +15,4 @@
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<%= link_to 'New snippets', new_admin_snippet_path, :class => 'button positive' %>
|
<%= link_to 'New snippets', new_admin_snippet_path, :class => 'button positive' %>
|
||||||
<%= link_to 'New menu snippets', new_admin_snippet_path, :class => 'button positive' %>
|
|
Loading…
Reference in New Issue