@upstatement/twix-linux-x64 0.1.3 → 0.1.4
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 +136 -10
- package/bin/twix +0 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Twix
|
|
1
|
+
# Twix 🌱🍫
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An opinionated formatter for [Twig](https://twig.symfony.com/) templating engine. **Entirely coded with Claude.**
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,28 +8,154 @@ A formatter for Twig templates with HTML.
|
|
|
8
8
|
npm install --save-dev @upstatement/twix
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
Or download the binary directly from [GitHub Releases](https://github.com/Upstatement/twix/releases).
|
|
12
|
+
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
13
15
|
```bash
|
|
14
16
|
# Format a file (in-place)
|
|
15
|
-
|
|
17
|
+
twix path/to/file.twig
|
|
16
18
|
|
|
17
19
|
# Format multiple files
|
|
18
|
-
|
|
20
|
+
twix "src/**/*.twig"
|
|
19
21
|
|
|
20
22
|
# Check if files are formatted (exit 1 if not)
|
|
21
|
-
|
|
23
|
+
twix --check path/to/file.twig
|
|
22
24
|
|
|
23
25
|
# Format from stdin
|
|
24
|
-
cat file.twig |
|
|
26
|
+
cat file.twig | twix --stdin
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Configuration
|
|
30
|
+
|
|
31
|
+
Create a `.twixrc.json` or `twix.config.json` file in your project root:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"indentSize": 2,
|
|
36
|
+
"indentStyle": "space",
|
|
37
|
+
"printWidth": 80,
|
|
38
|
+
"customTags": {
|
|
39
|
+
"block": ["if"],
|
|
40
|
+
"inline": ["set"],
|
|
41
|
+
"intermediate": ["else"]
|
|
42
|
+
}
|
|
43
|
+
}
|
|
25
44
|
```
|
|
26
45
|
|
|
46
|
+
### Options
|
|
47
|
+
|
|
48
|
+
| Option | Type | Default | Description |
|
|
49
|
+
| ------------------------- | -------- | --------- | ------------------------------------------------------------------------- |
|
|
50
|
+
| `indentSize` | number | `2` | Number of spaces or tabs per indentation level |
|
|
51
|
+
| `indentStyle` | string | `"space"` | Use `"space"` or `"tab"` for indentation |
|
|
52
|
+
| `printWidth` | number | `80` | Maximum line width before wrapping attributes |
|
|
53
|
+
| `customTags.block` | string[] | `[]` | Custom Twig block tags (tags with bodies, e.g., `{% if %}...{% endif %}`) |
|
|
54
|
+
| `customTags.inline` | string[] | `[]` | Custom Twig inline tags (self-closing, e.g., `{% set = ... %}`) |
|
|
55
|
+
| `customTags.intermediate` | string[] | `[]` | Custom intermediate tags (like `{% else %}` or `{% case %}`) |
|
|
56
|
+
|
|
57
|
+
### Built-in Tag Support
|
|
58
|
+
|
|
59
|
+
**Block tags** (have a body and `{% end* %}` tag):
|
|
60
|
+
|
|
61
|
+
- Standard Twig: `if`, `for`, `block`, `set`, `apply`, `autoescape`, `embed`, `filter`, `macro`, `sandbox`, `verbatim`, `with`
|
|
62
|
+
- Craft CMS: `switch`, `cache`, `js`, `css`, `nav`, `paginate`, `tag`
|
|
63
|
+
|
|
64
|
+
**Inline tags** (self-closing):
|
|
65
|
+
|
|
66
|
+
- Standard Twig: `extends`, `include`, `use`, `import`, `from`, `do`, `flush`, `deprecated`
|
|
67
|
+
- Craft CMS: `exit`, `header`, `redirect`, `requireLogin`, `requireAdmin`, `requireGuest`, `requirePermission`
|
|
68
|
+
|
|
69
|
+
**Intermediate tags** (appear within blocks):
|
|
70
|
+
|
|
71
|
+
- `else`, `elseif`, `case`, `default`
|
|
72
|
+
|
|
27
73
|
## Features
|
|
28
74
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
75
|
+
### HTML Formatting
|
|
76
|
+
|
|
77
|
+
- Proper indentation of nested elements
|
|
78
|
+
- Block elements (`div`, `p`, `section`, etc.) get their own lines
|
|
79
|
+
- Inline elements (`span`, `a`, `strong`, etc.) stay on the same line when possible
|
|
80
|
+
- Void elements (`meta`, `link`, `input`, etc.) are self-closing
|
|
81
|
+
- Multi-line attribute formatting when attributes exceed `printWidth`
|
|
82
|
+
|
|
83
|
+
### Twig Formatting
|
|
84
|
+
|
|
85
|
+
- Block tags are indented with their content
|
|
86
|
+
- Expressions (`{{ }}`) preserve their content
|
|
87
|
+
- Whitespace control modifiers (`{%- -%}`, `{{- -}}`) are preserved
|
|
88
|
+
- Comments (`{# #}`) are preserved
|
|
89
|
+
|
|
90
|
+
### Twig Inside HTML Attributes
|
|
91
|
+
|
|
92
|
+
Twix properly handles Twig embedded in HTML attribute values:
|
|
93
|
+
|
|
94
|
+
```twig
|
|
95
|
+
<!-- Expressions in attributes -->
|
|
96
|
+
<div class="container {{ dynamicClass }}">
|
|
97
|
+
|
|
98
|
+
<!-- Conditional classes -->
|
|
99
|
+
<div class="item {% if active %}is-active{% endif %}">
|
|
100
|
+
|
|
101
|
+
<!-- Conditional attributes -->
|
|
102
|
+
<button {% if disabled %}disabled{% endif %}>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Ignore Blocks
|
|
106
|
+
|
|
107
|
+
Skip formatting for specific sections using ignore directives:
|
|
108
|
+
|
|
109
|
+
```twig
|
|
110
|
+
{# twix:ignore-start #}
|
|
111
|
+
<div class="preserve" data-value="exactly as-is" >
|
|
112
|
+
This content will not be formatted
|
|
113
|
+
</div>
|
|
114
|
+
{# twix:ignore-end #}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Blank Line Handling
|
|
118
|
+
|
|
119
|
+
- Multiple consecutive blank lines are collapsed to a single blank line
|
|
120
|
+
- Blank lines immediately after opening block tags (`{% if %}`, `{% for %}`, etc.) are removed
|
|
121
|
+
- Intentional blank lines between statements are preserved
|
|
122
|
+
|
|
123
|
+
## Limitations & Known Issues
|
|
124
|
+
|
|
125
|
+
### Not Supported
|
|
126
|
+
|
|
127
|
+
- **Twig expressions are not parsed** - Content inside `{{ }}` and `{% %}` is preserved as-is, not reformatted
|
|
128
|
+
- **No HTML entity handling** - Entities like ` ` are passed through unchanged
|
|
129
|
+
- **No CSS/JS formatting** - Content inside `<style>` and `<script>` tags is not formatted
|
|
130
|
+
- **Windows line endings** - Output uses Unix line endings (`\n`)
|
|
131
|
+
|
|
132
|
+
## Editor Integration
|
|
133
|
+
|
|
134
|
+
### Pre-commit Hook
|
|
135
|
+
|
|
136
|
+
Using [husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged):
|
|
137
|
+
|
|
138
|
+
```json
|
|
139
|
+
// package.json
|
|
140
|
+
{
|
|
141
|
+
"lint-staged": {
|
|
142
|
+
"*.twig": "twix"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Development
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Build
|
|
151
|
+
go build
|
|
152
|
+
|
|
153
|
+
# Run tests
|
|
154
|
+
go test ./...
|
|
155
|
+
|
|
156
|
+
# Build for all platforms
|
|
157
|
+
./scripts/build.sh 0.1.0
|
|
158
|
+
```
|
|
33
159
|
|
|
34
160
|
## License
|
|
35
161
|
|
package/bin/twix
CHANGED
|
Binary file
|
package/package.json
CHANGED