miki-template 1.2.0 → 1.3.6

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.
Files changed (105) hide show
  1. package/.github/release-notes/v1.3.1.md +55 -0
  2. package/.github/release-notes/v1.3.3.md +77 -0
  3. package/.github/workflows/ci.yml +38 -54
  4. package/.github/workflows/release.yml +106 -0
  5. package/AGENT.md +71 -71
  6. package/API_REFERENCE.md +314 -314
  7. package/CHANGELOG.md +173 -97
  8. package/CODE_OF_CONDUCT.md +14 -14
  9. package/CONTRIBUTING.md +27 -27
  10. package/README.md +342 -304
  11. package/ROADMAP.md +40 -40
  12. package/assets/banner.png +0 -0
  13. package/benchmarks/report.json +16 -16
  14. package/benchmarks/run.js +49 -49
  15. package/benchmarks/stress.mjs +647 -0
  16. package/benchmarks/templates/large.dtpl +7 -7
  17. package/benchmarks/templates/medium.dtpl +3 -3
  18. package/benchmarks/templates/small.dtpl +7 -7
  19. package/context/component.md +109 -109
  20. package/context/prd.md +131 -131
  21. package/context/project-structure.md +33 -33
  22. package/dir/base.html +23 -0
  23. package/dir/cmpnt.html +11 -0
  24. package/dir/footer.html +3 -0
  25. package/dir/home.html +80 -0
  26. package/dir/index.html +80 -0
  27. package/dir/navbar.html +9 -0
  28. package/docs/README.md +18 -18
  29. package/docs/advanced_usage.md +71 -71
  30. package/docs/api.md +119 -102
  31. package/docs/filters.md +708 -540
  32. package/docs/installation.md +106 -106
  33. package/docs/overview.md +57 -57
  34. package/docs/partialdef.md +70 -41
  35. package/docs/security.md +27 -27
  36. package/docs/tags.md +673 -610
  37. package/docs/usage.md +646 -599
  38. package/eslint.config.mjs +42 -34
  39. package/ex.mjs +33 -0
  40. package/miki-template-extension/.github/workflows/ci.yml +116 -0
  41. package/miki-template-extension/.vscodeignore +7 -0
  42. package/miki-template-extension/CHANGELOG.md +99 -0
  43. package/miki-template-extension/LICENSE +21 -21
  44. package/miki-template-extension/README.md +273 -82
  45. package/miki-template-extension/extension.js +1013 -0
  46. package/miki-template-extension/icon.png +0 -0
  47. package/miki-template-extension/icon.svg +10 -10
  48. package/miki-template-extension/miki-template-1.7.1.vsix +0 -0
  49. package/miki-template-extension/package.json +280 -46
  50. package/miki-template-extension/snippets/miki-template.json +717 -177
  51. package/miki-template-extension/syntaxes/language-configuration.json +114 -26
  52. package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +355 -146
  53. package/miki-template-extension/tests/grammar-tests.json +162 -0
  54. package/miki-template-extension/tests/run-grammar-tests.js +82 -0
  55. package/package.json +37 -31
  56. package/sample-app/package-lock.json +901 -0
  57. package/sample-app/package.json +9 -0
  58. package/sample-app/server.js +14 -0
  59. package/sample-app/views/index.html +1 -0
  60. package/scripts/build-vsix.js +129 -0
  61. package/scripts/build-vsix.ps1 +15 -0
  62. package/snippets/miki-template.json +177 -177
  63. package/src/asyncRender.js +20 -20
  64. package/src/cache.js +80 -41
  65. package/src/context.js +126 -122
  66. package/src/context_processors.js +48 -41
  67. package/src/esm.mjs +84 -72
  68. package/src/filters.js +975 -527
  69. package/src/i18n.js +171 -171
  70. package/src/index.js +974 -454
  71. package/src/lexer.js +114 -92
  72. package/src/libraries.js +371 -240
  73. package/src/parser.js +270 -250
  74. package/src/security.js +53 -51
  75. package/src/tags/control.js +719 -590
  76. package/src/tags/extra.js +154 -0
  77. package/src/tags/helpers.js +26 -26
  78. package/src/tags/i18n.js +256 -230
  79. package/src/tags/inheritance.js +335 -216
  80. package/src/tags/registry.js +18 -18
  81. package/src/tags/util.js +400 -322
  82. package/src/types.d.ts +107 -107
  83. package/syntaxes/language-configuration.json +26 -26
  84. package/syntaxes/miki-template.tmLanguage.json +146 -146
  85. package/tests/asyncRender.test.js +17 -17
  86. package/tests/base.html +6 -6
  87. package/tests/child.html +3 -3
  88. package/tests/context_processors.test.js +13 -13
  89. package/tests/esm.test.mjs +61 -26
  90. package/tests/filters.test.js +254 -99
  91. package/tests/include_security.test.js +9 -9
  92. package/tests/integration/README.md +32 -0
  93. package/tests/integration/features.test.cjs +1681 -0
  94. package/tests/integration/features.test.mjs +1697 -0
  95. package/tests/integration/templates/base.miki +6 -0
  96. package/tests/integration/templates/child.miki +6 -0
  97. package/tests/integration/templates/index.html +17 -0
  98. package/tests/lexer.test.js +45 -45
  99. package/tests/parser.test.js +57 -55
  100. package/tests/partial.html +1 -1
  101. package/tests/partialdef.test.js +79 -40
  102. package/tests/production_checks.js +57 -57
  103. package/tests/security.test.js +28 -28
  104. package/tests/tags.test.js +233 -203
  105. package/miki-template-1.2.0.vsix +0 -0
