Code Monkey home page Code Monkey logo

gotmpl's Introduction

gotmpl

gotmpl is a command-line interface (CLI) tool for template rendering. Whether you're working with templates from stdin, files, or web resources, gotmpl simplifies the process by allowing you to provide multiple data inputs through arguments, files, or URLs. The rendered output can be directed to stdout or saved into a specified file.

Example

$ echo "Hello, {{.Name}}" | go run main.go -data '{"Name": "John"}'
Hello, John%     

Usage

Currently supported arguments can be listed as follow.

$ ./gotmpl --help
Usage: gotmpl [options] -tmpl {URL,Path} -out {Path}
Options:
  -data value
        Data to use {URL,Path,JSON}. Multiple allowed.
  -help
        Show this help message.
  -out string
        Render output {Path} or stdout.
  -tmpl string
        Template to use {URL,Path} or stdin.

This cli tool uses the go text template engine. A documentation for that is available here. In general, the tool can be used as follow:

  1. provide a template
    • from a file like -tmpl /some/path/mail_template.txt
    • from a web resource like -tmpl https://some.url/mail_template (requires http or https prefix)
    • from std like echo "template" | ... (without -tmpl argument)
  2. provide data (for multiple data source see note below)
    • from a JSON formatted file like -tmpl /some/path/user_a.json
    • from a JSON formatted web resource like -tmpl https://some.url/user_a (requires http or https prefix)
    • directly as JSON formatted string -tmpl '{...}' or -tmpl '[...]'
  3. define the output
    • into a file like -out result.txt
    • stdout is used by default if -out not defined

NOTE: When using multiple data sources, they are placed in an array (keeping the order). For example the templates will look as follow multiple data sources:

echo "Name: {{(index . 0).Name}}, Age: {{(index . 1).Age}}" | ./gotmpl -data '{"Name": "Nina"}' -data '{"Age": 33}'
# OR
echo "Name: {{index . 0 \"Name\"}}, Age: {{index . 1 \"Age\"}}" | ./gotmpl -data '{"Name": "Nina"}' -data '{"Age": 33}'

With single data source:

echo "Name: {{.Name}}, Age: {{.Age}}" | ./gotmpl -data '{"Name": "Nina", "Age": 33}'

gotmpl's People

Contributors

stevencyb avatar

Watchers

 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.