@@ -104,7 +104,7 @@ impl Template {
104
104
id : raw. id . clone ( ) ,
105
105
description : raw. description . clone ( ) ,
106
106
trigger : Self :: parse_trigger_type ( raw. trigger_type , layout) ,
107
- variants : Self :: parse_template_variants ( raw. add_component ) ,
107
+ variants : Self :: parse_template_variants ( raw. new_application , raw . add_component ) ,
108
108
parameters : Self :: parse_parameters ( & raw . parameters) ?,
109
109
custom_filters : Self :: load_custom_filters ( layout, & raw . custom_filters) ?,
110
110
snippets_dir,
@@ -200,21 +200,41 @@ impl Template {
200
200
}
201
201
202
202
fn parse_template_variants (
203
+ new_application : Option < RawTemplateVariant > ,
203
204
add_component : Option < RawTemplateVariant > ,
204
205
) -> HashMap < TemplateVariantKind , TemplateVariant > {
205
206
let mut variants = HashMap :: default ( ) ;
206
- // TODO: in future we might have component-only templates
207
- variants. insert (
208
- TemplateVariantKind :: NewApplication ,
209
- TemplateVariant :: default ( ) ,
210
- ) ;
211
- if let Some ( ac) = add_component {
212
- let vt = Self :: parse_template_variant ( ac) ;
207
+ if let Some ( vt) = Self :: get_variant ( new_application, true ) {
208
+ variants. insert ( TemplateVariantKind :: NewApplication , vt) ;
209
+ }
210
+ if let Some ( vt) = Self :: get_variant ( add_component, false ) {
213
211
variants. insert ( TemplateVariantKind :: AddComponent , vt) ;
214
212
}
215
213
variants
216
214
}
217
215
216
+ fn get_variant (
217
+ raw : Option < RawTemplateVariant > ,
218
+ default_supported : bool ,
219
+ ) -> Option < TemplateVariant > {
220
+ match raw {
221
+ None => {
222
+ if default_supported {
223
+ Some ( Default :: default ( ) )
224
+ } else {
225
+ None
226
+ }
227
+ }
228
+ Some ( rv) => {
229
+ if rv. supported . unwrap_or ( true ) {
230
+ Some ( Self :: parse_template_variant ( rv) )
231
+ } else {
232
+ None
233
+ }
234
+ }
235
+ }
236
+ }
237
+
218
238
fn parse_template_variant ( raw : RawTemplateVariant ) -> TemplateVariant {
219
239
TemplateVariant {
220
240
skip_files : raw. skip_files . unwrap_or_default ( ) ,
0 commit comments