Sha256: 7beaa516cf089963f0beed810af86d22ba77c91d9c262962e68f05e4d2041d27

Contents?: true

Size: 1.46 KB

Versions: 28

Compression:

Stored size: 1.46 KB

Contents

module Smithy
  class PageList < ActiveRecord::Base
    include Smithy::ContentBlocks::Model

    validates_presence_of :parent_id

    belongs_to :parent, :class_name => "Page"

    class << self
      def content_block_description
        "Page Lists are primarily used to provide a sub-navigation for parent pages or cross-navigation to other sections of your website."
      end

      def sort_options
        [
          ['Sitemap Order', 'sitemap'],
          ['Most Recently Created First', 'created_desc'],
          ['Earliest Created First', 'created_asc'],
          ['Alphabetical Order', 'title_asc'],
          ['Reverse Alphabetical Order', 'title_desc']
        ]
      end
    end

    def pages
      unless @pages
        return unless self.parent
        @pages = self.parent.children
        @pages = @pages.except(:order).order(sort_sql) unless sort_sql.nil?
        @pages = @pages.limit(self.count) if self.count?
        @pages = @pages.where(:template_id => self.page_template_id) if self.page_template_id?
      end
      @pages
    end

    def to_liquid
      {
        'id' => self.id,
        'parent' => self.parent,
        'pages' => self.pages
      }
    end

    private
      def sort_sql
        case self.sort
        when 'created_desc'
          'created_at DESC'
        when 'created_asc'
          'created_at ASC'
        when 'title_asc'
          'title ASC'
        when 'title_desc'
          'title DESC'
        end
      end

  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
smithycms-0.8.1 app/models/smithy/page_list.rb
smithycms-0.7.3 app/models/smithy/page_list.rb
smithycms-0.7.2 app/models/smithy/page_list.rb
smithycms-0.7.1 app/models/smithy/page_list.rb
smithycms-0.7.0 app/models/smithy/page_list.rb
smithycms-0.6.10 app/models/smithy/page_list.rb
smithycms-0.5.99.3 app/models/smithy/page_list.rb
smithycms-0.6.9 app/models/smithy/page_list.rb
smithycms-0.6.7 app/models/smithy/page_list.rb
smithycms-0.6.6 app/models/smithy/page_list.rb
smithycms-0.6.5 app/models/smithy/page_list.rb
smithycms-0.6.4 app/models/smithy/page_list.rb
smithycms-0.6.3 app/models/smithy/page_list.rb
smithycms-0.5.99.2 app/models/smithy/page_list.rb
smithycms-0.5.99.1 app/models/smithy/page_list.rb
smithycms-0.5.99 app/models/smithy/page_list.rb
smithycms-0.6.2 app/models/smithy/page_list.rb
smithycms-0.6.1 app/models/smithy/page_list.rb
smithycms-0.5.2 app/models/smithy/page_list.rb
smithycms-0.6.0 app/models/smithy/page_list.rb