Chris's first commit at Fri Jan 28 2011 10:14:32 GMT+0800 (CST)

This commit is contained in:
ihower committed 2011-04-13 18:19:51 +08:00
1 parent 554aa0a95d
commit 19a7d51e60
145 files changed
+12742 -893

No files matched your search

+55 -19
View File
@@ -2,10 +2,41 @@ class ApplicationController < ActionController::Base
protect_from_forgery
helper :all
before_filter :set_locale
before_filter :set_locale, :set_site
Liquid::Template.register_filter(SnippetFilter)
# Find the parent for the given item
def find_parent_item
@parent_item = Item.first(:conditions => { :id => BSON::ObjectId(params[:parent_id]) }) rescue nil
end
# Clean the link back
# Remove the locale but keep all the other params
def get_go_back
begin
if env['REQUEST_URI'].include?('locale=')
session[:last_page]
else
target = env['HTTP_REFERER'].split('?')
vars = target[1].split('&')
vars.delete_if {|var| var.include? 'locale=' }
if vars.size > 0
target[0].to_s + '?' + vars.join('&')
else
target[0].to_s
end
end
rescue
nil
end
end
# Check if the current_user is admin
def is_admin?
redirect_to root_url unless current_user.admin?
end
# Parse and render the pages with liquid
def render_liquid_page
if @page
@layout = @page.layout
@@ -18,26 +49,31 @@ class ApplicationController < ActionController::Base
end
end
# Set I18n.locale
def set_locale
# update session if passed
if params[:locale] && VALID_LOCALES.include?( params[:locale] )
session[:locale] = params[:locale]
end
session[:locale] = params[:locale] if params[:locale]
# set locale based on session or default
I18n.locale = session[:locale] || I18n.default_locale
end
def find_parent_item
@parent_item = Item.find_by_name(params[:parent_name] || 'root')
unless @parent_item
@parent_item = Page.create( :name => "root", :title => "root", :layout_name => "root" )
end
end
def require_entry_name
render :text => 'missing entry_name' if params[:entry_name].blank?
return
begin
# check if locale is valid for non site pages
if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s) && !VALID_LOCALES.include?(session[:locale])
I18n.locale = I18n.default_locale
else
I18n.locale = session[:locale]
end
rescue
I18n.locale = I18n.default_locale
end
end
# Set the site variables
def set_site
# set site if exist or create site
site = Site.first || Site.create({:valid_locales => [], :in_use_locales => []})
session[:site] = site.id
@site_in_use_locales = site.in_use_locales
@site_valid_locales = site.valid_locales
end
end