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 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::Administrator < Communication::Website::Page class Communication::Website::Page::Administrator < Communication::Website::Page
def current_git_path
"#{git_path_prefix}administrators/_index.html"
end
end end
...@@ -41,4 +41,8 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::Author < Communication::Website::Page class Communication::Website::Page::Author < Communication::Website::Page
def current_git_path
"#{git_path_prefix}authors/_index.html"
end
end end
...@@ -41,11 +41,11 @@ ...@@ -41,11 +41,11 @@
# #
class Communication::Website::Page::CommunicationPost < Communication::Website::Page class Communication::Website::Page::CommunicationPost < Communication::Website::Page
def git_path(website) def current_git_path
"#{git_path_content_prefix(website)}posts/_index.html" "#{git_path_prefix}posts/_index.html"
end end
def git_dependencies def git_dependencies(website)
[ [
website.config_default_permalinks, website.config_default_permalinks,
website.categories, website.categories,
......
...@@ -41,4 +41,8 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::EducationDiploma < Communication::Website::Page class Communication::Website::Page::EducationDiploma < Communication::Website::Page
def current_git_path
"#{git_path_prefix}diplomas/_index.html"
end
end end
...@@ -41,4 +41,8 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::EducationProgram < Communication::Website::Page class Communication::Website::Page::EducationProgram < Communication::Website::Page
def current_git_path
"#{git_path_prefix}programs/_index.html"
end
end end
...@@ -50,4 +50,8 @@ class Communication::Website::Page::Home < Communication::Website::Page ...@@ -50,4 +50,8 @@ class Communication::Website::Page::Home < Communication::Website::Page
def set_slug def set_slug
self.slug = '' self.slug = ''
end end
def validate_slug
true
end
end end
...@@ -41,4 +41,8 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::Organization < Communication::Website::Page class Communication::Website::Page::Organization < Communication::Website::Page
def current_git_path
"#{git_path_prefix}organizations/_index.html"
end
end end
...@@ -41,4 +41,8 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::Person < Communication::Website::Page class Communication::Website::Page::Person < Communication::Website::Page
def current_git_path
"#{git_path_prefix}persons/_index.html"
end
end end
...@@ -41,4 +41,8 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::ResearchPaper < Communication::Website::Page class Communication::Website::Page::ResearchPaper < Communication::Website::Page
def current_git_path
"#{git_path_prefix}papers/_index.html"
end
end end
...@@ -41,4 +41,8 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::ResearchVolume < Communication::Website::Page class Communication::Website::Page::ResearchVolume < Communication::Website::Page
def current_git_path
"#{git_path_prefix}volumes/_index.html"
end
end end
...@@ -41,4 +41,8 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::Researcher < Communication::Website::Page class Communication::Website::Page::Researcher < Communication::Website::Page
def current_git_path
"#{git_path_prefix}researchers/_index.html"
end
end end
...@@ -41,4 +41,8 @@ ...@@ -41,4 +41,8 @@
# #
class Communication::Website::Page::Teacher < Communication::Website::Page class Communication::Website::Page::Teacher < Communication::Website::Page
def current_git_path
"#{git_path_prefix}teachers/_index.html"
end
end end
...@@ -2,18 +2,8 @@ module Communication::Website::Page::WithPath ...@@ -2,18 +2,8 @@ module Communication::Website::Page::WithPath
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do 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 before_validation :set_slug
validate :validate_slug
end end
def path def path
...@@ -31,30 +21,26 @@ module Communication::Website::Page::WithPath ...@@ -31,30 +21,26 @@ module Communication::Website::Page::WithPath
end end
def git_path(website) 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 return unless website.id == communication_website_id && published
current_git_path
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"
end end
def url def url
return unless published return unless published
return if website.url.blank? return if website.url.blank?
"#{website.url}#{path}" "#{website.url}#{path}".gsub('//', '/')
end end
protected protected
def current_git_path
@current_git_path ||= "#{git_path_prefix}pages/#{slug_with_ancestors}/_index.html"
end
def git_path_prefix def git_path_prefix
git_path_content_prefix(website) @git_path_prefix ||= git_path_content_prefix(website)
end end
def set_slug def set_slug
...@@ -74,8 +60,28 @@ module Communication::Website::Page::WithPath ...@@ -74,8 +60,28 @@ module Communication::Website::Page::WithPath
.exists? .exists?
end 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 def slug_must_be_unique
errors.add(:slug, ActiveRecord::Errors.default_error_messages[:taken]) if slug_unavailable?(slug) errors.add(:slug, ActiveRecord::Errors.default_error_messages[:taken]) if slug_unavailable?(slug)
end 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 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