Add root menu snippet
This commit is contained in:
		
							parent
							
								
									32fdf99833
								
							
						
					
					
						commit
						62602940ed
					
				| 
						 | 
				
			
			@ -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 }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,12 +3,12 @@ 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
 | 
			
		||||
      @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 )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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' %>
 | 
			
		||||
| 
						 | 
				
			
			@ -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' %>
 | 
			
		||||
		Reference in New Issue