Giter VIP home page Giter VIP logo

zaunic-lite's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.