Skip to content

pseudo-su/templ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Templ

Note
This library is a work in progress

Templ is a library to allow loading structured data (YAML/JSON/TOML) and applying go-like templating to the string fields, enabling relative references to the same document.

Example usage
os.Setenv("SOME_ENV_VAR", "some_env_var_value")

params := map[string]string{
  "param_name": "param_value"
}

expandedTree, err := templ.New().Params(params).File("./service.yaml").Execute()
Example service.yaml input
data:
  string: Hello World
  array:
    - Array
    - of
    - strings
  object:
    key: val
example_env: ${ env `SOME_ENV_VAR` }
example_param: ${ param `param_name` }
example_self_1: ${ self `data.string` }
example_self_2: ${ self `data.array` }
example_self_3: ${ self `data.object` }
Example output
data:
  string: Hello World
  array:
  - Array
  - of
  - strings
  object:
    key: val
example_env: some_env_var_value
example_param: param_value
example_1: Hello World
example_2:
  array:
  - Array
  - of
  - strings
example_3:
  object:
    key: val

Contributing

Install Tool Dependencies

# install golanglint-ci into ./bin
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.16.0
# Install gobin globally
env GO111MODULE=off go get -u github.com/myitcv/gobin

Build tasks

Note
if this repo is cloned into you GOPATH you will need to prefix all commands with GO111MODULES=on

CLI Example (example/ folder)

  • codegen: go generate ./...

  • build: go build -o stencil example/*.go

  • run: ./stencil package --cwd=example/

Project ideas & potential features

  • Preserve the key order when Unmarshalling JSON/YAML/TOML

  • Implement as a lexer/parser/ast

  • Implment Unmarshal-ing the tree into your own custom data types

  • Support for "Layering" Nodes/trees trees similar to onion

  • Add ability to provide additional functions that hook-in to the node tree

  • Marshal tree back to JSON/YAML/TOML

  • Example CLI tool that uses templ library

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published