2009-05-07 16:53:18 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
2009-06-01 06:20:15 +00:00
|
|
|
protect_from_forgery
|
2010-03-08 08:04:05 +00:00
|
|
|
|
|
|
|
helper :all
|
|
|
|
|
2009-06-19 09:31:10 +00:00
|
|
|
before_filter :set_locale
|
|
|
|
|
2009-06-01 06:20:15 +00:00
|
|
|
filter_parameter_logging :password
|
|
|
|
|
|
|
|
Liquid::Template.register_filter(SnippetFilter)
|
|
|
|
|
|
|
|
def render_liquid_page
|
|
|
|
if @page
|
|
|
|
@layout = @page.layout
|
|
|
|
@page_options ||= {}
|
2010-01-08 07:32:44 +00:00
|
|
|
@page_content = Liquid::Template.parse( @page.content ).render(@page_options)
|
|
|
|
@layout_content = (@page.layout)? @layout.content : "{{page_content}}"
|
2009-06-01 06:20:15 +00:00
|
|
|
render :text => Liquid::Template.parse(@layout_content).render( 'page_content' => @page_content )
|
|
|
|
else
|
|
|
|
render :text => '404 Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-19 09:31:10 +00:00
|
|
|
def set_locale
|
|
|
|
# update session if passed
|
|
|
|
if params[:locale] && VALID_LOCALES.include?( params[:locale] )
|
|
|
|
session[:locale] = params[:locale]
|
|
|
|
end
|
|
|
|
|
|
|
|
# set locale based on session or default
|
|
|
|
I18n.locale = session[:locale] || I18n.default_locale
|
|
|
|
end
|
2010-01-11 09:09:50 +00:00
|
|
|
|
2010-01-14 10:30:53 +00:00
|
|
|
def find_parent_item
|
2010-02-22 09:09:39 +00:00
|
|
|
@parent_item = Item.find_by_name(params[:parent_name] || 'root')
|
2010-01-14 10:30:53 +00:00
|
|
|
unless @parent_item
|
2010-01-18 07:52:52 +00:00
|
|
|
@parent_item = Page.create( :name => "root", :title => "root", :layout_name => "root" )
|
2010-01-14 10:30:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-11 09:09:50 +00:00
|
|
|
def require_entry_name
|
|
|
|
render :text => 'missing entry_name' if params[:entry_name].blank?
|
|
|
|
return
|
|
|
|
end
|
2010-03-08 08:04:05 +00:00
|
|
|
|
2009-05-07 16:53:18 +00:00
|
|
|
end
|