Package: jinsi
JSON/YAML homoiconic templating languagepython3-mpipinstalljinsiJinsi is a templating engine that uses YAML/JSON syntax, i.e. it is homoiconic. Never mess with indentation again.Most template engines are a poor choice for templating YAML/JSON, which is why Jinsi is embedded in the document as
native YAML/JSON syntax.Example:::let:foo:Hellobar:Worldvalue:<<foo>> <<bar>>Yields:value: Hello WorldSince Jinsi is basically independent from the syntax it works natively in JSON (or any other dialect which uses the
same data model) too:{
  "::let": {
    "foo": "Hello",
    "bar": "World"
  },
  "value": "<<foo>> <<bar>>"
}Jinsi was inspired by AWS Cloudformation templates, which are also homoiconic and feature builtin functions
(with more limited scope though). As I am using it to ease my DevOps woes it supports Cloudformation's
Bang-Syntax (!Sub) natively.Jinsi comes as a command line tool, but you can use it as a library for reading/writing YAML/JSON files too.Usage:jinsitemplate.yamlfoo=barqux=quuzThe above invocation will set$footoJaneand$quxtoJim:value: Hello <<$foo>>...would result invalue: Hello Jane.I am also using it to template Kubernetes YAML files. Bothkustomizeas well ashelm(which uses Go
Templates 😖) do not cut it for me. My developer life has been happier ever since. I could imagine using it with salt, too
(Jinja templates + YAML is just a PITA). Here's an example which configures
aningress resource using aws load balancer controller::let:$name:web-application$subdomain:dashboard$domain:example.com$services:-users-messages-backofficeapiVersion:extensions/v1beta1kind:Ingressmetadata:name:<<$subdomain>>annotations:kubernetes.io/ingress.class:albalb.ingress.kubernetes.io/group.name:<<$domain>>alb.ingress.kubernetes.io/scheme:internet-facingalb.ingress.kubernetes.io/listen-ports:::json_serialize:-HTTPS:443-HTTP:80alb.ingress.kubernetes.io/actions.ssl-redirect:::json_serialize:Type:redirectRedirectConfig:Protocol:HTTPSPort:'443'StatusCode:HTTP_301spec:rules:-host:<<$subdomain>>.<<$domain>>http:paths:::concat:--path:/*backend:serviceName:ssl-redirectservicePort:use-annotation-::each $services as $service:path:'/<<$service>>/*'backend:serviceName:<<$service>>-serviceservicePort:80--path:'/*'backend:serviceName:<<$name>>servicePort:80Usage via CLIpython3-mjinsi-# read from stdinpython3-mjinsi-j-# read from stdin, render as jsonpython3-mjinsifile1.yamlfile2.yamlExamplesCloudformation TemplateYAML input:::let:user:::object:-::titlecase:::get:$user.username-Type:AWS::IAM::UserProperties:UserName:::get:$user.usernameGroups:-AdministratorsLoginProfile:Password:::get:$user.password::else:defaultPasswordResetRequired:Yesusers:::merge:::each $ as $user:::call user:Resources:::call users:-username:jimpassword:one-username:jackpassword:two-username:johnnyRendered output:Resources:Jack:Properties:Groups:-AdministratorsLoginProfile:Password:twoPasswordResetRequired:trueUserName:jackType:AWS::IAM::UserJim:Properties:Groups:-AdministratorsLoginProfile:Password:onePasswordResetRequired:trueUserName:jimType:AWS::IAM::UserJohnny:Properties:Groups:-AdministratorsLoginProfile:Password:defaultPasswordResetRequired:trueUserName:johnnyType:AWS::IAM::UserSome fancy shit, too 🥸This is just an example to show how complex a template can be.
Also note: The fibonacci function is defined recursively. This
would blow up and values upto 50 could not be computed. Since
Jinsi is purely functional, functions are mappings and can be
cached. This is why the computation returns quickly (at all).python3-mjinsimax=50-YAML input:::let:fib:::when:::get:$n == 0 or $n == 1::then:::get:$n::else:::add:-::call fib:$n:::get:$n - 1-::call fib:$n:::get:$n - 2fibs:::range_exclusive:-0-::get:$max::else:10result:::each fibs as $n:::call:fibRendered output:result:-0-1-1-2-3-5-8-13-21-34-55-89-144-233-377-610-987-1597-2584-4181-6765-10946-17711-28657-46368-75025-121393-196418-317811-514229-832040-1346269-2178309-3524578-5702887-9227465-14930352-24157817-39088169-63245986-102334155-165580141-267914296-433494437-701408733-1134903170-1836311903-2971215073-4807526976-7778742049