{"id":16813121,"url":"https://github.com/ivanvc/tpl","last_synced_at":"2025-04-11T01:52:08.413Z","repository":{"id":181548907,"uuid":"666945428","full_name":"ivanvc/tpl","owner":"ivanvc","description":"Simple gotemplate wrapper","archived":false,"fork":false,"pushed_at":"2023-08-05T06:11:38.000Z","size":61,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T23:16:13.057Z","etag":null,"topics":["gotemplate","template","templates"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivanvc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-16T05:46:21.000Z","updated_at":"2024-12-16T00:46:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"af612ed7-cd06-49f4-8103-95ecea97478a","html_url":"https://github.com/ivanvc/tpl","commit_stats":null,"previous_names":["ivanvc/tpl"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanvc%2Ftpl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanvc%2Ftpl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanvc%2Ftpl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanvc%2Ftpl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivanvc","download_url":"https://codeload.github.com/ivanvc/tpl/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328108,"owners_count":21085258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gotemplate","template","templates"],"created_at":"2024-10-13T10:24:48.846Z","updated_at":"2025-04-11T01:52:08.403Z","avatar_url":"https://github.com/ivanvc.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tpl\n\n\u003csvg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" align=\"right\" width=\"81px\" height=\"43px\" style=\"shape-rendering:geometricPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality; fill-rule:evenodd; clip-rule:evenodd\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\u003e\n\u003cg\u003e\n\u003cpath style=\"opacity:1\" fill=\"#9f9cfa\" d=\"M 9.5,2.5 C 11.5,2.5 13.5,2.5 15.5,2.5C 15.5,5.16667 15.5,7.83333 15.5,10.5C 17.8333,10.5 20.1667,10.5 22.5,10.5C 22.5,12.8333 22.5,15.1667 22.5,17.5C 20.1667,17.5 17.8333,17.5 15.5,17.5C 15.5,20.1667 15.5,22.8333 15.5,25.5C 17.8333,25.5 20.1667,25.5 22.5,25.5C 22.5,27.5 22.5,29.5 22.5,31.5C 18.1667,31.5 13.8333,31.5 9.5,31.5C 9.5,26.8333 9.5,22.1667 9.5,17.5C 7.16667,17.5 4.83333,17.5 2.5,17.5C 2.5,15.1667 2.5,12.8333 2.5,10.5C 4.83333,10.5 7.16667,10.5 9.5,10.5C 9.5,7.83333 9.5,5.16667 9.5,2.5 Z\"/\u003e\n\u003cpath style=\"opacity:1\" fill=\"#9f9cfa\" d=\"M 58.5,2.5 C 60.5,2.5 62.5,2.5 64.5,2.5C 64.5,10.1667 64.5,17.8333 64.5,25.5C 66.8333,25.5 69.1667,25.5 71.5,25.5C 71.5,27.5 71.5,29.5 71.5,31.5C 67.1667,31.5 62.8333,31.5 58.5,31.5C 58.5,21.8333 58.5,12.1667 58.5,2.5 Z\"/\u003e\n\u003cpath style=\"opacity:1\" fill=\"#9f9cfa\" d=\"M 30.5,10.5 C 37.1667,10.5 43.8333,10.5 50.5,10.5C 50.5,17.5 50.5,24.5 50.5,31.5C 45.8333,31.5 41.1667,31.5 36.5,31.5C 36.5,34.1667 36.5,36.8333 36.5,39.5C 34.5,39.5 32.5,39.5 30.5,39.5C 30.5,29.8333 30.5,20.1667 30.5,10.5 Z M 36.5,17.5 C 39.1667,17.5 41.8333,17.5 44.5,17.5C 44.5,20.1667 44.5,22.8333 44.5,25.5C 41.8333,25.5 39.1667,25.5 36.5,25.5C 36.5,22.8333 36.5,20.1667 36.5,17.5 Z\"/\u003e\n\u003c/g\u003e\n\u003c/svg\u003e\n\n`tpl` is a simple [Go template] wrapper. It enables using them in the command\nline by using the `tpl` binary.\n\n## Installation\n\n1. Download the binary from the [releases page], or\n2. Download with go\n    ```bash\n    $ go install github.com/ivanvc/tpl@latest\n    ```\n3. Or use it with Docker\n    ```bash\n    $ docker run --rm ivan/tpl:latest --help\n    ```\n\n## Usage\n\n```bash\n$ tpl -h\nUsage: tpl [options] [template input]:\n\nExecutes the template from the input applying the environment passed in options.\n\nIf you specify the input template via an option flag (-input), then it will\nread it inline.\nIf you specify that the template comes from the stdin by setting the option flag\n(-stdin), then it will read it inline from the stdin.\nIf you set it as the first argument, it assumes that it is a file.\n\nFor the environment (-env) it will expect it as inline data. However, if you\nstart it with @, it will assume it is a file. It tries to guess the format,\ngiving precedence to JSON, then TOML, and lastly to YAML. Unless you specify to\nforce parsing it via an option flag.\n\nThe output is sent to stdout.\n\nOptions:\n  -debug\n        Set log level to debug.\n  -env string\n        The environment for the template (YAML, JSON or TOML).\n  -input string\n        The template input to process.\n  -json\n        Force the environment to be parsed as a JSON.\n  -stdin\n        Read template from stdin.\n  -toml\n        Force the environment to be parsed as a TOML.\n  -yaml\n        Force the environment to be parsed as a YAML.\n```\n\n### YAML\n\nAssuming you have a template with:\n\n```hcl\nmodule \"app\" {\n    source = \"../modules/app\"\n    name   = \"{{ .name }}\"\n}\n```\n\nExecuting with the following YAML environment:\n\n```YAML\nname: test\n```\n\n```bash\n$ cat \u003c\u003cEOF | tpl -env 'name: test' -stdin\nmodule \"app\" {\n    source = \"../modules/app\"\n    name   = \"{{ .name }}\"\n}\nEOF\n```\n\nReturns the rendered output:\n\n```hcl\nmodule \"app\" {\n    source = \"../modules/app\"\n    name   = \"test\"\n}\n```\n\n### \u003ca name=\"JSON\"\u003e\u003c/a\u003eJSON\n\nIt works with JSON environments:\n\n```bash\n$ cat \u003c\u003cEOF | tpl -stdin -env \"$(curl https://api.github.com/users/ivanvc/events 2\u003e /dev/null)\"\n{{- define \"type\" -}}\n{{ . | replace \"Event\" \"\" | lower }}\n{{- end -}}\n{{- range . }}\n{{ .created_at | toDate \"2006-01-02T15:04:05Z07:00\" | ago }} ago {{ include \"type\" .type }}:\n{{- with .repo }}\n  {{ .name }}: {{ .url }}\n{{- end }}\n{{- end }}\nEOF\n```\n\nGenerates the output:\n\n```\n18h51m49s ago push:\n  ivanvc/tpl: https://api.github.com/repos/ivanvc/tpl\n18h58m44s ago push:\n  ivanvc/tpl: https://api.github.com/repos/ivanvc/tpl\n35h53m29s ago push:\n  ivanvc/tpl: https://api.github.com/repos/ivanvc/tpl\n35h59m5s ago create:\n  ivanvc/tpl: https://api.github.com/repos/ivanvc/tpl\n36h0m1s ago create:\n  ivanvc/tpl: https://api.github.com/repos/ivanvc/tpl\n95h44m45s ago push:\n  ivanvc/aports: https://api.github.com/repos/ivanvc/aports\n95h52m22s ago push:\n  ivanvc/aports: https://api.github.com/repos/ivanvc/aports\n...\n```\n\n### TOML\n\nIt also supports TOML. Generating index pages is easy, given the\n`index.html.tpl` template:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003eIndex\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eIndex of {{ .dir }}\u003c/h1\u003e\n    \u003cul\u003e\n      {{- range .files }}\n      \u003cli\u003e\u003ca href=\"{{ . }}\"\u003e{{ . }}\u003c/a\u003e\u003c/li\u003e\n      {{- end }}\n    \u003c/ul\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nRunning it with:\n\n```bash\n$ tpl -env @\u003c(echo -e \"dir='$(basename $PWD)'\\nfiles=['$(echo * | sed s/[[:space:]]/\\',\\'/g)']\") index.html.tpl\n```\n\nGenerates the following output:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003eIndex\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eIndex of tpl\u003c/h1\u003e\n    \u003cul\u003e\n      \u003cli\u003e\u003ca href=\"Dockerfile\"\u003eDockerfile\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"go.mod\"\u003ego.mod\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"go.sum\"\u003ego.sum\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"internal\"\u003einternal\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"main.go\"\u003emain.go\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"pkg\"\u003epkg\u003c/a\u003e\u003c/li\u003e\n      \u003cli\u003e\u003ca href=\"README.md\"\u003eREADME.md\u003c/a\u003e\u003c/li\u003e\n    \u003c/ul\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Template functions\n\n`tpl` includes Sprig functions, refer to their\n[documentation](https://masterminds.github.io/sprig/).\n\n* `include`: This function is as defined by Helm. So you can include\n  templates defined before, see the [JSON](#JSON) example to see its usage.\n* `fileSize`: This function returns a human-readable file size from\n  integer bytes, i.e. given the input \"1024\", it returns \"1.0 kB\".\n\n## License\n\nSee [LICENSE](LICENSE) © [Ivan Valdes](https://github.com/ivanvc/)\n\n[Go template]: https://pkg.go.dev/text/template\n[releases page]: https://github.com/ivanvc/tpl/releases\n\n\u003c!--\n▄█▄ ▄▄▄ █\n █▄ █▄█ █▄\n    ▀\n--\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanvc%2Ftpl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanvc%2Ftpl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanvc%2Ftpl/lists"}