philipw / yaml-template-generator
1.0.0
2019-04-01 19:07 UTC
Requires
- php: >7.1
- mustache/mustache: 2.12.*
- phpunit/phpunit: 7.5.*
- symfony/yaml: v4.2.*
- wp-cli/php-cli-tools: v0.11.*
This package is auto-updated.
Last update: 2024-10-29 05:59:51 UTC
README
YAML/JSON Template Engine
This turns YAML/JSON files into templates that allows the user to pipe in params.
Example YAML template:
foo: {{ foo }}
Example params file:
{
"foo" : "bar"
}
Output:
foo: bar
Universal Usage:
docker run -v ${workingdir}:/config \
-e "TEMPLATEENGINE_TEMPLATEFILE=example/template.yaml" \
-e "TEMPLATEENGINE_OUTPUTFILE=example/output.yaml" \
-e "TEMPLATEENGINE_PARAMS=example/params.json" \
-i philipw/yamltemplates
Bash Function: Put this bash function in your bash profile and you will be able to generate a templated yaml from anywhere on the CLI
function generateYaml() {
TEMPLATEENGINE_TEMPLATEFILE=$0
TEMPLATEENGINE_OUTPUTFILE=$1
TEMPLATEENGINE_PARAMS=$2
TEMPLATEENGINE_MIXIN=$3
workingdir=$(pwd)
docker run -v ${workingdir}:/config \
-e "TEMPLATEENGINE_TEMPLATEFILE=${TEMPLATEENGINE_TEMPLATEFILE}" \
-e "TEMPLATEENGINE_OUTPUTFILE=${TEMPLATEENGINE_OUTPUTFILE}" \
-e "TEMPLATEENGINE_PARAMS=${TEMPLATEENGINE_PARAMS}" \
-e "TEMPLATEENGINE_MIXIN=${TEMPLATEENGINE_MIXIN}" \
-i philipw/yamltemplates
}
See examples folder for a more complete example.
PHP Lib Usage
Install via composer: philipw/yaml-template-generator
use TemplateEngine\Config;
use TemplateEngine\Template;
$config = new Config(__DIR__.'/example/params.json');
$template = new Template(
$config,
__DIR__.'/example/example.yaml'
);
$template->writeRenderedOutput(__DIR__.'/output.yaml');