A CLI tool for developers that tries to speedup the development workflow while working with templating (.twig
) files.
It focuses mainly on formatting the files with a uniform code style and detecting mistakes.
It is only a "formatter" that can be run locally or in the pipeline, it will not report anything to your IDE.
Ludtwig is currently in an early development state. Please use the tool with caution and validate the changes that is has made (backup your files before running this). Feel free to create new issues and help to steer this project in the right direction.
```twig
{% block mycomponent %}
This is a paragraph. And the browser sees only whitespace and doesn't care about many spaces.
Linebreaks are also no problem. they are kept. {% endblock %}
```
*This is not what a normal template should look like, but it demonstrates that ludtwig can work with
any combination of Html / Twig / Vue.js (or other solutions that only need the {{...}} syntax and bring custom tags / attributes).
For example you can use the powerful block feature of twig.js, but also every feature from vue.js and ludtwig can still work with the templates. ```twig
{% block my_component %}
{% endblock %}
``` ```text
Parsing files... File: "./fixtures/showcase.html.twig"
[Error] Parsing goes wrong in line 7 and column 38 :
Files scanned: 1, Errors: 1, Warnings: 0
Happy bug fixing ;)
```
*The example template was changed with missing quotes ```text
Parsing files... File: "./fixtures/showcase.html.twig"
[Warning] Duplicate twig block name found: 'my_component' Files scanned: 1, Errors: 0, Warnings: 1
Happy bug fixing ;)
```
*The example template was extended with another twig block with the name 'my_component'. Run the following cargo command to install or update ludtwig:
Download the latest release binary for your operating system and put it in your PATH for easy access. After installation have a look at Make sure you have Rust installed on your system. Run the project with parameters: If you want to benchmark the performance of the release build you could use Hyperfine
and run it like so: Copyright (c) 2020 Malte Janz If you build this project locally or use the distributed binary keep also the following licenses in mind:
- ludtwig-parser - MIT
- async-std - MIT / Apache 2.0
- clap - MIT / Apache 2.0
- ansi_term - MIT
- walkdir - MIT / UNLICENSE
- async-trait - MIT / Apache 2.0 For testing purposes this repository also includes code from the following sources (not included in distributed binary):
- Shopware - MIT
- SwagMigrationAssistant - MIT Special thanks goes to the authors of these dependencies. {{ header }}
{% endblock %}
{% block mycomponent_body %}
The browser also does not care about empty lines.
So why not format text like this how the browser displays it (but keep single line breaks for visibility)?
</p>
</my-component-body>
{% endblock %}
</div>
After running ludtwig
{% block my_component_header %}
<h2 :style="style"
class="whitespace-sensitive">{{ header }}</h2>
{% endblock %}
{% block my_component_body %}
<my-component-body
class="component-body"
v-model="body"
@change="if a > 0 { onChange(); }"
{% if isDisabled %}
disabled
{% elseif hasCustomAttribute %}
{{ customAttrName }}="{{ customAttrValue }}"
{% else %}
{{ completeCustomAttr }}
{% endif %}>
<charlong9
some="custom"
attributes="that"
are="at least 3 or make the line long enough">
(whitespaces around this)
</charlong9>
<span>(but here are no whitespaces)</span>
<p>
This is a paragraph.
And the browser sees only whitespace and doesn't care about many spaces.
Linebreaks are also no problem. they are kept.
The browser also does not care about empty lines.
So why not format text like this how the browser displays it (but keep single line breaks for visibility)?
</p>
</my-component-body>
{% endblock %}
</div>
It also catches errors / problems during parsing*
And if the parsing succeeds it checks the AST (abstract syntax tree) for mistakes / best practices*
Current features
Current limitations
Installation
Cargo (rust toolchain)
cargo install ludtwig
You can install cargo here: https://www.rust-lang.org/learn/get-started
If you don't want to install the rust toolchain / cargo you can still use the manual installation below.Manual
How to use Ludtwig?
ludtwig --help
for more information. It should be self explanatory.Basic Concepts
Development setup
Clone this repository.cargo run -- filaA.twig
Build the project for production with: cargo build --release
(the produced binary will be here: target/release/ludtwig
)
Run tests with: cargo test
hyperfine -i 'ludtwig -o ./output ./my-template-folder'
License
ludtwig
is distributed under the terms of the MIT License.
See the LICENSE file for details.Dependencies / License notices*
*This list and the links may not be up to date and you should do your own research. Also deeper dependencies are not listed.