{"id":15406753,"url":"https://github.com/dannyben/gtx","last_synced_at":"2025-07-11T14:37:27.817Z","repository":{"id":37956731,"uuid":"503050905","full_name":"DannyBen/gtx","owner":"DannyBen","description":"Minimal Template Engine","archived":false,"fork":false,"pushed_at":"2025-02-05T06:14:22.000Z","size":33,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-26T08:03:08.087Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","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/DannyBen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2022-06-13T17:24:09.000Z","updated_at":"2025-04-30T08:18:05.000Z","dependencies_parsed_at":"2024-01-08T18:32:15.352Z","dependency_job_id":"a357a2ac-da13-44e8-83e5-ed5d7efbc2a6","html_url":"https://github.com/DannyBen/gtx","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"1efbc98b8dd027c5ce2fa6fcf464b6cef51d73ed"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/DannyBen/gtx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fgtx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fgtx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fgtx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fgtx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DannyBen","download_url":"https://codeload.github.com/DannyBen/gtx/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DannyBen%2Fgtx/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264833290,"owners_count":23670617,"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":[],"created_at":"2024-10-01T16:25:13.339Z","updated_at":"2025-07-11T14:37:27.798Z","avatar_url":"https://github.com/DannyBen.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GTX - Minimal Template Engine\n\n[![Gem Version](https://badge.fury.io/rb/gtx.svg)](https://badge.fury.io/rb/gtx)\n[![Build Status](https://github.com/DannyBen/gtx/workflows/Test/badge.svg)](https://github.com/DannyBen/gtx/actions?query=workflow%3ATest)\n[![Maintainability](https://api.codeclimate.com/v1/badges/8c7e16a17866cc0e6a17/maintainability)](https://codeclimate.com/github/DannyBen/gtx/maintainability)\n\n---\n\nGTX is a minimal template engine that transpiles to ERB before using it to \ngenerate the output.\n\nAs opposed to ERB, GTX is a code-first template engine - where Ruby code does\nnot need to be enclosed in tags. Instead, the output of the template needs to\nbe marked with a \"Greater Than\" sign (hence the name).\n\n## Install\n\n```bash\n$ gem install gtx\n```\n\n## Template Syntax\n\n### Summary\n\nGTX converts your template code to ERB before rendering its output. \n\n\u003ctable\u003e\n\u003ctr\u003e\u003cth\u003eGTX\u003c/th\u003e\u003cth\u003eERB\u003c/th\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003e\n\n```ruby\n\u003e any text\n\u003e inline code: {{ \"hello \" * 3 }}\n\u003e          or: \u003c%= \"world \" * 3 %\u003e\n\n3.times do |i|\n  \u003e loopy text {{ i + 1 }}\nend\n\n= user.welcome_message\n```\n      \n\u003c/td\u003e\u003ctd\u003e\n\n```ruby\nany text\ninline code: \u003c%= \"hello \" * 3 %\u003e\n         or: \u003c%= \"world \" * 3 %\u003e\n\n\u003c%- 3.times do |i| -%\u003e\nloopy text \u003c%= i + 1 %\u003e\n\u003c%- end -%\u003e\n\n\u003c%= user.welcome_message %\u003e\n```\n\n\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\nThe conversion is specifically kept at 1:1 line ratio, so that the correct line\nnumber can be referenced in case of an error.\n\n### Explanation\n\nLines starting with `\u003e` are treated as output. Any number of spaces before and\none space after the `\u003e` are ignored:\n\n```ruby\n\u003e this line will output as is\n```\n\nUsing `{{ ... }}` in an output line executes inline ruby code, as if it is\nERB's `\u003c%= ... %\u003e` syntax:\n\n```ruby\n\u003e any ruby code: {{ \"hello \" * 3 }}\n```\n\nLines starting with `=` can be used to execute ruby code that returns a string\nthat is expected to be a part of the output.\n\n```ruby\n= user.welcome_message(:morning)\n# which is a shortcut to:\n\u003e {{ user.welcome_message(:morning) }}\n```\n\nAny other line, will be treated as Ruby code and will be enclosed using ERB's \n`\u003c%- ... -%\u003e` syntax.\n\nSee the [example template](examples/full.gtx) for additional nuances.\n\n## Usage\n\n### Using a GTX Instance\n\n```ruby\nrequire 'gtx'\n\n# Create an instance\npath = \"path/to/template_file\"\ntemplate = File.read path\ngtx = GTX.new template, filename: path\n\n# Parse it with optional context\ngtx.parse any_object\n\n# ... or with local binding\ngtx.parse binding\n\n# Get the ERB source\ngtx.erb_source\n\n# ... or the ERB object\ngtx.erb\n\n```\n\n### Class Shortcuts\n\n```ruby\nrequire 'gtx'\n\n# One-liner render template from file\nGTX.render_file path\n\n# ... with a context or Binding object\nGTX.render_file path, context: any_object\n\n# Get an instance, and parse later\ngtx = GTX.load_file path\ngtx.parse optional_context_object\n\n# Render from string\nGTX.render string, context: optional_object, filename: optional_filename\n```\n\n\n## But... why?\n\nGTX was created to provide a code-first alternative to ERB, specifically for \nthe [code generation templates][bashly-views] used by [Bashly][bashly].\nEnclosing Ruby code inside ERB tags, and ensuring there are no excess empty\nlines in the ERB template yielded some hard-to-maintain templates.\n\n\n## Contributing / Support\n\nIf you experience any issue, have a question or a suggestion, or if you wish\nto contribute, feel free to [open an issue][issues].\n\n---\n\n[issues]: https://github.com/DannyBen/gtx/issues\n[bashly]: https://bashly.dannyb.co/\n[bashly-views]: https://github.com/DannyBen/bashly/tree/master/lib/bashly/views\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Fgtx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdannyben%2Fgtx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannyben%2Fgtx/lists"}