Sha256: 27dd69fae790b2136e0a9ad3ac92ee5f8ff5b5b0456340fc718a27ce348b8c7a

Contents?: true

Size: 786 Bytes

Versions: 5

Compression:

Stored size: 786 Bytes

Contents

module Brightcontent
  module PageCore
    extend ActiveSupport::Concern

    included do
      attr_accessible :body, :name, :parent_id, :hidden
      acts_as_nested_set
      include Brightcontent::Attachable

      validates_presence_of :name
      after_save :update_slug
    end

    module ClassMethods
      def default_scope
        order(:lft)
      end
    end

    def homepage?
      lft == 1
    end

    def attachment_styles
      Brightcontent.page_attachment_styles
    end

    def root_parent_children
      root? ? children : ancestors.first.children
    end

    private

    def update_slug
      self.update_column(:slug, slug_name)
    end

    def slug_name
      homepage? ? "" : self_and_ancestors.map { |p| p.name.parameterize }.join("/")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
brightcontent-pages-2.0.22 app/models/brightcontent/page_core.rb
brightcontent-pages-2.0.21 app/models/brightcontent/page_core.rb
brightcontent-pages-2.0.20 app/models/brightcontent/page_core.rb
brightcontent-pages-2.0.19 app/models/brightcontent/page_core.rb
brightcontent-pages-2.0.18 app/models/brightcontent/page_core.rb