diff --git a/app/models/communication/website/git_file.rb b/app/models/communication/website/git_file.rb index ebf1afb61901309e899d9034cae5763e1b9d7e52..d67ff35c18d5207b47be73b70174cea251f10be1 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 6ff766a5d8ec8104d3e18dd0adea3b01d80d0377..ac9a2b009c2901f01b596f0ddf82010bc2ff9d0b 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 f078c1bc066118f4d51c13959fd9da8a952f70a8..d749a14032d2ae5f3e1f7f887fc0cd57e7c88240 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