app/models/archangel/page.rb in archangel-0.3.0 vs app/models/archangel/page.rb in archangel-0.4.0
- old
+ new
@@ -3,81 +3,45 @@
module Archangel
##
# Page model
#
class Page < ApplicationRecord
+ include Archangel::Models::MetatagableConcern
+ include Archangel::Models::PublishableConcern
+
extend ActsAsTree::TreeView
acts_as_tree order: :title
acts_as_paranoid
before_validation :parameterize_slug
- before_save :build_page_path
+ before_save :build_page_permalink
after_save :homepage_reset
after_destroy :column_reset
validates :content, presence: true
validates :homepage, inclusion: { in: [true, false] }
- validates :path, uniqueness: { scope: :site_id }
- validates :published_at, allow_blank: true, date: true
+ validates :permalink, uniqueness: { scope: :site_id }
validates :slug, presence: true,
uniqueness: { scope: %i[parent_id site_id] }
validates :title, presence: true
validate :valid_liquid_content
validate :within_valid_path
+ belongs_to :design, -> { where(partial: false) },
+ inverse_of: false,
+ optional: true
belongs_to :parent, class_name: "Archangel::Page", optional: true
belongs_to :site
- belongs_to :template, -> { where(partial: false) }, optional: true
- has_many :metatags, as: :metatagable
-
- accepts_nested_attributes_for :metatags, reject_if: :all_blank,
- allow_destroy: true
-
- scope :published, (lambda do
- where.not(published_at: nil).where("published_at <= ?", Time.now)
- end)
-
- scope :unpublished, (lambda do
- where("published_at IS NULL OR published_at > ?", Time.now)
- end)
-
scope :homepage, (-> { where(homepage: true) })
##
- # Check if Page is published. Published in the past, present and future.
- # Future publication date is also considered published.
- #
- # @return [Boolean] if published
- #
- def published?
- published_at.present?
- end
-
- ##
- # Return string of publication status.
- #
- # @return [String] publication status
- #
- def status
- if published?
- if published_at > Time.now
- "future-published"
- else
- "published"
- end
- else
- "unpublished"
- end
- end
-
- ##
# Liquid object for Page
#
# @return [Object] the Liquid object
#
def to_liquid
@@ -100,14 +64,14 @@
def parameterize_slug
self.slug = slug.to_s.downcase.parameterize
end
- def build_page_path
- parent_path = parent.blank? ? nil : parent.path
+ def build_page_permalink
+ parent_permalink = parent.blank? ? nil : parent.permalink
- self.path = [parent_path, slug].compact.join("/")
+ self.permalink = [parent_permalink, slug].compact.join("/")
end
def homepage_reset
return unless homepage?
@@ -125,10 +89,10 @@
def valid_liquid_content?
::Liquid::Template.parse(content)
true
- rescue ::Liquid::SyntaxError => _e
+ rescue ::Liquid::SyntaxError
false
end
def within_valid_path?
reserved_paths.reject(&:empty?).each do |path|