miki-template 1.2.0 → 1.3.3

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 (60) hide show
  1. package/.github/release-notes/v1.3.1.md +55 -0
  2. package/CHANGELOG.md +72 -0
  3. package/README.md +43 -26
  4. package/assets/banner.png +0 -0
  5. package/benchmarks/stress.mjs +647 -0
  6. package/dir/base.html +23 -0
  7. package/dir/cmpnt.html +11 -0
  8. package/dir/footer.html +3 -0
  9. package/dir/home.html +80 -0
  10. package/dir/navbar.html +9 -0
  11. package/docs/api.md +20 -3
  12. package/docs/filters.md +301 -133
  13. package/docs/partialdef.md +30 -1
  14. package/docs/tags.md +63 -0
  15. package/docs/usage.md +50 -3
  16. package/eslint.config.mjs +9 -1
  17. package/ex.mjs +33 -0
  18. package/miki-template-extension/.github/workflows/ci.yml +116 -0
  19. package/miki-template-extension/.vscodeignore +7 -0
  20. package/miki-template-extension/CHANGELOG.md +99 -0
  21. package/miki-template-extension/README.md +244 -53
  22. package/miki-template-extension/extension.js +1013 -0
  23. package/miki-template-extension/icon.png +0 -0
  24. package/miki-template-extension/miki-template-1.7.1.vsix +0 -0
  25. package/miki-template-extension/package.json +244 -10
  26. package/miki-template-extension/snippets/miki-template.json +612 -72
  27. package/miki-template-extension/syntaxes/language-configuration.json +101 -13
  28. package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +270 -61
  29. package/miki-template-extension/tests/grammar-tests.json +162 -0
  30. package/miki-template-extension/tests/run-grammar-tests.js +82 -0
  31. package/package.json +7 -4
  32. package/scripts/build-vsix.js +129 -0
  33. package/scripts/build-vsix.ps1 +15 -0
  34. package/src/cache.js +41 -2
  35. package/src/context.js +9 -5
  36. package/src/context_processors.js +9 -2
  37. package/src/esm.mjs +12 -0
  38. package/src/filters.js +472 -24
  39. package/src/index.js +571 -85
  40. package/src/lexer.js +76 -54
  41. package/src/libraries.js +134 -3
  42. package/src/parser.js +22 -2
  43. package/src/security.js +4 -2
  44. package/src/tags/control.js +150 -21
  45. package/src/tags/extra.js +154 -0
  46. package/src/tags/i18n.js +49 -23
  47. package/src/tags/inheritance.js +142 -23
  48. package/src/tags/util.js +102 -24
  49. package/tests/esm.test.mjs +37 -2
  50. package/tests/filters.test.js +155 -0
  51. package/tests/integration/README.md +32 -0
  52. package/tests/integration/features.test.cjs +1681 -0
  53. package/tests/integration/features.test.mjs +1697 -0
  54. package/tests/integration/templates/base.miki +6 -0
  55. package/tests/integration/templates/child.miki +6 -0
  56. package/tests/integration/templates/index.html +17 -0
  57. package/tests/parser.test.js +5 -3
  58. package/tests/partialdef.test.js +40 -1
  59. package/tests/tags.test.js +30 -0
  60. package/miki-template-1.2.0.vsix +0 -0
@@ -1,82 +1,273 @@
1
1
  # miki-template VS Code Extension
2
2
 
