From f5381931a140fd70ee218a4dfebe279f7a192156 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Mon, 3 Jan 2022 22:06:31 +0100
Subject: [PATCH] page saves descendents

---
 app/models/communication/website/git_file.rb |  5 +++++
 app/models/communication/website/page.rb     |  4 ++++
 app/models/concerns/with_git.rb              | 23 ++++++++------------
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/app/models/communication/website/git_file.rb b/app/models/communication/website/git_file.rb
index ebf1afb61..d67ff35c1 100644
--- a/app/models/communication/website/git_file.rb
+++ b/app/models/communication/website/git_file.rb
@@ -25,6 +25,11 @@ class Communication::Website::GitFile < ApplicationRecord
   belongs_to :website, class_name: 'Communication::Website'
   belongs_to :about, polymorphic: true
 
+  def self.sync(website, object, identifier)
+    git_file = where(website: website, about: object, identifier: identifier).first_or_create
+    website.git_repository.add_git_file git_file
+  end
+
   def synced?
     previous_path == path && previous_sha == sha
   end
diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb
index 6ff766a5d..ac9a2b009 100644
--- a/app/models/communication/website/page.rb
+++ b/app/models/communication/website/page.rb
@@ -75,6 +75,10 @@ class Communication::Website::Page < ApplicationRecord
     "content/pages/#{path}/_index.html".gsub(/\/+/, '/')
   end
 
+  def git_dependencies(identifier)
+    descendents
+  end
+
   def list_of_other_pages
     website.list_of_pages.reject! { |p| p[:id] == id }
   end
diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb
index f078c1bc0..d749a1403 100644
--- a/app/models/concerns/with_git.rb
+++ b/app/models/concerns/with_git.rb
@@ -11,8 +11,10 @@ module WithGit
   def sync_with_git
     websites.each do |website|
       identifiers.each do |identifier|
-        git_file = git_files.where(website: website, about: self, identifier: identifier).first_or_create
-        website.git_repository.add_git_file git_file
+        Communication::Website::GitFile.sync website, self, identifier
+        git_dependencies(identifier).each do |object|
+          Communication::Website::GitFile.sync website, object, identifier
+        end
       end
       website.git_repository.sync!
     end
@@ -21,7 +23,11 @@ module WithGit
 
 
   def git_path_static
-    ""
+    ''
+  end
+
+  def git_dependencies(identifier)
+    []
   end
 
   # Overridden for multiple files generation
@@ -33,15 +39,4 @@ module WithGit
   def websites
     [website]
   end
-
-  protected
-
-  def sync_git_files
-    websites.each do |website|
-      identifiers.each do |identifier|
-        git_file = git_files.where(website: website, about: self, identifier: identifier).first_or_create
-        website.sync_file git_file
-      end
-    end
-  end
 end
-- 
GitLab