GithubHelp home page GithubHelp logo

mathiasgr / render Goto Github PK

View Code? Open in Web Editor NEW

This project forked from virtuslab/render

0.0 0.0 0.0 3.95 MB

Universal data-driven template for generating textual output, as a static binary and a library

License: Apache License 2.0

Makefile 17.99% Go 82.01%

render's Introduction

render

Version Travis CI Github All Releases Go Report Card GoDoc

Universal data-driven templates for generating textual output. Can be used as a single static binary (no dependencies) or as a golang library.

The renderer extends go-template and Sprig functions.

If you are interested in one of the use cases, take a look at this blog post about Kubernetes resources rendering. Also see Helm compatibility.

Installation

Binaries

For binaries please visit the Releases Page.

The binaries are statically compiled and does not require any dependencies.

Via Go

$ go get github.com/VirtusLab/render

Usage

$ render --help
NAME:
   render - Universal file renderer

USAGE:
   render [global options] command [command options] [arguments...]

VERSION:
   v0.0.5-3155324

AUTHOR:
   VirtusLab

COMMANDS:
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug, -d               run in debug mode
   --in value                the input template file, stdin if empty
   --out value               the output file, stdout if empty
   --config value            optional configuration YAML file, can be used multiple times
   --set value, --var value  additional parameters in key=value format, can be used multiple times
   --help, -h                show help
   --version, -v             print the version

Notes:

  • --in, --out take only files (not directories) at the moment, --in will consume any file as long as it can be parsed
  • stdin and stdout can be used instead of --in and --out
  • --config accepts any YAML file, can be used multiple times, the values of the configs will be merged
  • --set, --var are the same (one is used in Helm, the other in Terraform), we provide both for convenience, any values set here will override values form configuration files

Command line

Example usage of render with stdin, stdout and --var:

$ echo "something {{ .value }}" | render --var "value=new"
something new

Example usage of render with --in, --out and --config:

$ echo "something {{ .value }}" > test.txt.tmpl
$ echo "value: new" > test.config.yaml
$ ./render --in test.txt.tmpl --out test.txt --config test.config.yaml
$ cat test.txt
something new

Also see a more advanced template example.

As a library

package example

import (
    "github.com/VirtusLab/render/renderer"
    "github.com/VirtusLab/render/renderer/configuration"
)

func CustomRender(template string) (string, error) {
    config := configuration.Configuration{}
    r := renderer.New(config, renderer.MissingKeyErrorOption)
    return r.Render("nameless", template)
}

See also other functions.

Also see tests for more usage examples.

Notable standard and sprig functions

All syntax and functions:

Custom functions

  • render - calls the render from inside of the template, making the renderer recursive
  • readFile - reads a file from a path, relative paths are translated to absolute paths, based on root function
  • root - the root path, used for relative to absolute path translation in any file based operations; by default PWD is used
  • toYaml - provides a configuration data structure fragment as a YAML format
  • gzip, ungzip - use gzip compression and extraction inside the templates, for best results use with b64enc and b64dec

See also example template and a more detailed documentation.

Helm compatibility

As of now, there is a limited Helm 2 Chart compatibility, simple Charts will render just fine.

There is no plan to implement full compatibility with Helm, because of unnecessary complexity that would bring.

Limitations and future work

Planned new functions

  • encrypt, decrypt - cloud KMS (AWS, Amazon, Google) based encryption for any data

Planned new features

  • directories as --in and --out arguments, currently only files are supported

Operating system support

We provide cross-compiled binaries for most platforms, but is currently used mainly with linux/amd64.

Contribution

Feel free to file issues or pull requests.

Development

mkdir $GOPATH/src/github.com/VirtusLab/
git clone 

go get -u github.com/golang/dep/cmd/dep

export PATH=$PATH:$GOPATH/bin
cd $GOPATH/src/github.com/VirtusLab/render
make all

The name

We believe in obvious names. It renders. It's a verb. It's render.

render's People

Contributors

antoniaklja avatar pawelprazak avatar pdolega avatar placydo avatar

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.