Module: Cmtool::Includes::PagesController
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/cmtool/includes/pages_controller.rb
Instance Method Summary collapse
- #home ⇒ Object
- #not_found ⇒ Object
-
#show ⇒ Object
General catcher for pages.
- #sitemap ⇒ Object
Instance Method Details
#home ⇒ Object
6 7 8 9 10 11 |
# File 'lib/cmtool/includes/pages_controller.rb', line 6 def home page_name = 'home' @page = find_page(page_name) @sub_pages = @page.children.select{|child| child..present? } render template: "pages/#{page_name}", layout: @page.layout.presence || ::Page.layouts.first.to_s, formats: [:html] end |
#not_found ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cmtool/includes/pages_controller.rb', line 28 def not_found @page = ::Page.find_by_name_and_locale('404', I18n.locale.to_s) || ::Page.new(name: '404', body: "404 Page Not Found") @sub_pages = [] page_name_extension = params[:name].to_s[/(?<=\.)\w{2,4}$/] format = %w[html css js json].find{|f| f == request.format.symbol.to_s or f == page_name_extension }.try(:to_sym) || :html case format when :json render json: {}, status: 404 when :html render template: 'pages/404', formats: [:html], layout: @page.layout.presence || ::Page.layouts.first.to_s, status: 404 else render nothing: true, status: 404 end end |
#show ⇒ Object
General catcher for pages
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cmtool/includes/pages_controller.rb', line 14 def show @page = ::Page.find_by_name_and_locale(params[:name], I18n.locale.to_s) not_found and return unless @page @sub_pages = [@page] + @page.children.select{|child| child..present? } template = "pages/#{@page.name}" if template_exists?(template) render template: template, formats: [:html], layout: @page.layout.presence || ::Page.layouts.first return else render formats: [:html], layout: @page.layout.presence || ::Page.layouts.first end end |
#sitemap ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cmtool/includes/pages_controller.rb', line 43 def sitemap respond_to do |format| format.xml do pages_xml = ::Page.for_sitemap.map do |page| uri = page_url(page.name, locale: page.locale) "<url><loc>#{uri}</loc><lastmod>#{page.updated_at.strftime('%Y-%m-%d')}</lastmod></url>" end.join("\n") result = <<-XML <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> #{pages_xml} </urlset> XML render xml: result end end end |