2010-05-30 23:57:33 +00:00
|
|
|
module Locomotive
|
|
|
|
module Render
|
|
|
|
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
module InstanceMethods
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def render_locomotive_page
|
2010-06-16 14:43:29 +00:00
|
|
|
@page = locomotive_page
|
2010-05-30 23:57:33 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
redirect_to application_root_url and return if @page.nil?
|
2010-05-30 23:57:33 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
output = @page.render(locomotive_context)
|
2010-05-30 23:57:33 +00:00
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
prepare_and_set_response(output, @page.cache_expires_in || 0)
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def locomotive_page
|
|
|
|
path = request.fullpath.clone
|
|
|
|
path.gsub!(/\.[a-zA-Z][a-zA-Z0-9]{2,}$/, '')
|
|
|
|
path.gsub!(/^\//, '')
|
|
|
|
path = 'index' if path.blank?
|
|
|
|
|
2010-06-01 00:06:46 +00:00
|
|
|
if page = current_site.pages.where(:fullpath => path).first
|
2010-06-10 22:07:59 +00:00
|
|
|
if not page.published? and current_admin.nil?
|
2010-06-01 00:06:46 +00:00
|
|
|
page = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
page || current_site.pages.not_found.first
|
2010-05-30 23:57:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def locomotive_context
|
|
|
|
assigns = {
|
|
|
|
'site' => current_site,
|
2010-06-16 14:43:29 +00:00
|
|
|
'page' => @page,
|
2010-05-30 23:57:33 +00:00
|
|
|
'asset_collections' => Locomotive::Liquid::Drops::AssetCollections.new(current_site),
|
|
|
|
'stylesheets' => Locomotive::Liquid::Drops::Stylesheets.new(current_site),
|
|
|
|
'javascripts' => Locomotive::Liquid::Drops::Javascripts.new(current_site),
|
|
|
|
'contents' => Locomotive::Liquid::Drops::Contents.new(current_site),
|
|
|
|
'current_page' => self.params[:page]
|
|
|
|
}
|
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
registers = { :controller => self, :site => current_site, :page => @page }
|
2010-05-30 23:57:33 +00:00
|
|
|
|
|
|
|
::Liquid::Context.new(assigns, registers)
|
|
|
|
end
|
|
|
|
|
2010-06-16 14:43:29 +00:00
|
|
|
def prepare_and_set_response(output, cache_expiration = 0)
|
|
|
|
response.headers['Cache-Control'] = "public, max-age=#{cache_expiration}" if cache_expiration > 0
|
|
|
|
response.headers['Content-Type'] = 'text/html; charset=utf-8'
|
2010-05-30 23:57:33 +00:00
|
|
|
render :text => output, :layout => false, :status => :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|