Sha256: ed8772054fa0fbfa9c566076f92bb93eb74bf74eb37c8d449caa404dfb474a0e

Contents?: true

Size: 836 Bytes

Versions: 3

Compression:

Stored size: 836 Bytes

Contents

module Brightcontent
  module PageCore
    extend ActiveSupport::Concern

    included do
      acts_as_nested_set
      include Brightcontent::Attachable
      include TheSortableTree::Scopes
      validates_presence_of :name
      after_save :update_slug
      after_move :update_slug
    end

    module ClassMethods
      def default_scope
        order(:lft)
      end
    end

    def homepage?
      lft == 1
    end

    def path
      "/" + slug
    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

3 entries across 3 versions & 1 rubygems

Version Path
brightcontent-pages-2.0.30 app/models/brightcontent/page_core.rb
brightcontent-pages-2.0.29 app/models/brightcontent/page_core.rb
brightcontent-pages-2.0.28 app/models/brightcontent/page_core.rb