@@ -1,109 +1,109 @@
1
- # Component Hierarchy — Django-Style Template Engine (Node.js/Express)
2
-
3
- ## 📖 Purpose
4
- This document defines the **modules, responsibilities, and relationships** for the template engine. It ensures clarity in implementation and maintainability.
5
-
6
- ---
7
-
8
- ## 🧩 Core Components
9
-
10
- ### 1. **Lexer**
11
- - **Responsibility**: Tokenize template strings into `TEXT`, `VAR`, `BLOCK`.
12
- - **Inputs**: Raw template string.
13
- - **Outputs**: Token stream.
14
- - **Dependencies**: None.
15
-
16
- ### 2. **Parser**
17
- - **Responsibility**: Convert tokens into an AST (Abstract Syntax Tree).
18
- - **Inputs**: Token stream.
19
- - **Outputs**: AST nodes (`Text`, `Var`, `If`, `For`, `Block`, etc.).
20
- - **Dependencies**: Lexer.
21
-
22
- ### 3. **Renderer**
23
- - **Responsibility**: Walk AST, evaluate expressions, apply filters, render output.
24
- - **Inputs**: AST + context.
25
- - **Outputs**: Final HTML string.
26
- - **Dependencies**: Parser, Filter Registry, Tag Handlers.
27
-
28
- ---
29
-
30
- ## 🔧 Supporting Modules
31
-
32
- ### 4. **Filter Registry**
33
- - **Responsibility**: Store and apply filters.
34
- - **Built-in Filters**: `upper`, `lower`, `date`, `truncatechars`, `safe`, `escape`, etc.
35
- - **Extensibility**: Developers can register custom filters.
36
- - **Dependencies**: Renderer.
37
-
38
- ### 5. **Tag Handlers**
39
- - **Responsibility**: Implement logic for each tag.
40
- - **Control Flow**: `if`, `elif`, `else`, `for`, `empty`, `with`, `cycle`.
41
- - **Inheritance**: `extends`, `block`, `include`.
42
- - **Utilities**: `url`, `static`, `regroup`, `spaceless`, `comment`, `verbatim`.
43
- - **Security**: `autoescape`, `csrf_token`, `csp_nonce_attr`.
44
- - **Dependencies**: Renderer, Context.
45
-
46
- ### 6. **Inheritance System**
47
- - **Responsibility**: Manage parent/child templates, block overrides.
48
- - **Mechanism**: Block registry + AST merging.
49
- - **Dependencies**: Parser, Renderer.
50
-
51
- ### 7. **Context Manager**
52
- - **Responsibility**: Provide variables to templates.
53
- - **Features**: Dotted lookups (`user.name`), querystring injection, context processors.
54
- - **Dependencies**: Renderer.
55
-
56
- ---
57
-
58
- ## 🔐 Security Components
59
-
60
- ### 8. **Escaping Engine**
61
- - **Responsibility**: Autoescape HTML by default.
62
- - **Features**: `safe` filter disables escaping, `escape` forces escaping.
63
- - **Dependencies**: Renderer, Filter Registry.
64
-
65
- ---
66
-
67
- ## 📦 Integration Layer
68
-
69
- ### 9. **Express Adapter**
70
- - **Responsibility**: Integrate engine with Express.
71
- - **API**: `app.engine('dtpl', renderFile)`.
72
- - **Dependencies**: Renderer, Context Manager.
73
-
74
- ---
75
-
76
- ## 🛠️ Extensibility Components
77
-
78
- ### 10. **Custom Tag API**
79
- - **Responsibility**: Allow developers to register new tags.
80
- - **Mechanism**: Tag registry with handler functions.
81
-
82
- ### 11. **Custom Filter API**
83
- - **Responsibility**: Allow developers to register new filters.
84
- - **Mechanism**: Filter registry extension.
85
-
86
- ### 12. **Context Processors**
87
- - **Responsibility**: Inject global variables (e.g., `user`, `request`).
88
- - **Mechanism**: Middleware-like hooks.
89
-
90
- ---
91
-
92
- ## 📋 Relationships Diagram (Textual)
93
-
94
- - **Lexer → Parser → Renderer**
95
- - **Renderer → Filter Registry + Tag Handlers + Context Manager**
96
- - **Tag Handlers → Inheritance System + Escaping Engine**
97
- - **Express Adapter → Renderer**
98
- - **Custom APIs → Filter Registry + Tag Handlers**
99
- - **Context Processors → Context Manager**
100
-
101
- ---
102
-
103
- ## 🎯 Deliverables
104
- - Modular codebase with clear separation of concerns.
105
- - Each tag/filter implemented as independent handler.
106
- - Extensible APIs for developers.
107
- - Secure rendering pipeline with autoescape.
108
- - Seamless Express integration.
109
-
1
+ # Component Hierarchy — Django-Style Template Engine (Node.js/Express)
2
+
3
+ ## 📖 Purpose
4
+ This document defines the **modules, responsibilities, and relationships** for the template engine. It ensures clarity in implementation and maintainability.
5
+
6
+ ---
7
+
8
+ ## 🧩 Core Components
9
+
10
+ ### 1. **Lexer**
11
+ - **Responsibility**: Tokenize template strings into `TEXT`, `VAR`, `BLOCK`.
12
+ - **Inputs**: Raw template string.
13
+ - **Outputs**: Token stream.
14
+ - **Dependencies**: None.
15
+
16
+ ### 2. **Parser**
17
+ - **Responsibility**: Convert tokens into an AST (Abstract Syntax Tree).
18
+ - **Inputs**: Token stream.
19
+ - **Outputs**: AST nodes (`Text`, `Var`, `If`, `For`, `Block`, etc.).
20
+ - **Dependencies**: Lexer.
21
+
22
+ ### 3. **Renderer**
23
+ - **Responsibility**: Walk AST, evaluate expressions, apply filters, render output.
24
+ - **Inputs**: AST + context.
25
+ - **Outputs**: Final HTML string.
26
+ - **Dependencies**: Parser, Filter Registry, Tag Handlers.
27
+
28
+ ---
29
+
30
+ ## 🔧 Supporting Modules
31
+
32
+ ### 4. **Filter Registry**
33
+ - **Responsibility**: Store and apply filters.
34
+ - **Built-in Filters**: `upper`, `lower`, `date`, `truncatechars`, `safe`, `escape`, etc.
35
+ - **Extensibility**: Developers can register custom filters.
36
+ - **Dependencies**: Renderer.
37
+
38
+ ### 5. **Tag Handlers**
39
+ - **Responsibility**: Implement logic for each tag.
40
+ - **Control Flow**: `if`, `elif`, `else`, `for`, `empty`, `with`, `cycle`.
41
+ - **Inheritance**: `extends`, `block`, `include`.
42
+ - **Utilities**: `url`, `static`, `regroup`, `spaceless`, `comment`, `verbatim`.
43
+ - **Security**: `autoescape`, `csrf_token`, `csp_nonce_attr`.
44
+ - **Dependencies**: Renderer, Context.
45
+
46
+ ### 6. **Inheritance System**
47
+ - **Responsibility**: Manage parent/child templates, block overrides.
48
+ - **Mechanism**: Block registry + AST merging.
49
+ - **Dependencies**: Parser, Renderer.
50
+
51
+ ### 7. **Context Manager**
52
+ - **Responsibility**: Provide variables to templates.
53
+ - **Features**: Dotted lookups (`user.name`), querystring injection, context processors.
54
+ - **Dependencies**: Renderer.
55
+
56
+ ---
57
+
58
+ ## 🔐 Security Components
59
+
60
+ ### 8. **Escaping Engine**
61
+ - **Responsibility**: Autoescape HTML by default.
62
+ - **Features**: `safe` filter disables escaping, `escape` forces escaping.
63
+ - **Dependencies**: Renderer, Filter Registry.
64
+
65
+ ---
66
+
67
+ ## 📦 Integration Layer
68
+
69
+ ### 9. **Express Adapter**
70
+ - **Responsibility**: Integrate engine with Express.
71
+ - **API**: `app.engine('dtpl', renderFile)`.
72
+ - **Dependencies**: Renderer, Context Manager.
73
+
74
+ ---
75
+
76
+ ## 🛠️ Extensibility Components
77
+
78
+ ### 10. **Custom Tag API**
79
+ - **Responsibility**: Allow developers to register new tags.
80
+ - **Mechanism**: Tag registry with handler functions.
81
+
82
+ ### 11. **Custom Filter API**
83
+ - **Responsibility**: Allow developers to register new filters.
84
+ - **Mechanism**: Filter registry extension.
85
+
86
+ ### 12. **Context Processors**
87
+ - **Responsibility**: Inject global variables (e.g., `user`, `request`).
88
+ - **Mechanism**: Middleware-like hooks.
89
+
90
+ ---
91
+
92
+ ## 📋 Relationships Diagram (Textual)
93
+
94
+ - **Lexer → Parser → Renderer**
95
+ - **Renderer → Filter Registry + Tag Handlers + Context Manager**
96
+ - **Tag Handlers → Inheritance System + Escaping Engine**
97
+ - **Express Adapter → Renderer**
98
+ - **Custom APIs → Filter Registry + Tag Handlers**
99
+ - **Context Processors → Context Manager**
100
+
101
+ ---
102
+
103
+ ## 🎯 Deliverables
104
+ - Modular codebase with clear separation of concerns.
105
+ - Each tag/filter implemented as independent handler.
106
+ - Extensible APIs for developers.
107
+ - Secure rendering pipeline with autoescape.
108
+ - Seamless Express integration.
109
+
package/context/prd.md CHANGED
@@ -1,131 +1,131 @@
1
- # Django-Style Template Engine for Node.js/Express
2
-
3
- ## 📖 Overview
4
- A custom template engine for Express that replicates **Django’s template language** in Node.js. It supports variables, filters, tags, inheritance, partials, escaping, and extensibility — providing full parity with Django templates while integrating seamlessly into Express.
5
-
6
- ---
7
-
8
- ## 🎯 Goals
9
- - Full Django template feature parity in Node.js.
10
- - Simple Express integration via `app.engine`.
11
- - Extensible API for custom tags, filters, and context processors.
12
- - Secure by default (autoescape enabled).
13
- - Production-ready performance (AST caching, error handling).
14
-
15
- ---
16
-
17
- ## 🧩 Core Architecture
18
- 1. **Lexer** → Tokenizes template into `TEXT`, `VAR`, `BLOCK`.
19
- 2. **Parser** → Builds AST nodes for tags/filters.
20
- 3. **Renderer** → Walks AST, evaluates expressions, applies filters.
21
- 4. **Filter Registry** → Built-in + custom filters.
22
- 5. **Tag Handlers** → Functions for each tag (`if`, `for`, `block`, etc.).
23
- 6. **Inheritance System** → Block registry + parent merging.
24
- 7. **Express Integration** → `app.engine('dtpl', renderFile)`.
25
-
26
- ---
27
-
28
- ## 🏷️ Built-in Template Tags
29
-
30
- | Tag | Purpose | Node.js Implementation |
31
- |-----|---------|------------------------|
32
- | **autoescape** | Toggle HTML escaping. | Maintain `context.autoescape` flag. |
33
- | **block** | Define overridable content. | Store block AST in registry. |
34
- | **extends** | Template inheritance. | Load parent file, merge blocks. |
35
- | **include** | Insert partial template. | Load file, render with context. |
36
- | **if/elif/else** | Conditional rendering. | Evaluate JS expression safely. |
37
- | **for/empty** | Loop over iterable. | Inject `forloop` vars (`counter`, `first`, `last`). |
38
- | **with** | Assign temporary variable. | Extend context object. |
39
- | **cycle** | Alternate values. | Maintain cycle state per loop. |
40
- | **comment** | Ignore enclosed content. | Strip from AST. |
41
- | **verbatim** | Raw output. | Treat enclosed text as literal. |
42
- | **csrf_token** | CSRF protection. | Insert token from context. |
43
- | **csp_nonce_attr** | CSP nonce attribute. | Render `nonce="value"`. |
44
- | **url** | Generate route URL. | Integrate with Express router. |
45
- | **static** | Reference static files. | Map to Express static dir. |
46
- | **regroup** | Group list by attribute. | Use JS `reduce`. |
47
- | **spaceless** | Strip whitespace. | Regex replace in output. |
48
-
49
- ---
50
-
51
- ## 🔧 Built-in Filters
52
-
53
- | Filter | Purpose | Node.js Implementation |
54
- |--------|---------|------------------------|
55
- | **Text** | `upper`, `lower`, `title`, `capfirst`, `truncatewords`, `truncatechars`, `wordcount`, `linebreaks`, `linebreaksbr`, `striptags`, `slugify` | JS string methods, regex, libraries. |
56
- | **HTML** | `safe`, `escape` | Use `he` for escaping; safe flag. |
57
- | **List** | `length`, `join`, `slice`, `dictsort`, `dictsortreversed` | JS array methods. |
58
- | **Date/Time** | `date`, `time`, `timesince`, `timeuntil` | Wrap JS `Date` with `Intl.DateTimeFormat`. |
59
- | **Numeric** | `add`, `divisibleby`, `floatformat` | Arithmetic ops; `toFixed`. |
60
- | **Default** | `default`, `default_if_none` | Fallback values. |
61
- | **Misc** | `pluralize`, `yesno`, `filesizeformat` | String transformations; filesize units. |
62
-
63
- ---
64
-
65
- ## 🔐 Escaping & Security
66
- - Autoescape enabled by default.
67
- - `safe` filter disables escaping.
68
- - `escape` filter forces escaping.
69
- - Use `he` library for HTML entity encoding.
70
-
71
- ---
72
-
73
- ## 🛠️ Extensibility
74
- - **Custom filters**: `filters[name] = fn`.
75
- - **Custom tags**: Register handler functions in tag registry.
76
- - **Context processors**: Middleware to inject globals (e.g., `user`, `request`).
77
-
78
- ---
79
-
80
- ## 📋 Development Roadmap
81
-
82
- ### Phase 1 — Core Foundations
83
- - Lexer, parser, renderer.
84
- - Express integration.
85
-
86
- ### Phase 2 — Variables & Filters
87
- - Variables with dotted lookups.
88
- - Full filter system (text, list, date, numeric, misc).
89
- - Custom filter API.
90
-
91
- ### Phase 3 — Control Flow Tags
92
- - `if/elif/else`, `for/empty`, `with`, `cycle`, `comment`, `verbatim`.
93
-
94
- ### Phase 4 — Template Inheritance
95
- - `extends`, `block`, nested blocks.
96
- - `include` for partials.
97
-
98
- ### Phase 5 — Utilities & Helpers
99
- - `static`, `url`, `regroup`, `spaceless`.
100
-
101
- ### Phase 6 — Security
102
- - Autoescape, safe strings, escape filter.
103
-
104
- ### Phase 7 — Extensibility
105
- - Custom tags/filters.
106
- - Context processors.
107
-
108
- ### Phase 8 — Advanced Features
109
- - Querystring/context passing.
110
- - Template partials with context overrides.
111
- - Error handling.
112
- - Performance optimizations (AST caching).
113
-
114
- ### Phase 9 — Developer Experience
115
- - Documentation.
116
- - Testing suite.
117
- - Packaging as npm module.
118
- - Example apps.
119
-
120
- ---
121
-
122
- ## 🎯 Final Deliverables
123
- - **Engine core**: Lexer, parser, renderer.
124
- - **Filter library**: All Django filters.
125
- - **Tag handlers**: All Django tags.
126
- - **Inheritance system**: Full block/extends support.
127
- - **Express integration**: `app.engine('dtpl', ...)`.
128
- - **Extensibility API**: Custom tags/filters/context processors.
129
- - **Security**: Autoescape + safe strings.
130
- - **Docs & tests**: Full coverage.
131
-
1
+ # Django-Style Template Engine for Node.js/Express
2
+
3
+ ## 📖 Overview
4
+ A custom template engine for Express that replicates **Django’s template language** in Node.js. It supports variables, filters, tags, inheritance, partials, escaping, and extensibility — providing full parity with Django templates while integrating seamlessly into Express.
5
+
6
+ ---
7
+
8
+ ## 🎯 Goals
9
+ - Full Django template feature parity in Node.js.
10
+ - Simple Express integration via `app.engine`.
11
+ - Extensible API for custom tags, filters, and context processors.
12
+ - Secure by default (autoescape enabled).
13
+ - Production-ready performance (AST caching, error handling).
14
+
15
+ ---
16
+
17
+ ## 🧩 Core Architecture
18
+ 1. **Lexer** → Tokenizes template into `TEXT`, `VAR`, `BLOCK`.
19
+ 2. **Parser** → Builds AST nodes for tags/filters.
20
+ 3. **Renderer** → Walks AST, evaluates expressions, applies filters.
21
+ 4. **Filter Registry** → Built-in + custom filters.
22
+ 5. **Tag Handlers** → Functions for each tag (`if`, `for`, `block`, etc.).
23
+ 6. **Inheritance System** → Block registry + parent merging.
24
+ 7. **Express Integration** → `app.engine('dtpl', renderFile)`.
25
+
26
+ ---
27
+
28
+ ## 🏷️ Built-in Template Tags
29
+
30
+ | Tag | Purpose | Node.js Implementation |
31
+ |-----|---------|------------------------|
32
+ | **autoescape** | Toggle HTML escaping. | Maintain `context.autoescape` flag. |
33
+ | **block** | Define overridable content. | Store block AST in registry. |
34
+ | **extends** | Template inheritance. | Load parent file, merge blocks. |
35
+ | **include** | Insert partial template. | Load file, render with context. |
36
+ | **if/elif/else** | Conditional rendering. | Evaluate JS expression safely. |
37
+ | **for/empty** | Loop over iterable. | Inject `forloop` vars (`counter`, `first`, `last`). |
38
+ | **with** | Assign temporary variable. | Extend context object. |
39
+ | **cycle** | Alternate values. | Maintain cycle state per loop. |
40
+ | **comment** | Ignore enclosed content. | Strip from AST. |
41
+ | **verbatim** | Raw output. | Treat enclosed text as literal. |
42
+ | **csrf_token** | CSRF protection. | Insert token from context. |
43
+ | **csp_nonce_attr** | CSP nonce attribute. | Render `nonce="value"`. |
44
+ | **url** | Generate route URL. | Integrate with Express router. |
45
+ | **static** | Reference static files. | Map to Express static dir. |
46
+ | **regroup** | Group list by attribute. | Use JS `reduce`. |
47
+ | **spaceless** | Strip whitespace. | Regex replace in output. |
48
+
49
+ ---
50
+
51
+ ## 🔧 Built-in Filters
52
+
53
+ | Filter | Purpose | Node.js Implementation |
54
+ |--------|---------|------------------------|
55
+ | **Text** | `upper`, `lower`, `title`, `capfirst`, `truncatewords`, `truncatechars`, `wordcount`, `linebreaks`, `linebreaksbr`, `striptags`, `slugify` | JS string methods, regex, libraries. |
56
+ | **HTML** | `safe`, `escape` | Use `he` for escaping; safe flag. |
57
+ | **List** | `length`, `join`, `slice`, `dictsort`, `dictsortreversed` | JS array methods. |
58
+ | **Date/Time** | `date`, `time`, `timesince`, `timeuntil` | Wrap JS `Date` with `Intl.DateTimeFormat`. |
59
+ | **Numeric** | `add`, `divisibleby`, `floatformat` | Arithmetic ops; `toFixed`. |
60
+ | **Default** | `default`, `default_if_none` | Fallback values. |
61
+ | **Misc** | `pluralize`, `yesno`, `filesizeformat` | String transformations; filesize units. |
62
+
63
+ ---
64
+
65
+ ## 🔐 Escaping & Security
66
+ - Autoescape enabled by default.
67
+ - `safe` filter disables escaping.
68
+ - `escape` filter forces escaping.
69
+ - Use `he` library for HTML entity encoding.
70
+
71
+ ---
72
+
73
+ ## 🛠️ Extensibility
74
+ - **Custom filters**: `filters[name] = fn`.
75
+ - **Custom tags**: Register handler functions in tag registry.
76
+ - **Context processors**: Middleware to inject globals (e.g., `user`, `request`).
77
+
78
+ ---
79
+
80
+ ## 📋 Development Roadmap
81
+
82
+ ### Phase 1 — Core Foundations
83
+ - Lexer, parser, renderer.
84
+ - Express integration.
85
+
86
+ ### Phase 2 — Variables & Filters
87
+ - Variables with dotted lookups.
88
+ - Full filter system (text, list, date, numeric, misc).
89
+ - Custom filter API.
90
+
91
+ ### Phase 3 — Control Flow Tags
92
+ - `if/elif/else`, `for/empty`, `with`, `cycle`, `comment`, `verbatim`.
93
+
94
+ ### Phase 4 — Template Inheritance
95
+ - `extends`, `block`, nested blocks.
96
+ - `include` for partials.
97
+
98
+ ### Phase 5 — Utilities & Helpers
99
+ - `static`, `url`, `regroup`, `spaceless`.
100
+
101
+ ### Phase 6 — Security
102
+ - Autoescape, safe strings, escape filter.
103
+
104
+ ### Phase 7 — Extensibility
105
+ - Custom tags/filters.
106
+ - Context processors.
107
+
108
+ ### Phase 8 — Advanced Features
109
+ - Querystring/context passing.
110
+ - Template partials with context overrides.
111
+ - Error handling.
112
+ - Performance optimizations (AST caching).
113
+
114
+ ### Phase 9 — Developer Experience
115
+ - Documentation.
116
+ - Testing suite.
117
+ - Packaging as npm module.
118
+ - Example apps.
119
+
120
+ ---
121
+
122
+ ## 🎯 Final Deliverables
123
+ - **Engine core**: Lexer, parser, renderer.
124
+ - **Filter library**: All Django filters.
125
+ - **Tag handlers**: All Django tags.
126
+ - **Inheritance system**: Full block/extends support.
127
+ - **Express integration**: `app.engine('dtpl', ...)`.
128
+ - **Extensibility API**: Custom tags/filters/context processors.
129
+ - **Security**: Autoescape + safe strings.
130
+ - **Docs & tests**: Full coverage.
131
+
@@ -1,33 +1,33 @@
1
- /project-root
2
- /src
3
- lexer.js
4
- parser.js
5
- renderer.js
6
- filters.js
7
- security.js
8
- cache.js
9
- context.js
10
- tags/
11
- control.js
12
- inheritance.js
13
- util.js
14
- index.js
15
- /templates
16
- base.html
17
- home.html
18
- header.html
19
- /examples
20
- app.js
21
- /tests
22
- lexer.test.js
23
- parser.test.js
24
- renderer.test.js
25
- filters.test.js
26
- tags.test.js
27
- security.test.js
28
- README.md
29
- API_REFERENCE.md
30
- ROADMAP.md
31
- CONTRIBUTING.md
32
- CODE_OF_CONDUCT.md
33
- package.json
1
+ /project-root
2
+ /src
3
+ lexer.js
4
+ parser.js
5
+ renderer.js
6
+ filters.js
7
+ security.js
8
+ cache.js
9
+ context.js
10
+ tags/
11
+ control.js
12
+ inheritance.js
13
+ util.js
14
+ index.js
15
+ /templates
16
+ base.html
17
+ home.html
18
+ header.html
19
+ /examples
20
+ app.js
21
+ /tests
22
+ lexer.test.js
23
+ parser.test.js
24
+ renderer.test.js
25
+ filters.test.js
26
+ tags.test.js
27
+ security.test.js
28
+ README.md
29
+ API_REFERENCE.md
30
+ ROADMAP.md
31
+ CONTRIBUTING.md
32
+ CODE_OF_CONDUCT.md
33
+ package.json
package/dir/base.html ADDED
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+
8
+ {% block title %}
9
+ Document
10
+ {% endblock title %}
11
+
12
+ </title>
13
+ </head>
14
+ <body>
15
+ {% include "navbar.html" %}
16
+
17
+ {% block content %}
18
+
19
+ {% endblock content %}
20
+ {% include "footer.html" %}
21
+
22
+ </body>
23
+ </html>
package/dir/cmpnt.html ADDED
@@ -0,0 +1,11 @@
1
+ {% partialdef me %}
2
+ <h2>here is some content</h2>
3
+ {% endpartialdef %}
4
+ {% partialdef you %}
5
+ <h2>here is some content for you</h2>
6
+ {% endpartialdef %}
7
+ {% partialdef us inline %}
8
+ {% partial me%}
9
+ {% partial you%}
10
+ <h2>here is some content for us</h2>
11
+ {% endpartialdef %}
@@ -0,0 +1,3 @@
1
+ <footer>
2
+ <h3>some footer content with : {{siteName}}</h3>
3
+ </footer>
package/dir/home.html ADDED
@@ -0,0 +1,80 @@
1
+ {% extends 'base.html' %}
2
+
3
+ {% block title %}
4
+ {{ siteName|default:'Home page Here'|title }} | {{ block.super }}
5
+ {% endblock %}
6
+
7
+ {% block content %}
8
+ {% partialdef card inline %}
9
+ <div class="card">
10
+ <h3>{{ title|default:'No title' }}</h3>
11
+ <p>{{ description|default:'{% lorem 20 %}'|upper }}</p>
12
+ </div>
13
+ {% endpartialdef %}
14
+
15
+ {% partial card with title='Hello' description='World' %}
16
+
17
+ {% with a=5 %}
18
+ <marquee behavior="" direction="">
19
+ <span>some new stuff with with tag : {{ a|add:5 }}</span>
20
+ </marquee>
21
+ {% endwith %}
22
+
23
+ {{ name }}
24
+ {{ login.name }}
25
+ {{ login.email }}
26
+ <h1>Users table goes below</h1>
27
+ <table border="3">
28
+ <th>name</th>
29
+ <th>email</th>
30
+ <th>action</th>
31
+
32
+ {% for user in users %}
33
+ <tr>
34
+ <td>{{ user.name|title }}</td>
35
+ <td>{{ user.email }}</td>
36
+ <td>
37
+ <a href="">Delete user</a>
38
+ </td>
39
+ </tr>
40
+ {% endfor %}
41
+
42
+ </table>
43
+ <h1>Data list</h1>
44
+ <h2>data list of data</h2>
45
+ {% for obj in data %}
46
+ {% partialdef mike inline %}
47
+
48
+ <li>{{ obj.name }}</li>
49
+ <li>{{ forloop.counter }}</li>
50
+ <li> {{ obj.email }}</li>
51
+ {% endpartialdef %}
52
+ {% endfor %}
53
+
54
+ <h2>users list of data</h2>
55
+ <ul style="background-color: aqua;color: blueviolet; list-style-type:upper-roman;">
56
+
57
+ {% for obj in users %}
58
+ {% partial mike %}
59
+ {% endfor %}
60
+ </ul>
61
+
62
+ <h3>form with crsf</h3>
63
+
64
+ <form action="">
65
+ {% csrf_token %}
66
+ <input type="text" name="" id="" title="some text"/>
67
+ </form>
68
+ <h3>included content here</h3>
69
+ {% include 'cmpnt.html#me' %}
70
+
71
+ {{"2324"|filesizeformat}}
72
+ {{"224"|filesizeformat}}
73
+ {{ "123456789"|filesizeformat }}
74
+ {{ "1234567890"|filesizeformat }}
75
+ {{ "1234567890123"|filesizeformat }}
76
+ {{ "1234567890123456"|filesizeformat }}
77
+ {{ "1234567890123456789"|filesizeformat }}
78
+
79
+
80
+ {% endblock %}