@@ -123,6 +123,7 @@ def process_html(html)
123
123
errors << I18n . t ( "themes.errors.optimized_link" ) if contains_optimized_link? ( html )
124
124
125
125
js_compiler = ThemeJavascriptCompiler . new ( theme_id , self . theme . name )
126
+ deprecated_template_names = [ ]
126
127
127
128
doc = Nokogiri ::HTML5 . fragment ( html )
128
129
@@ -144,6 +145,7 @@ def process_html(html)
144
145
"discourse/templates/#{ name . delete_prefix ( "/" ) } " ,
145
146
hbs_template ,
146
147
)
148
+ deprecated_template_names << name
147
149
end
148
150
rescue ThemeJavascriptCompiler ::CompileError => ex
149
151
js_compiler . append_js_error ( "discourse/templates/#{ name } " , ex . message )
@@ -153,6 +155,28 @@ def process_html(html)
153
155
node . remove
154
156
end
155
157
158
+ if deprecated_template_names . present?
159
+ js = <<~JS
160
+ import deprecated from "discourse/lib/deprecated";
161
+
162
+ export default {
163
+ initialize(){
164
+ const names = #{ deprecated_template_names . to_json } ;
165
+ names.forEach((name) => {
166
+ deprecated(
167
+ `[${name}] adding templates to a theme using <script type='text/x-handlebars'> is deprecated. Move to dedicated .hbs or .gjs files.`,
168
+ {
169
+ id: "discourse.script-tag-hbs",
170
+ url: "https://meta.discourse.org/t/366482",
171
+ }
172
+ )
173
+ });
174
+ }
175
+ }
176
+ JS
177
+ js_compiler . append_module ( js , "discourse/initializers/script-tag-hbs-deprecations" , "js" )
178
+ end
179
+
156
180
doc
157
181
. css ( 'script[type="text/discourse-plugin"]' )
158
182
. each_with_index do |node , index |
@@ -165,12 +189,20 @@ def process_html(html)
165
189
begin
166
190
js = <<~JS
167
191
import { withPluginApi } from "discourse/lib/plugin-api";
192
+ import deprecated from "discourse/lib/deprecated";
168
193
169
194
export default {
170
195
name: #{ initializer_name . inspect } ,
171
196
after: "inject-objects",
172
197
173
198
initialize() {
199
+ deprecated(
200
+ "Adding JS code using <script type='text/x-handlebars'> is deprecated. Move this code to a dedicated JavaScript file.",
201
+ {
202
+ id: "discourse.script-tag-discourse-plugin",
203
+ url: "https://meta.discourse.org/t/366482",
204
+ }
205
+ )
174
206
withPluginApi(#{ version . inspect } , (api) => {
175
207
#{ node . inner_html }
176
208
});
0 commit comments