Skip to content

razaibi/zaunic-lite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zaunic Lite

This is Golang based code generator. This is a light weight version that uses yml files and go.tmpl files to generate code.

Steps to Setup.

  1. Create your new project using the script.
./scripts/add_project.sh <name-of-your-project>
  1. Setup Data for Generation in _projects//data folder in yaml format.

Sample:

data:
  name: "Raz"
  options:
    - item: "somecontent"
      points:
        - name: "abcde"

Always start with data as the root element.

  1. Setup template for generation in _projects//templates folder. You can choose between the go templating engine (go.tmpl format) and liquid templating (.liquid format).

Sample Go Template:

<html>
	<head>
		<title>Sample HTML Generation</title>
	</head>
	<body>
    Name: {{.data.name}}
    Something Other Value: {{.somethingElse}}

	{{range  .data.options}}
		<li>Product Price : {{.item}}</li>
		{{range  .points}}
			<li>Product Price : {{.name}}</li>
		{{end}}
	{{end}}

	</body>
</html>

Sample Liquid Template:

Single Item: {{ data.name }}
Item List:
{% for item in data.items %}
    - {{ item.name }}
{% endfor %}
  1. Create Worksheet to execute/generate in _projects//worksheets folder (in .yml format). Worksheet drives the sequence of execution of the code generated.

Sample:

---
items:
  - name: "Generate Progam.cs."
    data: "sample-data.yml"
    template: "sample.go.tmpl"
    output: "sample.html"

The output value will be appended to the base path of the output folder.

Optional

If you intend to use templating engines apart from go templates, you can explicitly mention the engine as shown below:

---
items:
  - name: "Generate Progam.cs."
    data: "sample-data.yml"
    template: "sample.liquid"
    engine: "liquid"
    output: "sample-2.html"

Currently the following template types are supported:

  • Go Templates (.go.tmpl),
  • Liquid (.liquid)
  • Pongo (.pongo)
  • Mustache (.mustache)
  1. In main.go, setup the worksheet name you want to run.

Sample:

core.ProcessWorksheet("<your-project>","<your-worksheet>")
  1. Simply run using:
go run main.go

Other commands to get started.

Adding new template data.

Add new project with the below script.

./scripts/add_data.sh <name-of-your-project>
Adding a new template.

Add new project with the below script.

./scripts/add_template.sh <name-of-your-project>

Knowledge Hub

Secrets Management

  • Zaunic-Lite supports pulling secrets from cloud and embedding it into your generated code.

  • To do this, your environment variables are used.

  • Let us take an example to illustrate. If you have your AWS access key id and secret key stored as environment variables, you can use them to pull up your secrets like below.

secrets:
  - name: "some-awesome-secret"
    source: "aws"
    env: "dev"
    region: "us-east-1"

Core will start looking for environment variables.

  • Ensure these environment variables (in all caps) are set based on the cloud provider.

For AWS,

AWS_<your-environment-name>_ACCESS_KEY_ID=<your-access-key-id>
AWS_<your-environment-name>_SECRET_ACCESS_KEY=<your-secret-access-key>
  • Usage in Templates

In Liquid templates (sample secret name: appcred),

Sample Secret: {{ secrets.appcred }}

In Go Templates (sample secret name: appcred),

Sample Secret: {{index .secrets "appcred"}}

Useful templating plugins for VSCode.

Other Templating engine links.