replace Liquid by Radius

This commit is contained in:
chris 2011-02-22 16:00:13 +08:00 committed by ihower
parent 70347d4c34
commit 8b8eff6920
8 changed files with 36 additions and 59 deletions

View File

@ -5,7 +5,6 @@ gem 'rails', '3.0.3'
gem 'bson_ext'
gem 'carrierwave'
gem 'devise'
gem 'liquid'
gem 'mini_magick'
gem 'mongoid', '2.0.0.rc.6'

View File

@ -41,7 +41,6 @@ GEM
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.5.0)
liquid (2.2.2)
mail (2.2.15)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
@ -93,7 +92,6 @@ DEPENDENCIES
bson_ext
carrierwave
devise
liquid
mini_magick
mongoid (= 2.0.0.rc.6)
rails (= 3.0.3)

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

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

View File

@ -1,13 +0,0 @@
class I18nLiquid < Liquid::Tag
def initialize(tag_name, value, tokens)
super
@value = value.to_s
end
def render(context)
I18nVariable.first(:conditions => {:key => @value})[I18n.locale] rescue ''
end
end
Liquid::Template.register_tag('t', I18nLiquid)

View File

@ -1,27 +0,0 @@
module SnippetFilter
def render_snippet(snippet_name)
snippet = Snippet.first(:conditions => {:name => snippet_name})
if snippet
return Liquid::Template.parse( snippet.content ).render
else
return t('nothing')
end
end
def ruling_snippet(snippet_name)
case snippet_name
when 'language_bar'
site = Site.first
@site_in_use_locales = site.in_use_locales
@site_valid_locales = site.valid_locales
end
return Liquid::Template.parse( eval(File.open("#{RAILS_ROOT}/lib/snippets/#{snippet_name}.snippet").read) ).render
end
end
Liquid::Template.register_filter(SnippetFilter)

View File

@ -1,8 +0,0 @@
@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(' | ')

1
vendor/plugins/radius vendored Submodule

@ -0,0 +1 @@
Subproject commit d312e31954c3dfa5711b06267d79b9ea11c5f059