@rhinostone/swig-django 2.10.0 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/lib/index.js +1 -1
- package/lib/parser.js +22 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,8 +24,8 @@ var out = swig.render('Hello, {{ name|upper }}!', {
|
|
|
24
24
|
// => Hello, WORLD!
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
Supported surface
|
|
28
|
-
|
|
27
|
+
Supported surface
|
|
28
|
+
-----------------
|
|
29
29
|
|
|
30
30
|
Renders real Django templates — everything below was cross-checked against Django 5.2.
|
|
31
31
|
|
|
@@ -33,6 +33,7 @@ Renders real Django templates — everything below was cross-checked against Dja
|
|
|
33
33
|
* **Variable resolution** — Django-faithful attribute / dictionary / index lookup. Callable attributes are auto-called (honoring `alters_data` / `do_not_call_in_templates`), numeric indexing works (`{{ list.0 }}`), and dicts iterate via `.keys` / `.values` / `.items`.
|
|
34
34
|
* **Filter arguments** — Django colon syntax (`{{ value|date:"Y-m-d" }}`).
|
|
35
35
|
* **Filters** — 42 built-ins (`add`, `addslashes`, `capfirst`, `center`, `cut`, `date`, `default`, `default_if_none`, `divisibleby`, `escape` / `e`, `escapejs`, `filesizeformat`, `first`, `floatformat`, `force_escape`, `get_digit`, `iriencode`, `join`, `last`, `length`, `linebreaks`, `linebreaksbr`, `linenumbers`, `ljust`, `lower`, `make_list`, `phone2numeric`, `pluralize`, `rjust`, `safe`, `slice`, `slugify`, `striptags`, `time`, `title`, `truncatechars`, `truncatewords`, `upper`, `urlencode`, `wordcount`, `wordwrap`, `yesno`). See `lib/filters.js` for the full list.
|
|
36
|
+
* **Equality** — `==`, `!=` and `in` compare as Python does: a string never equals a number, and lists and mappings compare item by item.
|
|
36
37
|
* **Unknown names** — a filter name the instance does not hold is a compile error wherever it stands, as in Django. Register custom filters before the compile that uses them.
|
|
37
38
|
* **Async** — `renderFile(path, locals, cb)` against a loader with `async === true`, or `compileFile` with `codegenMode: 'async'`; `renderFileAsync` / `compileFileAsync` still work but are deprecated.
|
|
38
39
|
|
package/lib/index.js
CHANGED
package/lib/parser.js
CHANGED
|
@@ -25,6 +25,23 @@ function escapeRegExp(str) {
|
|
|
25
25
|
*/
|
|
26
26
|
var _reserved = ['break', 'case', 'catch', 'continue', 'debugger', 'default', 'delete', 'do', 'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with'];
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Build the IR of `left == right` or `left != right`, flagged so swig-core
|
|
30
|
+
* emits Python's equality (`_utils.pyEq`) instead of JavaScript's loose
|
|
31
|
+
* operators.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} op `==` or `!=`.
|
|
34
|
+
* @param {object} left Left operand IR.
|
|
35
|
+
* @param {object} right Right operand IR.
|
|
36
|
+
* @return {object} IRBinaryOp.
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
function equality(op, left, right) {
|
|
40
|
+
var node = ir.binaryOp(op, left, right);
|
|
41
|
+
node.pyEq = 'django';
|
|
42
|
+
return node;
|
|
43
|
+
}
|
|
44
|
+
|
|
28
45
|
/**
|
|
29
46
|
* Build the IR of `left in right`, or of `left not in right` when `negate`
|
|
30
47
|
* is set: a BinaryOp `in` flagged with this flavor's name, so swig-core
|
|
@@ -533,7 +550,11 @@ exports.parseExpr = function (tokens, filters, _posOut, _scope) {
|
|
|
533
550
|
continue;
|
|
534
551
|
}
|
|
535
552
|
var right = parseExpression(info.prec + 1);
|
|
536
|
-
|
|
553
|
+
if (info.op === 'in' || info.op === 'not in') {
|
|
554
|
+
left = membership(left, right, info.op === 'not in');
|
|
555
|
+
} else {
|
|
556
|
+
left = (info.op === '==' || info.op === '!=') ? equality(info.op, left, right) : ir.binaryOp(info.op, left, right);
|
|
557
|
+
}
|
|
537
558
|
}
|
|
538
559
|
return left;
|
|
539
560
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhinostone/swig-django",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "Django-syntax frontend for the @rhinostone/swig-core template engine. Part of the @rhinostone/swig multi-flavor family.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"template",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"node": ">=12"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@rhinostone/swig-core": "2.
|
|
25
|
+
"@rhinostone/swig-core": "2.11.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|