Class: Ecm::CmsCore::PageController

Inherits:
FrontendController
  • Object
show all
Includes:
Ecm::CmsCoreHelper
Defined in:
app/controllers/ecm/cms_core/page_controller.rb

Direct Known Subclasses

PageController

Instance Method Summary collapse

Methods included from Ecm::CmsCoreHelper

#cms_body_classes, #cms_meta_description, #cms_meta_description_tag, #cms_page_stylesheets, #cms_title, #render_fragment

Instance Method Details

#extract_names_from_paramsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/ecm/cms_core/page_controller.rb', line 42

def extract_names_from_params
  page = params[:page]
  page ||= "/home/index"
  pathname = "#{I18n.locale}"
  
  subpath = page.split("/").reverse.drop(1).reverse.join("/").sub(/(\/)+$/,'')
  if subpath.length > 0
    pathname << '/' unless subpath.start_with?('/')
    pathname << "#{subpath}"
  end
  pathname << '/' unless pathname.end_with?('/')
  basename = page.split("/").last
  logger.debug("pathname in page#respond: #{pathname}")
  logger.debug("basename in page#respond: #{basename}")
  logger.debug("page in page#respond: #{page}")        
  return page, pathname, basename
end

#render_404Object



9
10
11
12
13
14
15
# File 'app/controllers/ecm/cms_core/page_controller.rb', line 9

def render_404
  respond_to do |format|
    format.html { render :file => "#{Rails.root}/public/404.html", :status => :not_found, :layout => nil }
    format.xml  { head :not_found }
    format.any  { head :not_found }
  end
end

#respondObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/ecm/cms_core/page_controller.rb', line 17

def respond
  page, pathname, basename = extract_names_from_params
  
  if template = Template.where(:pathname => pathname).where(:basename => basename).where(:locale => I18n.locale).first
    @meta_description = template.meta_description
    @title = template.title
    layout = template.layout unless template.layout.nil?
  end
  
  begin 
    if layout.respond_to?(:length) && layout.length > 0
      render :template => page, :layout => template.layout
    else  
      render :template => page
    end 
  rescue ActionView::MissingTemplate
    if Rails.env.development? or Rails.env.test?
      raise
    else  
      render_404
    end
  end 
  return 
end