Add snippet support and unpack liquid plugin
This commit is contained in:
1 parent
8dcde174cf
commit
438c508ea1
79 files changed
+5708
-1
No files matched your search
@@ -1,4 +1,7 @@
|
||||
class Admin::LayoutsController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
|
||||
# GET /layouts
|
||||
# GET /layouts.xml
|
||||
def index
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
class Admin::PagesController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
|
||||
# GET /pages
|
||||
# GET /pages.xml
|
||||
def index
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
class Admin::SnippetsController < ApplicationController
|
||||
|
||||
layout "admin"
|
||||
|
||||
# GET /snippets
|
||||
# GET /snippets.xml
|
||||
def index
|
||||
@snippets = Snippet.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @snippets }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /snippets/1
|
||||
# GET /snippets/1.xml
|
||||
def show
|
||||
@snippet = Snippet.find(params[:id])
|
||||
|
||||
redirect_to "/#{@snippet.name}"
|
||||
end
|
||||
|
||||
# GET /snippets/new
|
||||
# GET /snippets/new.xml
|
||||
def new
|
||||
@snippet = Snippet.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @snippets }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /snippets/1/edit
|
||||
def edit
|
||||
@snippet = Snippet.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /snippets
|
||||
# POST /snippets.xml
|
||||
def create
|
||||
@snippet = Snippet.new(params[:snippet])
|
||||
|
||||
respond_to do |format|
|
||||
if @snippet.save
|
||||
flash[:notice] = 'Snippet was successfully created.'
|
||||
format.html { redirect_to admin_snippets_url }
|
||||
format.xml { render :xml => @snippet, :status => :created, :location => @snippets }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @snippet.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /snippets/1
|
||||
# PUT /snippets/1.xml
|
||||
def update
|
||||
@snippet = Snippet.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @snippet.update_attributes(params[:snippet])
|
||||
flash[:notice] = 'Snippet was successfully updated.'
|
||||
format.html { redirect_to admin_snippets_url }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @snippet.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /snippets/1
|
||||
# DELETE /snippets/1.xml
|
||||
def destroy
|
||||
@snippet = Snippet.find(params[:id])
|
||||
@snippet.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to admin_snippets_url }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,7 @@
|
||||
class PagesController < ApplicationController
|
||||
|
||||
Liquid::Template.register_filter(SnippetFilter)
|
||||
|
||||
def show
|
||||
@page = Page.find_by_name(params[:page_name])
|
||||
@layout = @page.layout
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Snippet < CouchFoo::Base
|
||||
|
||||
property :name, String
|
||||
property :content, String
|
||||
|
||||
validates_presence_of :name
|
||||
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
module SnippetFilter
|
||||
def render_snippet(snippet_name)
|
||||
|
||||
snippet = Snippet.find_by_name(snippet_name)
|
||||
|
||||
if snippet
|
||||
return Liquid::Template.parse(snippet.content).render
|
||||
else
|
||||
return "nothing"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
<h1>Editing snippets</h1>
|
||||
|
||||
<% form_for @snippet, :url => admin_snippet_path(@snippet) do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<%= f.label :name, "Name" %>
|
||||
<%= f.text_field :name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :content, "Content" %>
|
||||
<%= f.text_area :content, :size => '100x30' %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.submit 'Update' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', admin_snippets_path %>
|
||||
@@ -0,0 +1,18 @@
|
||||
<h1>Listing snippets</h1>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
</tr>
|
||||
|
||||
<% @snippets.each do |snippet| %>
|
||||
<tr>
|
||||
<td><%= snippet.name %></td>
|
||||
<td><%= link_to 'Edit', edit_admin_snippet_path(snippet) %></td>
|
||||
<td><%= link_to 'Destroy', admin_snippet_path(snippet), :confirm => 'Are you sure?', :method => :delete %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<br />
|
||||
|
||||
<%= link_to 'New snippets', new_admin_snippet_path %>
|
||||
@@ -0,0 +1,21 @@
|
||||
<h1>New snippets</h1>
|
||||
|
||||
<% form_for :snippet, :url => admin_snippets_path do |f| %>
|
||||
<%= f.error_messages %>
|
||||
|
||||
<p>
|
||||
<%= f.label :name, "Name" %>
|
||||
<%= f.text_field :name %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.label :content, "Content" %>
|
||||
<%= f.text_area :content, :size => '100x30' %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<%= f.submit 'Create' %>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<%= link_to 'Back', admin_snippets_path %>
|
||||
File renamed without changes.
Reference in new issue
Block a user