Sha256: 2f456265f64ea5948c687b497275ab6194d5906a40507c77f46795cf9c25d9e7

Contents?: true

Size: 802 Bytes

Versions: 5

Compression:

Stored size: 802 Bytes

Contents

module Kms
  class Public::PagesController < ActionController::Base
    protect_from_forgery with: :exception

    before_action :eval_externals

    def show
      page_result = Kms.template_manager.render(@page.register_id, @externals)
      result = Kms.template_manager.render(@template.register_id,
        @externals.merge(_inner_template: page_result))

      render html: result.html_safe, status: (@page.not_found? ? :not_found : :ok)
    end

    protected

    def eval_externals
      @externals = Hash[ExternalsRegistry.externals.map{ |k, v| [k, v.call(request, self)] }]
      @page = @externals[:page].source
      @template = @page.template
    rescue ActiveRecord::RecordNotFound
      render file: "#{Rails.root}/public/404.html", layout: false, status: :not_found
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kms-1.2.1 app/controllers/kms/public/pages_controller.rb
kms-1.2.0 app/controllers/kms/public/pages_controller.rb
kms-1.1.0 app/controllers/kms/public/pages_controller.rb
kms-1.0.1 app/controllers/kms/public/pages_controller.rb
kms-1.0.0 app/controllers/kms/public/pages_controller.rb