replace Liquid by Radius
This commit is contained in:
1 parent
70347d4c34
commit
8b8eff6920
8 files changed
+36
-59
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user