https://github.com/macie/smallstache.sh
POSIX-compliant logic-less template engine.
https://github.com/macie/smallstache.sh
mustache posix posix-compliant shell template-engine
Last synced: 5 months ago
JSON representation
POSIX-compliant logic-less template engine.
- Host: GitHub
- URL: https://github.com/macie/smallstache.sh
- Owner: macie
- License: mit
- Created: 2023-01-30T17:57:55.000Z (over 3 years ago)
- Default Branch: dev
- Last Pushed: 2024-09-15T08:15:57.000Z (almost 2 years ago)
- Last Synced: 2024-09-16T10:27:39.913Z (almost 2 years ago)
- Topics: mustache, posix, posix-compliant, shell, template-engine
- Language: Shell
- Homepage:
- Size: 45.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Smallstache.sh
[](https://github.com/macie/smallstache.sh/actions/workflows/check.yml)
[](https://tldrlegal.com/license/mit-license)
A commandline, POSIX-compliant [logic-less template engine](https://en.wikipedia.org/wiki/Web_template_system)
similar to [Mustache](https://mustache.github.io/)/[Handlebars](http://handlebarsjs.com/).
## Usage
`smallstache` takes template from commandline argument and key-value data from stdin:
```bash
$ echo 'Hello {{ something }}!' >template
$ echo 'something=World' | smallstache template
Hello World!
```
It can use any source of standard unix key-value data format:
```bash
$ echo 'Your PATH variable: {{ PATH }}' >template
$ set | smallstache template
Your PATH variable: /bin:/usr/bin
```
## Installation
>The instruction is for Linux. On different OSes, you may need to use different
>commands
1. Download [latest stable release from GitHub](https://github.com/macie/smallstache.sh/releases/latest):
```bash
wget https://github.com/macie/smallstache.sh/releases/latest/download/smallstache
```
2. (OPTIONAL) Verify downloading:
```bash
wget https://github.com/macie/smallstache.sh/releases/latest/download/smallstache.sha256sum
sha256sum -c smallstache.sha256sum
```
3. Set execute permission:
```bash
chmod +x smallstache
```
4. Move to directory from `PATH` environment variable:
```bash
mv smallstache /usr/local/bin/
```
### Development version
```bash
git clone git@github.com:macie/smallstache.sh.git
cd smallstache.sh
make install
```
## Development
Use `make` (GNU or BSD):
- `make` - run checks
- `make test` - run test
- `make check` - perform static code analysis
- `make install` - install in `/usr/local/bin`
- `make dist` - prepare for distributing
- `make clean` - remove distributed artifacts
- `make cli-release` - tag latest commit as a new release
- `make info` - print system info (useful for debugging).
### Versioning
`smallstache` is versioned according to the scheme `YY.0M.MICRO` ([calendar versioning](https://calver.org/)). Releases are tagged in Git.
## Known bugs
### Argument list too long
`smallstache` handles limited length of key-value pairs. When you exceed
the limit, you will see an error such as:
```
smallstache[41]: sed: Argument list too long
```
As a workaround, fill template in parts with following steps:
```bash
# save key-value pairs to a few parts
set >data
split -l 2000 -a 5 data data_part_
# fill the template
cp template result
for part in data_part_*; do
smallstache result <"$part" >partially_filled
cp partially_filled result
done
# see the result
cat result
```
For more information, see [ARG_MAX, maximum length of arguments for a new process](https://www.in-ulm.de/~mascheck/various/argmax/).
### unknown option to `s'
`smallstache` uses special character to separate key-value pairs in substitution
command (default: `|`). When value contains this character, `smallstache` will
throw an error similar to:
```
sed: -e expression #1, char 24: unknown option to `s'
```
In such case, you should use another character as a delimiter, for example:
`smallstache -d _`.
## License
[MIT](./LICENSE) ([explanation in simple words](https://tldrlegal.com/license/mit-license))