Skip to content
Snippets Groups Projects
Commit ed81096d authored by Arnaud Levy's avatar Arnaud Levy
Browse files

special git paths

parent 77696198
No related branches found
No related tags found
No related merge requests found
Showing
with 77 additions and 27 deletions
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::Administrator < Communication::Website::Page
def current_git_path
"#{git_path_prefix}administrators/_index.html"
end
end
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::Author < Communication::Website::Page
def current_git_path
"#{git_path_prefix}authors/_index.html"
end
end
......@@ -41,11 +41,11 @@
#
class Communication::Website::Page::CommunicationPost < Communication::Website::Page
def git_path(website)
"#{git_path_content_prefix(website)}posts/_index.html"
def current_git_path
"#{git_path_prefix}posts/_index.html"
end
def git_dependencies
def git_dependencies(website)
[
website.config_default_permalinks,
website.categories,
......
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::EducationDiploma < Communication::Website::Page
def current_git_path
"#{git_path_prefix}diplomas/_index.html"
end
end
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::EducationProgram < Communication::Website::Page
def current_git_path
"#{git_path_prefix}programs/_index.html"
end
end
......@@ -50,4 +50,8 @@ class Communication::Website::Page::Home < Communication::Website::Page
def set_slug
self.slug = ''
end
def validate_slug
true
end
end
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::Organization < Communication::Website::Page
def current_git_path
"#{git_path_prefix}organizations/_index.html"
end
end
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::Person < Communication::Website::Page
def current_git_path
"#{git_path_prefix}persons/_index.html"
end
end
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::ResearchPaper < Communication::Website::Page
def current_git_path
"#{git_path_prefix}papers/_index.html"
end
end
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::ResearchVolume < Communication::Website::Page
def current_git_path
"#{git_path_prefix}volumes/_index.html"
end
end
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::Researcher < Communication::Website::Page
def current_git_path
"#{git_path_prefix}researchers/_index.html"
end
end
......@@ -41,4 +41,8 @@
#
class Communication::Website::Page::Teacher < Communication::Website::Page
def current_git_path
"#{git_path_prefix}teachers/_index.html"
end
end
......@@ -2,18 +2,8 @@ module Communication::Website::Page::WithPath
extend ActiveSupport::Concern
included do
validates :slug,
presence: true,
unless: :kind_home?
validate :slug_must_be_unique
validates :slug,
format: {
with: /\A[a-z0-9\-]+\z/,
message: I18n.t('slug_error')
},
unless: :kind_home?
before_validation :set_slug
validate :validate_slug
end
def path
......@@ -31,30 +21,26 @@ module Communication::Website::Page::WithPath
end
def git_path(website)
# Same website and page published
# Same website only, page published only
# FIXME is it ever called for other websites?
return unless website.id == communication_website_id && published
path = git_path_content_prefix(website)
if kind_home?
path += "_index.html"
elsif has_special_git_path?
path += "#{kind.split('_').last}/_index.html"
else
end
"#{git_path_prefix}pages/#{slug_with_ancestors}/_index.html"
current_git_path
end
def url
return unless published
return if website.url.blank?
"#{website.url}#{path}"
"#{website.url}#{path}".gsub('//', '/')
end
protected
def current_git_path
@current_git_path ||= "#{git_path_prefix}pages/#{slug_with_ancestors}/_index.html"
end
def git_path_prefix
git_path_content_prefix(website)
@git_path_prefix ||= git_path_content_prefix(website)
end
def set_slug
......@@ -74,8 +60,28 @@ module Communication::Website::Page::WithPath
.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
def slug_must_have_proper_format
# TODO method equivalent of:
# validates :slug,
# format: {
# with: /\A[a-z0-9\-]+\z/,
# message: I18n.t('slug_error')
# },
# unless: :kind_home?
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment