Skip to content

Commit 2495b6d

Browse files
detect_overwritten_templates task has been added
1 parent 1d797fc commit 2495b6d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/tasks/redmine_plugin_kit.rake

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,39 @@ namespace :redmine_plugin_kit do
7979
puts plugin_settings[setting]
8080
end
8181
end
82+
83+
desc 'Detects templates from the plugin that override Redmine core templates'
84+
task detect_overwritten_templates: :environment do
85+
redmine_views_root = Rails.root.join 'app/views'
86+
87+
Rails.root.glob('plugins/*').each do |plugin_path|
88+
plugin_path = plugin_path.to_s
89+
plugin_views = Dir.glob "#{plugin_path}/app/views/**/*.{erb,slim}"
90+
overwritten = []
91+
92+
plugin_views.each do |plugin_file|
93+
relative_path = plugin_file.sub %r{^#{Regexp.escape plugin_path}/app/views/}, ''
94+
base_path = relative_path.sub(/\.(erb|slim)$/, '')
95+
redmine_template = redmine_views_root.join "#{base_path}.erb"
96+
97+
overwritten << "app/views/#{base_path}.erb" if File.exist? redmine_template
98+
end
99+
100+
output_file = File.join plugin_path, '.overwritten_templates'
101+
previous_content = if File.exist? output_file
102+
lines = File.read(output_file).lines.map(&:strip)
103+
lines.sort
104+
else
105+
[]
106+
end
107+
new_content = overwritten.sort
108+
109+
if previous_content == new_content
110+
puts "✔️ No changes for: #{File.basename plugin_path}"
111+
else
112+
File.write output_file, "#{new_content.join "\n"}\n"
113+
puts "✅ Updated: #{output_file}"
114+
end
115+
end
116+
end
82117
end

0 commit comments

Comments
 (0)