3
- Syntax highlighting, bracket matching, and snippets for [miki-template](https://github.com/alainmiki/miki-template) — a Django-style template engine for Node.js and Express.
3
+ [![Buy Me A Coffee](https://img.buymeacoffee.com/button-api/?text=Buy%20me%20a%20coffee&emoji=%E2%98%95&slug=alainmiki&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff)](https://www.buymeacoffee.com/alainmiki)
4
+
5
+ The **ultimate** VS Code extension for **miki-template** and **Django** templates. Packed with features to supercharge your template development.
6
+
7
+ ## Why miki-template?
8
+
9
+ - 100% Django compatible
10
+ - All Django template tags & filters
11
+ - miki-template extensions (partialdef, cache, addtoblock)
12
+ - Works with `.django`, `.dj`, `.miki`, `.miki-template` files
13
+
14
+ ---
4
15
 
5
16
  ## Features
6
17
 
7
- - Syntax highlighting for `.miki` and `.miki-template` files
8
- - Snippets for all built-in tags and common patterns
9
- - Bracket auto-closing for `{% %}`, `{{ }}`, `{# #}`
10
- - Comment toggling with `{# #}`
18
+ ### 🔥 Intelligent Completions
19
+ - **Tags**: All 50+ Django/miki-template tags
20
+ - **Filters**: All 70+ filters with argument hints
21
+ - **forloop.* variables**: Auto-complete when inside for loops
22
+ - **Custom tags/filters**: Auto-detected from project config
23
+ - **Common variables**: user, request, form, items, etc.
24
+ - **Path completions**: Auto-suggest template files for `{% include %}` and `{% extends %}`
11
25
 
12
- ## Supported Tags
26
+ ### 📖 Hover Documentation
27
+ Hover over any tag or filter to see:
28
+ - Full description
29
+ - Syntax example
30
+ - Argument hints for filters
31
+ - `{{ block.super }}` shows parent block content explanation
13
32
 
14
- `if / elif / else / endif`, `for / empty / endfor`, `with / endwith`, `cycle`, `comment / endcomment`, `verbatim / endverbatim`, `include`, `extends`, `block / endblock`, `partialdef / endpartialdef`, `partial`, `load`, `templatetag`, `trans`, `blocktrans`, `language / endlanguage`, `widthratio`, `debug`, `autoescape / endautoescape`, `filter / endfilter`, `plural`, `cache / endcache`, `markdown / endmarkdown`, `regroup`, `firstof`, `csrf_token`, `csp_nonce_attr`, `static`, `url`
33
+ ### ⚡ Real-time Validation
34
+ - Unclosed tag detection
35
+ - Mismatched opening/closing tags
36
+ - `{% extends %}` placement validation
37
+ - Performance optimized with debouncing
15
38
 
16
- ## Supported Filters
39
+ ### 🎨 Color Decorations
40
+ Automatically highlights:
41
+ - `#ff0000`, `#fff`, `#ffffffaa`
42
+ - `rgb()`, `rgba()`
43
+ - `hsl()`, `hsla()`
17
44
 
18
- `upper`, `lower`, `title`, `capfirst`, `slugify`, `wordcount`, `striptags`, `linebreaks`, `linebreaksbr`, `truncatewords`, `truncatechars`, `safe`, `escape`, `escapejs`, `length`, `length_is`, `join`, `slice`, `dictsort`, `dictsortreversed`, `first`, `last`, `default`, `default_if_none`, `firstof`, `date`, `time`, `strftime`, `timesince`, `timeuntil`, `add`, `divisibleby`, `floatformat`, `yesno`, `pluralize`, `filesizeformat`, `urlencode`, `escapeuri`, `stringformat`, `cut`, `addslashes`, `removetags`, `trans`, `regroup`, `intcomma`, `intword`, `apnumber`, `ordinal`, `naturalday`, `lorem`
45
+ ### 🔧 Code Actions (Quick Fixes)
46
+ - Add missing `{% endif %}`
47
+ - Add missing `{% endfor %}`
48
+ - Wrap selection in `{% block %}`
49
+ - Add `{# prettier-ignore #}`
19
50
 
20
- ## Installation
51
+ ### 💡 Inlay Hints
52
+ Show inline parameter hints for filter arguments.
21
53
 
22
- ### From VS Code Marketplace
54
+ ### 🔗 Bracket Matching Highlights
55
+ Highlight matching `{% if %}` / `{% endif %}` pairs.
23
56
 
24
- ```bash
25
- code --install-extension miki-template
26
- ```
57
+ ### 🚀 Go-to-Definition
58
+ Jump to:
59
+ - `{% include "file" %}`
60
+ - `{% extends "file" %}`
61
+ - `{% block name %}`
62
+ - `{% partialdef name %}`
63
+
64
+ ### 🔍 Project-wide Find References
65
+ Find all references to:
66
+ - Block definitions across workspace
67
+ - Included templates
68
+ - Extended templates
69
+
70
+ ### 📋 Smart Tag Selection
71
+ Double-click to select entire `{% block %}` content.
72
+
73
+ ### 🎯 Quick Outline Navigation
74
+ Jump between blocks with keyboard shortcuts.
75
+
76
+ ### 📝 Template Preview
77
+ Preview template syntax in a new tab.
78
+
79
+ ### ✏️ Rename Blocks (F2)
80
+ Rename any `{% block name %}` and automatically update all `{{ block.name }}` references across your entire workspace. Just place cursor on a block name and press F2.
81
+
82
+ ### 🎨 Semantic Highlighting
83
+ Enhanced syntax highlighting using VS Code's Semantic Token API for better theme support and more accurate token classification.
84
+
85
+ ### 🌐 HTML/CSS/JS Support
86
+ Full embedded language support for:
87
+ - **HTML**: Proper tag and attribute highlighting
88
+ - **CSS**: Syntax highlighting in `<style>` tags
89
+ - **JavaScript**: Syntax highlighting in `<script>` tags
90
+ - **Emmet**: Full Emmet abbreviation support for HTML and JavaScript
91
+ - **Auto-closing**: HTML tags, brackets, and quotes
92
+ - **Bracket matching**: HTML tags, parentheses, brackets
93
+
94
+ ### 📋 Smart Paste
95
+ Paste HTML content and the extension will automatically append `|safe` filter to prevent escaping issues.
96
+
97
+ ### 🔧 Code Actions
98
+ Quick fixes for common issues.
27
99
 
28
- Or search for **miki-template** in the Extensions view (`Ctrl+Shift+X`).
100
+ ---
29
101
 
30
- ### Manual installation
102
+ ## Quick Commands
31
103
 
32
- 1. Copy `syntaxes/` and `snippets/` into your project or user settings
33
- 2. Associate `.miki` files with `miki-template`
104
+ | Command | Description | Shortcut |
105
+ |---------|-------------|----------|
106
+ | `insertFilter` | Wrap with filter | `Ctrl+Shift+F` |
107
+ | `wrapInBlock` | Wrap in block | - |
108
+ | `wrapInFor` | Wrap in for loop | - |
109
+ | `wrapInIf` | Wrap in if condition | - |
110
+ | `addPrettierIgnore` | Add prettier ignore | - |
111
+ | `goToNextBlock` | Next block | `Ctrl+Shift+.` |
112
+ | `goToPrevBlock` | Previous block | `Ctrl+Shift+,` |
113
+ | `previewTemplate` | Preview template | - |
114
+ | `showOutline` | Show outline | - |
115
+ | `findBlockReferences` | Find block refs | - |
116
+ | `validateAll` | Validate all | - |
117
+
118
+ > **Tip:** Press `F2` on any block name to rename it across the workspace!
119
+
120
+ ---
121
+
122
+ ## Settings
123
+
124
+ | Setting | Default | Description |
125
+ |---------|---------|-------------|
126
+ | `enableValidation` | `true` | Enable validation |
127
+ | `enableCompletions` | `true` | Enable completions |
128
+ | `enableHover` | `true` | Enable hover docs |
129
+ | `enableColorDecorations` | `true` | Highlight colors |
130
+ | `enableCodeActions` | `true` | Enable quick fixes |
131
+ | `enableInlayHints` | `true` | Show inlay hints |
132
+ | `enableBracketHighlight` | `true` | Highlight brackets |
133
+ | `enableSmartPaste` | `true` | Smart paste handling |
134
+ | `formatOnSave` | `false` | Format on save |
135
+
136
+ ---
34
137
 
35
138
  ## File Associations
36
139
 
37
- Add to your workspace or user `settings.json`:
140
+ | Extension | Language |
141
+ |-----------|----------|
142
+ | `.miki` | miki-template |
143
+ | `.miki-template` | miki-template |
144
+ | `.django` | Django HTML |
145
+ | `.dj` | Django HTML |
146
+
147
+ ---
148
+
149
+ ## Format on Save
38
150
 
39
151
  ```json
40
152
  {
41
- "files.associations": {
42
- "*.miki": "miki-template",
43
- "*.miki-template": "miki-template"
153
+ "[django-html]": {
154
+ "editor.formatOnSave": true,
155
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
44
156
  }
45
157
  }
46
158
  ```
47
159
 
48
- ## Snippets
49
-
50
- Type any of the following prefixes and press `Tab`:
51
-
52
- | Prefix | Output |
53
- |--------|--------|
54
- | `if` | `{% if %}...{% endif %}` |
55
- | `ifelse` | `{% if %}...{% else %}...{% endif %}` |
56
- | `for` | `{% for %}` with `empty` |
57
- | `block` | `{% block %}` |
58
- | `extends` | `{% extends %}` |
59
- | `include` | `{% include %}` |
60
- | `with` | `{% with %}` |
61
- | `cycle` | `{% cycle %}` |
62
- | `trans` | `{% trans %}` |
63
- | `blocktrans` | `{% blocktrans %}` |
64
- | `language` | `{% language %}` |
65
- | `partialdef` | `{% partialdef %}` |
66
- | `partial` | `{% partial %}` |
67
- | `csrf` | `{% csrf_token %}` |
68
- | `csp` | `{% csp_nonce_attr %}` |
69
- | `static` | `{% static %}` |
70
- | `url` | `{% url %}` |
71
- | `widthratio` | `{% widthratio %}` |
72
- | `debug` | `{% debug %}` |
73
- | `load` | `{% load %}` |
74
- | `comment` | `{# #}` block comment |
75
- | `verbatim` | `{% verbatim %}` |
76
- | `regroup` | `{% for %}` with `regroup` filter |
77
- | `firstof` | `{% firstof %}` |
78
- | `filter` | `{% filter %}` block |
160
+ ---
161
+
162
+ ## Custom Tags/Filters Detection
163
+
164
+ The extension auto-detects custom tags and filters from:
165
+ - `miki-template.config.js`
166
+ - `miki-template.config.json`
167
+ - `.mikirc`
168
+ - `package.json`
169
+
170
+ ```javascript
171
+ // miki-template.config.js
172
+ module.exports = {
173
+ filters: ['myFilter', 'customFilter'],
174
+ tags: ['myTag', 'customTag']
175
+ };
176
+ ```
177
+
178
+ ---
179
+
180
+ ## Path Completions
181
+
182
+ When typing `{% include %}` or `{% extends %}`, the extension automatically suggests template files from your workspace:
183
+
184
+ ```html
185
+ {% include "partials/" ← Shows all template files
186
+ {% extends "base" ← Shows matching templates
187
+ ```
188
+
189
+ Files are searched recursively throughout your workspace and filtered as you type.
190
+
191
+ ---
192
+
193
+ ## Examples
194
+
195
+ ### Basic Template
196
+ ```html
197
+ {% extends "base.html" %}
198
+
199
+ {% block content %}
200
+ <h1>{{ title|default:"Welcome" }}</h1>
201
+
202
+ {% if user.is_authenticated %}
203
+ <p>Hello, {{ user.name }}!</p>
204
+ {% else %}
205
+ <p>Please log in.</p>
206
+ {% endif %}
207
+
208
+ {% for item in items %}
209
+ <li>{{ forloop.counter }}. {{ item }}</li>
210
+ {% empty %}
211
+ <li>No items found.</li>
212
+ {% endfor %}
213
+ {% endblock %}
214
+ ```
215
+
216
+ ### Rename Blocks
217
+ Place cursor on any `{% block name %}` and press `F2`:
218
+
219
+ ```html
220
+ <!-- Before rename: block title → block heading -->
221
+ {% block title %}Welcome{% endblock %}
222
+ {{ block.title }}
223
+
224
+ <!-- After pressing F2 and entering "heading": -->
225
+ {% block heading %}Welcome{% endblock %}
226
+ {{ block.heading }}
227
+ ```
228
+
229
+ All references across the workspace are updated automatically.
230
+
231
+ ### With Partial
232
+ ```html
233
+ {% partialdef card inline %}
234
+ <div class="card">
235
+ <h3>{{ title }}</h3>
236
+ <p>{{ description }}</p>
237
+ </div>
238
+ {% endpartialdef %}
239
+
240
+ {% partial card with title="Hello" %}
241
+ ```
242
+
243
+ ---
244
+
245
+ ## Development
246
+
247
+ ```bash
248
+ # Install dependencies
249
+ npm install
250
+
251
+ # Run tests
252
+ npm test
253
+
254
+ # Package
255
+ npm run package
256
+
257
+ # Watch & install
258
+ npm run watch
259
+ ```
260
+
261
+ ---
79
262
 
80
263
  ## License
81
264
 
82
265
  MIT
266
+
267
+ ---
268
+
269
+ ## Support
270
+
271
+ If this extension helps you, consider [buying me a coffee](https://www.buymeacoffee.com/alainmiki)!
272
+
273
+ [![Buy Me A Coffee](https://img.buymeacoffee.com/button-api/?text=Buy%20me%20a%20coffee&emoji=%E2%98%95&slug=alainmiki&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff)](https://www.buymeacoffee.com/alainmiki)