{"id":15554149,"url":"https://github.com/amatsuda/string_template","last_synced_at":"2025-04-07T12:09:55.050Z","repository":{"id":47941946,"uuid":"115608265","full_name":"amatsuda/string_template","owner":"amatsuda","description":"A template engine for Rails, focusing on speed, using Ruby's String interpolation syntax","archived":false,"fork":false,"pushed_at":"2023-01-21T02:11:02.000Z","size":33,"stargazers_count":123,"open_issues_count":1,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-31T11:03:07.612Z","etag":null,"topics":["rails","ruby","template","template-engine"],"latest_commit_sha":null,"homepage":"","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/amatsuda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-28T09:36:33.000Z","updated_at":"2024-12-17T08:02:39.000Z","dependencies_parsed_at":"2023-02-12T07:31:39.452Z","dependency_job_id":null,"html_url":"https://github.com/amatsuda/string_template","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fstring_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fstring_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fstring_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amatsuda%2Fstring_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amatsuda","download_url":"https://codeload.github.com/amatsuda/string_template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648977,"owners_count":20972945,"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":["rails","ruby","template","template-engine"],"created_at":"2024-10-02T14:49:54.482Z","updated_at":"2025-04-07T12:09:55.027Z","avatar_url":"https://github.com/amatsuda.png","language":"Ruby","readme":"# StringTemplate\n\nThe fastest template engine for Rails.\n\n\n## Concept\n\nRuby's String literal has such a powerful interpolation mechanism.\nIt's almost a template engine, it's the fastest way to compose a String, and the syntax is already very well known by every Ruby programmer.\nWhy don't we use this for the view files in our apps?\n\n\n## Installation\n\nAdd this line to your Rails application's Gemfile:\n\n```ruby\ngem 'string_template'\n```\n\nAnd then bundle.\n\n\n## Syntax\n\nStringTemplate's syntax is based on Ruby's String interpolation.\nPlus, you can use Action View features.\n\n### Example\nHere's an example of a scaffold generated ERB template, and its string\\_template version.\n\nERB:\n```\n\u003cp id=\"notice\"\u003e\u003c%= notice %\u003e\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cstrong\u003eTitle:\u003c/strong\u003e\n  \u003c%= @post.title %\u003e\n\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cstrong\u003eBody:\u003c/strong\u003e\n  \u003c%= @post.body %\u003e\n\u003c/p\u003e\n\n\u003c%= link_to 'Edit', \"/posts/#{@post.id}/edit\" %\u003e |\n\u003c%= link_to 'Back', '/posts' %\u003e\n```\n\nstring\\_template:\n```\n\u003cp id=\"notice\"\u003e#{h notice }\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cstrong\u003eTitle:\u003c/strong\u003e\n  #{h @post.title }\n\u003c/p\u003e\n\n\u003cp\u003e\n  \u003cstrong\u003eBody:\u003c/strong\u003e\n  #{h @post.body }\n\u003c/p\u003e\n\n#{ link_to 'Edit', \"/posts/#{@post.id}/edit\" } |\n#{ link_to 'Back', '/posts' }\n```\n\n### More Examples\nPlease take a look at [the tests](https://github.com/amatsuda/string_template/blob/master/test/string_template_test.rb) for actual examples.\n\n\n## File Names\nBy default, string\\_template renders view files with `.string` extension, e.g. `app/views/posts/show.html.string`\n\n\n## Security\nstring\\_template does not automatically `html_escape`. Don't forget to explicitly call `h()` when interpolating possibly HTML unsafe strings, like we used to do in pre Rails 3 era.\n\n\n## So, Should We Rewrite Everything with This?\nstring\\_template may not be the best choice as a general purpose template engine.\nIt may sometimes be hard to express your template in a simple and maintainable code, especially when the template includes some business logic.\nYou need to care about security.\nSo this template engine is recommended to use only for performance hotspots.\nFor other templates, you might better use your favorite template engine such as haml, or haml, or haml.\n\n\n## Benchmark\nFollowing is the benchmark result showing how string\\_template is faster than ERB (Erubi, to be technically accurate), executed on Ruby trunk (2.6).\nThis repo includes [this actual benchmarking script](https://github.com/amatsuda/string_template/blob/master/benchmark.rb) so that you can try it on your machine.\n\n```\n% ruby benchmark.rb\nWarming up --------------------------------------\n                 erb   993.525  i/100ms\n              string     1.911k i/100ms\nCalculating -------------------------------------\n                 erb    11.012k i/s -     49.676k in 4.511268s\n              string    22.029k i/s -     95.529k in 4.336571s\n\nComparison:\n              string:     22028.7 i/s\n                 erb:     11011.5 i/s - 2.00x  slower\n```\n\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/amatsuda/string_template.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famatsuda%2Fstring_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famatsuda%2Fstring_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famatsuda%2Fstring_template/lists"}