Sha256: d46a230470458df3197b5a8d9dd22c75553de738425ee2df5d03e353ebdb1adc

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

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}}
        invalid_page
      else
        raise exception
      end
    end

    rescue_from HighVoltage::InvalidPageIdError, with: :invalid_page

    if respond_to?(:caches_action)
      caches_action :show, layout: HighVoltage.action_caching_layout,
        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

  def invalid_page
    raise ActionController::RoutingError, "No such page: #{params[:id]}"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
high_voltage-2.4.0 app/controllers/concerns/high_voltage/static_page.rb
high_voltage-2.3.0 app/controllers/concerns/high_voltage/static_page.rb