replace Liquid by Radius

This commit is contained in:
chris authored and ihower committed 2011-04-13 18:22:51 +08:00
1 parent 70347d4c34
commit 8b8eff6920
8 files changed
+36 -59

No files matched your search

+33 -6
View File
@@ -36,14 +36,41 @@ class ApplicationController < ActionController::Base
redirect_to root_url unless current_user.admin?
end
# Parse and render the pages with liquid
def render_liquid_page
# Parse and render the pages with Radius
def render_page
if @page
@layout = @page.layout
@page_options ||= {}
@page_content = Liquid::Template.parse( @page.content ).render(@page_options)
@layout_content = (@page.layout)? @layout.content : "{{page_content}}"
render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content )
@page_content = @page.content
@layout_content = (@page.layout)? @layout.content : "<r:content />"
context = Radius::Context.new do |c|
c.define_tag 'content' do |tag|
@page_content
end
c.define_tag 'snippet' do |tag|
snippet = Snippet.first(:conditions => {:name => tag.attr['name']})
if snippet
snippet.content
else
t('nothing')
end
end
c.define_tag 'language_bar' do
@site_in_use_locales.map{ |locale|
lang = I18nVariable.first(:conditions => {:key => locale})[locale]
if I18n.locale.to_s.eql?(locale)
lang
else
"<a href='?locale=#{locale}'>#{lang}</a>"
end
}.join(' | ')
end
end
parser = Radius::Parser.new(context, :tag_prefix => 'r')
render :text => parser.parse(@layout_content)
else
render :text => '404 Not Found'
end
+2 -2
View File
@@ -3,7 +3,7 @@ class PagesController < ApplicationController
def index
@page = Home.find_by_name('home')
if @page
render_liquid_page
render_page
else
render :text => 'You need a home page'
end
@@ -15,7 +15,7 @@ class PagesController < ApplicationController
case item._type
when 'Page'
@page = item
render_liquid_page
render_page
when 'Link'
redirect_to "http://#{item[:url]}"
end