Sha256: 63e5338fc00ac83b7c8a2b0fb4ec644c552ea067d71ca3ffc4aa4687aaff727f

Contents?: true

Size: 1.66 KB

Versions: 32

Compression:

Stored size: 1.66 KB

Contents

module Cmor
  module Cms
    class PageController < Cmor::Cms::Configuration.base_controller.constantize
      include Cmor::Cms::ControllerExtensions::PageResolver
      include Cmor::Cms::ControllerExtensions::PartialResolver

      def respond
        respond_to do |format|
          format.html { render template: params[:page] }
          format.txt  { render template: params[:page], layout: false, formats: [:text] }
          # format.pdf do
          #   output = render_to_string template: params[:page], formats: [:html, :pdf], layout: false
          #   self.response_body = WickedPdf.new.pdf_from_string(output)
          # end if Gem::Specification.find_all_by_name('wicked_pdf').any?
        end
      end

      module MissingTemplateConcern
        extend ActiveSupport::Concern

        included do
          # avoid error 500 on missing template
          rescue_from ActionView::MissingTemplate do
            if params[:page] == 'home'
              render_fallback_page
            else
              respond_to do |format|
                format.html do
                  render(file: "#{Rails.root}/public/404", formats: [:html],
                        layout: false,
                        status: 404
                        )
                end
                format.xml  { head :not_found }
                format.any  { head :not_found }
              end
            end
          end
        end

        private

        def render_fallback_page
          respond_to do |format|
            format.html { render :fallback }
            format.txt  { render :fallback }
          end
        end
      end

      include MissingTemplateConcern
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
cmor_cms-0.0.34.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.33.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.32.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.31.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.30.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.29.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.28.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.27.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.26.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.25.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.24.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.22.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.21.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.20.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.19.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.18.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.17.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.15.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.14.pre app/controllers/cmor/cms/page_controller.rb
cmor_cms-0.0.13.pre app/controllers/cmor/cms/page_controller.rb