Sha256: b62cc619c87208d49d973ebe8c3d31480b8d2c3d886e5c4c12e9c58c34096a53

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'cgi'

class Comfy::Archive::IndexController < Comfy::Cms::ContentController

  include Comfy::Paginate

  before_action :load_index,
                :authenticate,
                :authorize,
                only: :index

  def index
    if ! @cms_index || @cms_index.page != @cms_page
      show
    else
      scope = @cms_index.children(true).chronologically(@cms_index.datetime_fragment)
      if params[:year]
        @year = params[:year]
        scope = scope.for_year(@cms_index.datetime_fragment, @year)
        if params[:month]
          @month = params[:month]
          scope = scope.for_month(@cms_index.datetime_fragment, @month)
        end
      elsif params[:category]
        @category = CGI.unescape(params[:category])
        scope = scope.for_category(@category).distinct(false)
      end

      @archive_pages = comfy_paginate(scope, per_page: ComfyArchive.config.posts_per_page)
      if @cms_index.force_render_page
        show
      else
        render layout: app_layout
      end
    end
  end

  protected

  def load_index
    load_cms_page
    if @cms_page
      unless @cms_index = Comfy::Archive::Index.find_by(page: @cms_page)
        @cms_index = Comfy::Archive::Index.find_by(page: @cms_page.parent)
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comfy_archive-0.2.0 app/controllers/comfy/archive/index_controller.rb