Sha256: c1f9fefbf60c18015b1e2839bcfc4d64bb9fdc27bef041b7428773f7e779f2a3

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

require 'active_support/concern'

module Georgia
  module Concerns
    module Frontendable
      extend ActiveSupport::Concern

      included do

        include Pundit

        # Loads the page according to request url
        # Restore the latest published revision of the given page
        def show
          if preview?
            prepare_preview
          else
            @page = Georgia::Page.from_url(params[:request_path]).published.first || not_found
            @page = Georgia::PageDecorator.decorate(@page)
          end
        end

        protected

        def preview?
          params[:r].present?
        end

        # Loads the page according to given id
        # Temporarily set the given revision to preview as the 'current_revision'
        def prepare_preview
          @page = Georgia::Page.from_url(params[:request_path]).first || not_found
          @page = Georgia::PageDecorator.decorate(@page)
          @page.current_revision = Georgia::Revision.find(params[:r])
          authorize @page, :preview?
        end

        # Triggers a 404 page not found
        # Use when provided url doesn't match any the Georgia::Pages
        def not_found
          raise ActionController::RoutingError.new('Not Found')
        end

        def page_cache_key
          [Georgia::Page.where(url: "/#{params[:request_path]}").try(:first).try(:cache_key), I18n.locale].compact.join('/')
        end

      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
georgia-0.8.0 app/controllers/georgia/concerns/frontendable.rb