Skip to content
/ twit Public
forked from bander2/twit

A simple CLI Tool for wrIting templates.

License

Notifications You must be signed in to change notification settings

jpsainea/twit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TWIT

TWIT is a simple CLI Tool for WrIting Templates. It is really just a wrapper Go's text and html templates implementation which allows for command line usage.

Usage

Templates

Templates are written in the standard Go template format.

Filters

Filter support comes from the leekchan/gtf package.

Parameters

TWIT accepts parameters for the template as either a YAML file or as a JSON string.

Example

For our example, let's image that we needed to write an Apache vhosts configuration file.

First we create a template. We'll call it vhosts.conf.tpl:

Listen {{ .port }}

ServerName {{ .server_name }}
DocumentRoot "{{ .document_root }}"

{{ range $host := .hosts }}
    <VirtualHost {{ $host.ip }}>
        DocumentRoot "{{ $host.document_root }}"
        ServerName {{ $host.server_name }}
    </VirtualHost>
{{ end }}

Then we will create a YAML encoded file to hold the parameters. We'll call it vhosts.yml:

port:          80
server_name:   server.company.com
document_root: /srv/main
hosts:
  - ip:            172.20.30.1
    document_root: /srv/website1
    server_name:   site1.company.com
  - ip:            172.20.30.2
    document_root: /srv/website2
    server_name:   site2.company.com

Generate the Apache configuration with TWIT:

$ twit vhosts.conf.tpl /etc/apache2/sites-available/vhosts.conf -p vhosts.yml

About

A simple CLI Tool for wrIting templates.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%