Skip to content

Commit e233619

Browse files
fmt
1 parent 5d6e146 commit e233619

File tree

2 files changed

+53
-60
lines changed

2 files changed

+53
-60
lines changed

crates/djls-server/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl TemplateDb for DjangoDatabase {
192192
// If no settings, just use built-in specs
193193
djls_templates::templatetags::django_builtin_specs()
194194
};
195-
195+
196196
Arc::new(tag_specs)
197197
}
198198
}

crates/djls-templates/src/templatetags/builtins.rs

Lines changed: 52 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ impl TagBuilder {
4040
self
4141
}
4242

43-
fn with_end_args(mut self, end_name: &'static str, args: Vec<(&'static str, bool, ArgType)>) -> Self {
43+
fn with_end_args(
44+
mut self,
45+
end_name: &'static str,
46+
args: Vec<(&'static str, bool, ArgType)>,
47+
) -> Self {
4448
self.end_tag = Some((end_name, args));
4549
self
4650
}
@@ -149,15 +153,16 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
149153
// Control flow tags
150154
TagBuilder::new("autoescape")
151155
.with_end("endautoescape")
152-
.with_args(vec![choice("mode", vec!["on".to_string(), "off".to_string()])])
156+
.with_args(vec![choice(
157+
"mode",
158+
vec!["on".to_string(), "off".to_string()],
159+
)])
153160
.build(),
154-
155161
TagBuilder::new("if")
156162
.with_end("endif")
157163
.with_intermediate(vec!["elif", "else"])
158164
.with_args(vec![expr("condition")])
159165
.build(),
160-
161166
TagBuilder::new("for")
162167
.with_end("endfor")
163168
.with_intermediate(vec!["empty"])
@@ -168,28 +173,23 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
168173
opt_literal("reversed"),
169174
])
170175
.build(),
171-
172176
TagBuilder::new("ifchanged")
173177
.with_end("endifchanged")
174178
.with_intermediate(vec!["else"])
175179
.with_args(vec![opt_varargs("variables")])
176180
.build(),
177-
178181
TagBuilder::new("with")
179182
.with_end("endwith")
180183
.with_args(vec![varargs("assignments")])
181184
.build(),
182-
183185
// Block tags
184186
TagBuilder::new("block")
185187
.with_end_args("endblock", vec![opt_var("name")])
186188
.with_args(vec![var("name")])
187189
.build(),
188-
189190
TagBuilder::new("extends")
190191
.with_args(vec![string("template")])
191192
.build(),
192-
193193
TagBuilder::new("include")
194194
.with_args(vec![
195195
string("template"),
@@ -198,36 +198,26 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
198198
opt_literal("only"),
199199
])
200200
.build(),
201-
202201
// Comments and literals
203-
TagBuilder::new("comment")
204-
.with_end("endcomment")
205-
.build(),
206-
202+
TagBuilder::new("comment").with_end("endcomment").build(),
207203
TagBuilder::new("verbatim")
208204
.with_end("endverbatim")
209205
.with_args(vec![opt_string("name")])
210206
.build(),
211-
212207
TagBuilder::new("spaceless")
213208
.with_end("endspaceless")
214209
.build(),
215-
216210
// Template loading
217211
TagBuilder::new("load")
218212
.with_args(vec![varargs("libraries")])
219213
.build(),
220-
221214
// CSRF token
222-
TagBuilder::new("csrf_token")
223-
.build(),
224-
215+
TagBuilder::new("csrf_token").build(),
225216
// Filters
226217
TagBuilder::new("filter")
227218
.with_end("endfilter")
228219
.with_args(vec![expr("filter_expr")])
229220
.build(),
230-
231221
// Variables and display
232222
TagBuilder::new("cycle")
233223
.with_args(vec![
@@ -236,11 +226,9 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
236226
opt_var("varname"),
237227
])
238228
.build(),
239-
240229
TagBuilder::new("firstof")
241230
.with_args(vec![varargs("variables")])
242231
.build(),
243-
244232
TagBuilder::new("regroup")
245233
.with_args(vec![
246234
var("list"),
@@ -250,7 +238,6 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
250238
var("grouped"),
251239
])
252240
.build(),
253-
254241
// Date and time
255242
TagBuilder::new("now")
256243
.with_args(vec![
@@ -259,7 +246,6 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
259246
opt_var("varname"),
260247
])
261248
.build(),
262-
263249
// URLs and static files
264250
TagBuilder::new("url")
265251
.with_args(vec![
@@ -269,11 +255,9 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
269255
opt_var("varname"),
270256
])
271257
.build(),
272-
273258
TagBuilder::new("static")
274259
.with_args(vec![string("path")])
275260
.build(),
276-
277261
// Template tags
278262
TagBuilder::new("templatetag")
279263
.with_args(vec![choice(
@@ -290,7 +274,6 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
290274
],
291275
)])
292276
.build(),
293-
294277
// Utilities
295278
TagBuilder::new("widthratio")
296279
.with_args(vec![
@@ -301,18 +284,17 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
301284
opt_var("varname"),
302285
])
303286
.build(),
304-
305287
TagBuilder::new("lorem")
306288
.with_args(vec![
307289
opt_var("count"),
308-
opt_choice("method", vec!["w".to_string(), "p".to_string(), "b".to_string()]),
290+
opt_choice(
291+
"method",
292+
vec!["w".to_string(), "p".to_string(), "b".to_string()],
293+
),
309294
opt_literal("random"),
310295
])
311296
.build(),
312-
313-
TagBuilder::new("debug")
314-
.build(),
315-
297+
TagBuilder::new("debug").build(),
316298
// Cache tags
317299
TagBuilder::new("cache")
318300
.with_end("endcache")
@@ -322,13 +304,14 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
322304
opt_varargs("variables"),
323305
])
324306
.build(),
325-
326307
// Internationalization
327308
TagBuilder::new("localize")
328309
.with_end("endlocalize")
329-
.with_args(vec![opt_choice("mode", vec!["on".to_string(), "off".to_string()])])
310+
.with_args(vec![opt_choice(
311+
"mode",
312+
vec!["on".to_string(), "off".to_string()],
313+
)])
330314
.build(),
331-
332315
TagBuilder::new("blocktranslate")
333316
.with_end("endblocktranslate")
334317
.with_intermediate(vec!["plural"])
@@ -340,7 +323,6 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
340323
opt_var("varname"),
341324
])
342325
.build(),
343-
344326
TagBuilder::new("trans")
345327
.with_args(vec![
346328
string("message"),
@@ -350,13 +332,14 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
350332
opt_literal("noop"),
351333
])
352334
.build(),
353-
354335
// Timezone tags
355336
TagBuilder::new("localtime")
356337
.with_end("endlocaltime")
357-
.with_args(vec![opt_choice("mode", vec!["on".to_string(), "off".to_string()])])
338+
.with_args(vec![opt_choice(
339+
"mode",
340+
vec!["on".to_string(), "off".to_string()],
341+
)])
358342
.build(),
359-
360343
TagBuilder::new("timezone")
361344
.with_end("endtimezone")
362345
.with_args(vec![var("timezone")])
@@ -374,7 +357,7 @@ static BUILTIN_SPECS: LazyLock<TagSpecs> = LazyLock::new(|| {
374357
});
375358

