Skip to content
Snippets Groups Projects
Unverified Commit ba1f515c authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

publish with descendents

parent 2d589215
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,12 @@ class Communication::Website::GithubFile < ApplicationRecord
add_media_to_batch(github)
end
def manifest_data
@manifest_data ||= about.github_manifest.detect { |item|
item[:identifier] == manifest_identifier
}
end
protected
def add_media_to_batch(github)
......@@ -112,12 +118,6 @@ class Communication::Website::GithubFile < ApplicationRecord
"[Medium] Remove ##{blob.id}"
end
def manifest_data
@manifest_data ||= about.github_manifest.detect { |item|
item[:identifier] == manifest_identifier
}
end
def valid_for_publication?
if about.respond_to?(:published)
about.published?
......
......@@ -92,6 +92,13 @@ class Communication::Website::Page < ApplicationRecord
best_image
end
def update_children_paths
children.each do |child|
child.update_column :path, child.generated_path
child.update_children_paths
end
end
protected
def slug_unavailable?(slug)
......@@ -100,8 +107,4 @@ class Communication::Website::Page < ApplicationRecord
.where.not(id: self.id)
.exists?
end
def update_children_paths
children.each(&:save)
end
end
......@@ -56,7 +56,11 @@ module Communication::Website::WithBatchPublication
def commit_files_in_batch(files, commit_message)
files.find_each { |file| file.add_to_batch(github) }
github.commit_batch commit_message
if github.commit_batch(commit_message)
files.find_each { |file|
file.update_column :github_path, file.manifest_data[:generated_path].call(file)
}
end
end
end
......
......@@ -50,10 +50,36 @@ module WithGithubFiles
end
def publish_github_files
if respond_to?(:descendents)
publish_github_files_with_descendents
else
list_of_websites.each do |website|
github_manifest.each do |manifest_item|
github_file = github_files.where(website: website, manifest_identifier: manifest_item[:identifier]).first_or_create
github_file.publish
end
end
end
end
def publish_github_files_with_descendents
list_of_websites.each do |website|
website_github = Github.with_website website
target_github_files = []
github_manifest.each do |manifest_item|
github_file = github_files.where(website: website, manifest_identifier: manifest_item[:identifier]).first_or_create
github_file.publish
target_github_files << github_file
github_file.add_to_batch(website_github)
descendents.each do |descendent|
descendent_github_file = descendent.github_files.where(website: website, manifest_identifier: manifest_item[:identifier]).first_or_create
target_github_files << descendent_github_file
descendent_github_file.add_to_batch(website_github)
end
end
if website_github.commit_batch("[#{self.class.name.demodulize}] Save #{to_s} & descendents")
target_github_files.each { |file|
file.update_column :github_path, file.manifest_data[:generated_path].call(file)
}
end
end
end
......
......@@ -18,6 +18,10 @@ module WithSlug
end
end
def generated_path
"#{parent&.path}/#{slug}".gsub(/\/+/, '/')
end
protected
def slug_unavailable?(slug)
......@@ -29,7 +33,7 @@ module WithSlug
def make_path
return unless respond_to?(:path) && respond_to?(:parent)
self.path = "#{parent&.path}/#{slug}".gsub(/\/+/, '/')
self.path = generated_path
end
end
end
......@@ -18,6 +18,11 @@ module WithTree
: []
end
def descendents
has_children? ? children.map { |child| [child, child.descendents].flatten }.flatten
: []
end
def self_and_children(level)
elements = []
label = "&nbsp;&nbsp;&nbsp;" * level + self.to_s
......
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