saladplate
v0.2.1
Published
Very simple templating.
Downloads
212
Readme
Saladplate
Simple templating; it's smaller than usual.
Saladplate is a very simple templating tool, with 3 core features:
- Replace
${{ VAR }}with the contents of the environment variableVAR. - Replace
$<< filename >>with the contents of the filefilename. - Replace
$(( command ))with the output of the commandcommand.
Each of these replacements supports "injection" mode, useful for layouts/wrappers:
- Replace
$^<< filename >>and everything after it with the contents offilename, but replacing^^in that content with the "everything after". - Replace
$^(( command ))similarly, but with the output ofcommand. - Replace
$^{{ VAR }}similarly, but with the value of the environment variableVAR.
If you need more functionality than that, this is not the templating tool for you.
Installation
$ npm install -g saladplate
$ saladplate --version
saladplate: version 0.2.1Usage
The easiest way to use Saladplate with via the saladplate command line tool:
$ saladplate --help
Usage: saladplate [options] <file>...
Options:
--debug enable debug mode
-v, --version show version information
-h, --help show this help message
-d, --directory output directory
-s, --suffix output suffix; only applies when using --directory
-o, --output output file; overrides --directory and --suffixSaladplate generally operates in 2 modes. If you pass --directory, then
each file you pass will be templated independently, and the output written
into the given directory. Use --suffix to change the extension of the output
file -- for instance, if you template the files some.template and another.txt
with --directory=out and --suffix=.html you will end up with a file out/some.html
and out/another.html:
$ saladplate --directory=out --suffix=.html *.templateIf instead you pass --output, then each file will be templated, with the
results concatenated into the single given output file.
$ saladplate --output=index.html *.templateYou can also use the exported template function to template a string:
import { template } from "saladplate";
console.info(await template("The current PATH is: ${{ PATH }}"));Examples
Assuming that GREETING="Hello" then:
${{ GREETING }}, world!Does what you'd expect. Supposing that quote.html is:
<blockquote>
^^
</blockquote>Then:
$^<< quote.html >>
${{ GREETING }}, world!Yields:
<blockquote>
Hello, world!
</blockquote>Development
When developing locally, you can test your changes using the script saladplate,
which uses bun. Note the use of run below, as well as the use of -- to
separate arguments to bun run from arguments to saladplate:
$ bun run saladplate -- --version
saladplate: version 0.2.1Building and publishing
To build the distributable JS:
$ bun run buildThis will build to dist/. To publish to NPM:
$ npm publishTesting
Tests are located in tests/ and consist of input templates tests/*.test and
corresponding expected outputs tests/*.expected. To run tests:
$ bun run test