Sha256: d698f5b1b29de31afc2045421adb7b80cc74661c41ed9487514627f3211b2276

Contents?: true

Size: 902 Bytes

Versions: 1

Compression:

Stored size: 902 Bytes

Contents

module HighVoltage::StaticPage
  extend ActiveSupport::Concern

  included do
    layout ->(_) { HighVoltage.layout }

    rescue_from ActionView::MissingTemplate do |exception|
      if exception.message =~ %r{Missing template #{page_finder.content_path}}
        raise ActionController::RoutingError, "No such page: #{params[:id]}"
      else
        raise exception
      end
    end

    if respond_to?(:caches_action)
      caches_action :show, if: -> { HighVoltage.action_caching }
    end

    if respond_to?(:caches_page)
      caches_page :show, if: -> { HighVoltage.page_caching }
    end

    hide_action :current_page, :page_finder, :page_finder_factory
  end

  def show
    render template: current_page
  end

  def current_page
    page_finder.find
  end

  def page_finder
    page_finder_factory.new(params[:id])
  end

  def page_finder_factory
    HighVoltage::PageFinder
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
high_voltage-2.0.0 app/controllers/concerns/high_voltage/static_page.rb