376359
/// Returns all built-in Django template tag specifications
377-
///
360+
///
378361
/// This function returns a clone of the statically initialized built-in specs.
379362
/// The actual specs are only built once on first access and then cached.
380363
#[must_use]
@@ -389,13 +372,16 @@ mod tests {
389372
#[test]
390373
fn test_builtin_specs_non_empty() {
391374
let specs = django_builtin_specs();
392-
375+
393376
// Verify we have specs loaded
394-
assert!(specs.iter().count() > 0, "Should have loaded at least one spec");
395-
377+
assert!(
378+
specs.iter().count() > 0,
379+
"Should have loaded at least one spec"
380+
);
381+
396382
// Check a key tag is present as a smoke test
397383
assert!(specs.get("if").is_some(), "'if' tag should be present");
398-
384+
399385
// Verify all tag names are non-empty
400386
for (name, _) in specs.iter() {
401387
assert!(!name.is_empty(), "Tag name should not be empty");
@@ -424,7 +410,7 @@ mod tests {
424410
"localtime",
425411
"timezone",
426412
];
427-
413+
428414
// Single tags that should be present
429415
let expected_single_tags = [
430416
"csrf_token",
@@ -445,7 +431,9 @@ mod tests {
445431
];
446432

447433
for tag in expected_block_tags {
448-
let spec = specs.get(tag).unwrap_or_else(|| panic!("{tag} tag should be present"));
434+
let spec = specs
435+
.get(tag)
436+
.unwrap_or_else(|| panic!("{tag} tag should be present"));
449437
assert!(spec.end_tag.is_some(), "{tag} should have an end tag");
450438
}
451439

@@ -471,11 +459,11 @@ mod tests {
471459
fn test_if_tag_structure() {
472460
let specs = django_builtin_specs();
473461
let if_tag = specs.get("if").expect("if tag should exist");
474-
462+
475463
assert_eq!(if_tag.name, Some("if".to_string()));
476464
assert!(if_tag.end_tag.is_some());
477465
assert_eq!(if_tag.end_tag.as_ref().unwrap().name, "endif");
478-
466+
479467
let intermediates = if_tag.intermediate_tags.as_ref().unwrap();
480468
assert_eq!(intermediates.len(), 2);
481469
assert_eq!(intermediates[0].name, "elif");
@@ -486,15 +474,15 @@ mod tests {
486474
fn test_for_tag_structure() {
487475
let specs = django_builtin_specs();
488476
let for_tag = specs.get("for").expect("for tag should exist");
489-
477+
490478
assert_eq!(for_tag.name, Some("for".to_string()));
491479
assert!(for_tag.end_tag.is_some());
492480
assert_eq!(for_tag.end_tag.as_ref().unwrap().name, "endfor");
493-
481+
494482
let intermediates = for_tag.intermediate_tags.as_ref().unwrap();
495483
assert_eq!(intermediates.len(), 1);
496484
assert_eq!(intermediates[0].name, "empty");
497-
485+
498486
// Check args structure
499487
assert!(!for_tag.args.is_empty(), "for tag should have arguments");
500488
}
@@ -503,7 +491,7 @@ mod tests {
503491
fn test_block_tag_with_end_args() {
504492
let specs = django_builtin_specs();
505493
let block_tag = specs.get("block").expect("block tag should exist");
506-
494+
507495
let end_tag = block_tag.end_tag.as_ref().unwrap();
508496
assert_eq!(end_tag.name, "endblock");
509497
assert_eq!(end_tag.args.len(), 1);
@@ -514,15 +502,20 @@ mod tests {
514502
#[test]
515503
fn test_single_tag_structure() {
516504
let specs = django_builtin_specs();
517-
505+
518506
// Test a single tag has no end tag or intermediates
519-
let csrf_tag = specs.get("csrf_token").expect("csrf_token tag should exist");
507+
let csrf_tag = specs
508+
.get("csrf_token")
509+
.expect("csrf_token tag should exist");
520510
assert!(csrf_tag.end_tag.is_none());
521511
assert!(csrf_tag.intermediate_tags.is_none());
522-
512+
523513
// Test extends tag with args
524514
let extends_tag = specs.get("extends").expect("extends tag should exist");
525515
assert!(extends_tag.end_tag.is_none());
526-
assert!(!extends_tag.args.is_empty(), "extends tag should have arguments");
516+
assert!(
517+
!extends_tag.args.is_empty(),
518+
"extends tag should have arguments"
519+
);
527520
}
528-
}
521+
}

0 commit comments

Comments
 (0)