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

clean

parent 87a24399
No related branches found
No related tags found
No related merge requests found
Showing
with 131 additions and 132 deletions
......@@ -41,12 +41,13 @@ class Communication::Website < ApplicationRecord
"#{name}"
end
def git_path_static
def git_path(website)
"data/website.yml"
end
def git_dependencies_static
def git_dependencies(website)
dependencies = (
[self] +
pages + pages.map(&:active_storage_blobs).flatten +
posts + posts.map(&:active_storage_blobs).flatten +
[home] + home.explicit_active_storage_blobs +
......
......@@ -71,16 +71,16 @@ class Communication::Website::Category < ApplicationRecord
"#{name}"
end
def git_path_static
def git_path(website)
"content/categories/#{path}/_index.html"
end
def git_dependencies_static
descendents + posts
def git_dependencies(website)
[self] + descendents + posts
end
def git_destroy_dependencies_static
descendents
def git_destroy_dependencies(website)
[self] + descendents
end
def update_children_paths
......
......@@ -27,8 +27,8 @@ class Communication::Website::GitFile < ApplicationRecord
attr_accessor :will_be_destroyed
def self.sync(website, object, identifier, destroy: false)
git_file = where(website: website, about: object, identifier: identifier).first_or_create
def self.sync(website, object, destroy: false)
git_file = where(website: website, about: object).first_or_create
git_file.will_be_destroyed = destroy
website.git_repository.add_git_file git_file
end
......@@ -59,7 +59,7 @@ class Communication::Website::GitFile < ApplicationRecord
end
def path
@path ||= about.send "git_path_#{identifier}"
@path ||= about.git_path(website)
end
def sha
......
......@@ -34,15 +34,15 @@ class Communication::Website::Home < ApplicationRecord
website.to_s
end
def git_path_static
def git_path(website)
'content/_index.html'
end
def git_dependencies_static
active_storage_blobs
def git_dependencies(website)
[self] + active_storage_blobs
end
def git_destroy_dependencies_static
active_storage_blobs
def git_destroy_dependencies(website)
[self] + active_storage_blobs
end
end
......@@ -37,7 +37,7 @@ class Communication::Website::Menu < ApplicationRecord
"#{title}"
end
def git_path_static
def git_path(website)
"data/menus/#{identifier}.yml"
end
end
......@@ -71,16 +71,16 @@ class Communication::Website::Page < ApplicationRecord
scope :recent, -> { order(updated_at: :desc).limit(5) }
def git_path_static
def git_path(website)
"content/pages/#{path}/_index.html" if published
end
def git_dependencies_static
descendents + active_storage_blobs + siblings
def git_dependencies(website)
[self] + descendents + active_storage_blobs + siblings
end
def git_destroy_dependencies_static
descendents + active_storage_blobs
def git_destroy_dependencies(website)
[self] + descendents + active_storage_blobs
end
def to_s
......
......@@ -68,15 +68,15 @@ class Communication::Website::Post < ApplicationRecord
"/#{website.posts_github_directory}/#{published_at.strftime "%Y/%m/%d"}/#{slug}/"
end
def git_path_static
def git_path(website)
"content/posts/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at
end
def git_dependencies_static
[author] + categories + active_storage_blobs
def git_dependencies(website)
[self] + [author] + categories + active_storage_blobs
end
def git_destroy_dependencies_static
def git_destroy_dependencies
explicit_active_storage_blobs
end
......
......@@ -8,7 +8,7 @@ module WithGit
dependent: :destroy
end
def git_path_static
def git_path(website)
raise NotImplementedError
end
......@@ -37,12 +37,9 @@ module WithGit
def sync_with_git
websites_for_self.each do |website|
identifiers(website: website).each do |identifier|
Communication::Website::GitFile.sync website, self, identifier
dependencies = send("git_dependencies_#{identifier}").flatten.uniq.compact
dependencies.each do |object|
Communication::Website::GitFile.sync website, object, identifier
end
dependencies = git_dependencies(website).flatten.uniq.compact
dependencies.each do |object|
Communication::Website::GitFile.sync website, object
end
website.git_repository.sync!
end
......@@ -51,12 +48,9 @@ module WithGit
def destroy_from_git
websites_for_self.each do |website|
identifiers(website: website).each do |identifier|
Communication::Website::GitFile.sync website, self, identifier, destroy: true
dependencies = send("git_destroy_dependencies_#{identifier}").flatten.uniq.compact
dependencies.each do |object|
Communication::Website::GitFile.sync website, object, identifier, destroy: true
end
dependencies = git_destroy_dependencies(website).flatten.uniq.compact
dependencies.each do |object|
Communication::Website::GitFile.sync website, object, destroy: true
end
website.git_repository.sync!
end
......@@ -76,16 +70,11 @@ module WithGit
end
end
# Overridden for multiple files generation
def identifiers(website: nil)
[:static]
def git_dependencies(website = nil)
[self]
end
def git_dependencies_static
[]
end
def git_destroy_dependencies_static
[]
def git_destroy_dependencies(website = nil)
[self]
end
end
......@@ -116,11 +116,11 @@ class Education::Program < ApplicationRecord
best_image
end
def git_path_static
def git_path
"content/programs/#{path}/_index.html"
end
def git_dependencies_static
def git_dependencies
(
active_storage_blobs +
university_people_through_teachers +
......@@ -128,7 +128,7 @@ class Education::Program < ApplicationRecord
)
end
def git_destroy_dependencies_static
def git_destroy_dependencies
explicit_active_storage_blobs
end
......
......@@ -44,7 +44,7 @@ class Education::School < ApplicationRecord
"#{name}"
end
def git_path_static
def git_path
"data/school.yml"
end
end
......@@ -35,15 +35,15 @@ class Research::Journal < ApplicationRecord
"#{title}"
end
def git_path_static
def git_path
"data/journal.yml"
end
def git_dependencies_static
def git_dependencies
articles + volumes + researchers
end
def git_destroy_dependencies_static
def git_destroy_dependencies
articles + volumes
end
end
......@@ -55,11 +55,11 @@ class Research::Journal::Article < ApplicationRecord
"/assets/articles/#{id}/#{pdf.filename}"
end
def git_path_static
def git_path
"content/articles/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at
end
def git_dependencies_static
def git_dependencies
researchers
end
......
......@@ -43,15 +43,15 @@ class Research::Journal::Volume < ApplicationRecord
journal.website
end
def git_path_static
def git_path
"content/volumes/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" if published_at
end
def git_dependencies_static
def git_dependencies
articles + researchers + active_storage_blobs
end
def git_destroy_dependencies_static
def git_destroy_dependencies
active_storage_blobs
end
......
......@@ -96,77 +96,44 @@ class University::Person < ApplicationRecord
end
def websites
Communication::Website.where(id: [
author_website_ids,
researcher_website_ids,
teacher_website_ids
].flatten.uniq)
university.communication_websites
end
def identifiers(website: nil)
list = []
[:author, :researcher, :teacher, :administrator].each do |role|
list << role if public_send("is_#{role.to_s}_for_website", website)
end
list << :static unless list.empty?
list
def git_path(website)
"content/persons/#{slug}.html" if for_website?(website)
end
def is_author_for_website(website)
is_author && communication_website_posts.published.where(communication_website_id: website&.id).any?
def git_dependencies(website)
dependencies = []
dependencies << self if for_website?(website)
dependencies << administrator if administrator.for_website?(website)
dependencies << author if author.for_website?(website)
dependencies << researcher if researcher.for_website?(website)
dependencies << teacher if teacher.for_website?(website)
dependencies
end
def is_researcher_for_website(website)
is_researcher
def administrator
@administrator ||= University::Person::Administrator.find(id)
end
def is_teacher_for_website(website)
is_teacher && website.programs.published.joins(:teachers).where(education_program_teachers: { person_id: id }).any?
def author
@author ||= University::Person::Author.find(id)
end
def is_administrator_for_website(website)
# TODO
is_administrative
def researcher
@researcher ||= University::Person::Researcher.find(id)
end
def git_path_static
"content/persons/#{slug}.html"
def teacher
@teacher ||= University::Person::Teacher.find(id)
end
def git_path_author
"content/authors/#{slug}/_index.html"
end
def git_path_researcher
"content/researchers/#{slug}/_index.html"
end
def git_path_teacher
"content/teachers/#{slug}/_index.html"
end
def git_path_administrator
"content/administrators/#{slug}/_index.html"
end
def git_dependencies_static
[]
end
def git_dependencies_author
[]
end
def git_dependencies_researcher
[]
end
def git_dependencies_teacher
[]
end
def git_dependencies_administrator
[]
def for_website?(website)
administrator.for_website?(website) ||
author.for_website?(website) ||
researcher.for_website?(website) ||
teacher.for_website?(website)
end
protected
......
class University::Person::Administrator < University::Person
def self.polymorphic_name
'University::Person::Administrator'
end
def git_path(website)
"content/administrators/#{slug}/_index.html" if for_website?(website)
end
def for_website?(website)
# TODO
is_administrative
end
end
class University::Person::Author < University::Person
def self.polymorphic_name
'University::Person::Author'
end
def git_path(website)
"content/authors/#{slug}/_index.html" if for_website?(website)
end
def for_website?(website)
is_author && communication_website_posts.published
.where(communication_website_id: website&.id)
.any?
end
end
class University::Person::Researcher < University::Person
def self.polymorphic_name
'University::Person::Researcher'
end
def git_path(website)
"content/researchers/#{slug}/_index.html" if for_website?(website)
end
def for_website?(website)
# TODO
is_researcher
end
end
class University::Person::Author
include WithGit
class University::Person::Teacher < University::Person
def self.polymorphic_name
'University::Person::Teacher'
end
def git_path(website)
"content/teachers/#{slug}/_index.html" if for_website?(website)
end
def for_website?(website)
is_teacher && website.programs
.published
.joins(:teachers)
.where(education_program_teachers: { person_id: id })
.any?
end
end
---
title: >
Responsabilités de <%= @person.to_s %>
person: >
<%= @person.to_s %>
slug: "<%= @person.slug %>"
---
---
title: >
Actualités de <%= @person.to_s %>
person: >
<%= @person.to_s %>
slug: "<%= @person.slug %>"
---
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