You need to sign in or sign up before continuing.
Newer
Older
module Communication::Website::Page::WithPath
extend ActiveSupport::Concern
included do
path += "/#{website.default_language.iso_code}"
path += "/#{slug_with_ancestors}/"
path.gsub(/\/+/, '/')
def slug_with_ancestors
(ancestors.map(&:slug) << slug).reject(&:blank?).join('/')
# Same website only, page published only
# FIXME is it ever called for other websites?
return unless website.id == communication_website_id && published
end
def url
return unless published
return if website.url.blank?
def current_git_path
@current_git_path ||= "#{git_path_prefix}pages/#{slug_with_ancestors}/_index.html"
end
current_slug = self.slug
n = 0
while slug_unavailable?(self.slug)
n += 1
self.slug = [current_slug, n].join('-')
end
end
def slug_unavailable?(slug)
self.class.unscoped
.where(communication_website_id: self.communication_website_id, slug: slug)
.where.not(id: self.id)
.exists?
end
def validate_slug
slug_must_be_present
slug_must_be_unique
slug_must_have_proper_format
end
def slug_must_be_present
errors.add(:slug, ActiveRecord::Errors.default_error_messages[:absent]) if slug.blank?
end
def slug_must_be_unique
errors.add(:slug, ActiveRecord::Errors.default_error_messages[:taken]) if slug_unavailable?(slug)
end
errors.add(:slug, I18n.t('slug_error')) unless /\A[a-z0-9\-]+\z/.match?(slug)