File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff 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
82117end
You can’t perform that action at this time.
0 commit comments