Sha256: 4c31667e35c9a3b79a6198e1db480959ad17424b63e211a5bfa86caa71093572

Contents?: true

Size: 1.23 KB

Versions: 18

Compression:

Stored size: 1.23 KB

Contents

module Spina
  class PagesController < ApplicationController
    before_action :current_user_can_view_page?, except: [:robots]

    def homepage
      render_with_template(page)
    end

    def show
      if should_skip_to_first_child?
        if page.is_root?
          redirect_to spina.subpage_path(page, first_live_child) and return
        else
          redirect_to spina.third_level_page_path(page.parent, page, first_live_child) and return
        end
      elsif page.link_url.present?
        redirect_to page.link_url and return
      end

      render_with_template(page)
    end

    private

    def page
      @page ||= (action_name == 'homepage') ? Page.find_by(name: 'homepage') : Page.find(params[:id])
    end
    helper_method :page

    def current_user_can_view_page?
      raise ActiveRecord::RecordNotFound unless page.live? || current_user.present?
    end

    def should_skip_to_first_child?
      page.skip_to_first_child && first_live_child
    end

    def first_live_child
      page.children.sorted.live.first
    end

    def render_with_template(page)
      render layout: "#{current_theme.to_s.underscore}/application", template: "#{current_theme.to_s.underscore}/pages/#{page.view_template || 'show'}"
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
spina-0.6.28 app/controllers/spina/pages_controller.rb
spina-0.6.27 app/controllers/spina/pages_controller.rb
spina-0.6.26 app/controllers/spina/pages_controller.rb
spina-0.6.25 app/controllers/spina/pages_controller.rb
spina-0.6.24 app/controllers/spina/pages_controller.rb
spina-0.6.23 app/controllers/spina/pages_controller.rb
spina-0.6.22 app/controllers/spina/pages_controller.rb
spina-0.6.21 app/controllers/spina/pages_controller.rb
spina-0.6.20 app/controllers/spina/pages_controller.rb
spina-0.6.19 app/controllers/spina/pages_controller.rb
spina-0.6.18 app/controllers/spina/pages_controller.rb
spina-0.6.17 app/controllers/spina/pages_controller.rb
spina-0.6.16 app/controllers/spina/pages_controller.rb
spina-0.6.15 app/controllers/spina/pages_controller.rb
spina-0.6.14 app/controllers/spina/pages_controller.rb
spina-0.6.13 app/controllers/spina/pages_controller.rb
spina-0.6.12 app/controllers/spina/pages_controller.rb
spina-0.6.11 app/controllers/spina/pages_controller.rb