Ludtwig
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.
Status / Disclaimer
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.
Installation
Cargo (rust toolchain)
Run the following cargo command to install or update ludtwig:
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
Download the latest release binary for your operating system and put it in your PATH for easy access.
How to use Ludtwig?
After installation have a look at ludtwig --help for more information. It should be self explanatory.
Current features
- Fast / Highly concurrent execution
- Parsing of idiomatic Html / Twig / Vue.js templating files
- It will not parse non idiomatic Html where for example closing tags are forgotten (that otherwise could still work in the browser)
- Write the AST (abstract syntax tree) in a formatted way back into files
- Analyse the AST for common mistakes / suggestions
Current limitations
- Twig syntax is still not fully supported (Some hierarchical syntax is missing)
- There is no customization of the formatting or analyzing yet - you should be fine with the provided code style for now (or make the changes for yourself and recompile)
- You may encounter edge cases that result in parsing errors. Please create issues for them.
Basic Concepts
- Every file is parsed concurrently and independent from each other into an AST (abstract syntax tree)
- Parsing errors will result in not writing / analysing the file
- After the parsing was successful the following happens concurrently with the AST:
- the writer prints the AST in a formatted way back into a file
- the analyzer checks the AST for warnings and report them back to the user
- the analyzer can not influence the writer or the other way around
- After this is done for all files the output is presented to the user
Development setup
Make sure you have Rust installed on your system.
Clone this repository.
Run the project with parameters: 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
If you want to benchmark the performance of the release build you could use Hyperfine
and run it like so:
hyperfine -i 'ludtwig -o ./output ./my-template-folder'
License
Copyright (c) 2020 Malte Janz
ludtwig is distributed under the terms of the MIT License.
See the LICENSE file for details.
Dependencies / License notices*
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):
Special thanks goes to the authors of these dependencies.
*This list and the links may not be up to date and you should do your own research. Also deeper dependencies are not listed.