Skip to content

POSIX-compliant logic-less template engine.

License

Notifications You must be signed in to change notification settings

macie/smallstache.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smallstache.sh

Quality check status License

A commandline, POSIX-compliant logic-less template engine similar to Mustache/Handlebars.

Usage

smallstache takes template from commandline argument and key-value data from stdin:

$ echo 'Hello {{ something }}!' >template
$ echo 'something=World' | smallstache template
Hello World!

It can use any source of standard unix key-value data format:

$ 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:

    wget https://github.com/macie/smallstache.sh/releases/latest/download/smallstache
  2. (OPTIONAL) Verify downloading:

    wget https://github.com/macie/smallstache.sh/releases/latest/download/smallstache.sha256sum
    sha256sum -c smallstache.sha256sum
  3. Set execute permission:

    chmod +x smallstache
  4. Move to directory from PATH environment variable:

    mv smallstache /usr/local/bin/

Development version

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). 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:

# 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.

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 (explanation in simple words)