{"id":15593451,"url":"https://github.com/gi/handlebars-ruby","last_synced_at":"2026-03-07T04:01:32.140Z","repository":{"id":43809906,"uuid":"442300209","full_name":"gi/handlebars-ruby","owner":"gi","description":"A Ruby interface to the official JavaScript version of Handlebars.","archived":false,"fork":false,"pushed_at":"2025-08-12T07:47:03.000Z","size":59,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-10-07T20:22:52.279Z","etag":null,"topics":["handlebars","ruby"],"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/gi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2021-12-27T23:48:35.000Z","updated_at":"2025-08-12T07:47:07.000Z","dependencies_parsed_at":"2025-08-12T06:07:26.397Z","dependency_job_id":"f0371ff5-f882-40b9-81c5-adbdff0345d6","html_url":"https://github.com/gi/handlebars-ruby","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/gi/handlebars-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gi%2Fhandlebars-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gi%2Fhandlebars-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gi%2Fhandlebars-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gi%2Fhandlebars-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gi","download_url":"https://codeload.github.com/gi/handlebars-ruby/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gi%2Fhandlebars-ruby/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30207390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T03:24:23.086Z","status":"ssl_error","status_checked_at":"2026-03-07T03:23:11.444Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["handlebars","ruby"],"created_at":"2024-10-03T00:18:45.512Z","updated_at":"2026-03-07T04:01:32.111Z","avatar_url":"https://github.com/gi.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Handlebars::Engine\n\n[![Gem Version](https://badge.fury.io/rb/handlebars-engine.svg)](https://rubygems.org/gems/handlebars-engine)\n[![CI Status](https://github.com/gi/handlebars-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/gi/handlebars-ruby/actions/workflows/ci.yml)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/45d98ad9e12ee3384161/test_coverage)](https://codeclimate.com/github/gi/handlebars-ruby/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/45d98ad9e12ee3384161/maintainability)](https://codeclimate.com/github/gi/handlebars-ruby/maintainability)\n[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)\n\nA complete interface to [Handlebars.js](https://handlebarsjs.com) for Ruby.\n\n`Handlebars::Engine` provides a complete Ruby API for the official JavaScript\nversion of Handlebars, including the abilities to register Ruby blocks/procs as\nHandlebars helper functions and to dynamically register partials.\n\nIt uses [MiniRacer](https://github.com/rubyjs/mini_racer) for the bridge between\nRuby and the V8 JavaScript engine.\n\n`Handlebars::Engine` was created as a replacement for\n[handlebars.rb](https://github.com/cowboyd/handlebars.rb).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'handlebars-engine'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install handlebars-engine\n\n## Usage\n\n### Quick Start\n\n```ruby\nhandlebars = Handlebars::Engine.new\ntemplate = handlebars.compile(\"{{firstname}} {{lastname}}\")\ntemplate.call({ firstname: \"Yehuda\", lastname: \"Katz\" })\n# =\u003e \"Yehuda Katz\"\n```\n\n### Custom Helpers\n\nHandlebars helpers can be accessed from any context in a template. You can\nregister a helper with the `register_helper` method:\n\n```ruby\nhandlebars = Handlebars::Engine.new\nhandlebars.register_helper(:loud) do |ctx, arg, opts|\n  arg.upcase\nend\ntemplate = handlebars.compile(\"{{firstname}} {{loud lastname}}\")\ntemplate.call({ firstname: \"Yehuda\", lastname: \"Katz\" })\n# =\u003e \"Yehuda KATZ\"\n```\n\n#### Helper Arguments\n\nHelpers receive the current context as the first argument of the block.\n\n```ruby\nhandlebars = Handlebars::Engine.new\nhandlebars.register_helper(:full_name) do |ctx, opts|\n  \"#{ctx[\"firstname\"]} #{ctx[\"lastname\"]}\"\nend\ntemplate = handlebars.compile(\"{{full_name}}\")\ntemplate.call({ firstname: \"Yehuda\", lastname: \"Katz\" })\n# =\u003e \"Yehuda Katz\"\n```\n\nAny arguments to the helper are included as individual positional arguments.\n\n```ruby\nhandlebars = Handlebars::Engine.new\nhandlebars.register_helper(:join) do |ctx, *args, opts|\n  args.join(\" \")\nend\ntemplate = handlebars.compile(\"{{join firstname lastname}}\")\ntemplate.call({ firstname: \"Yehuda\", lastname: \"Katz\" })\n# =\u003e \"Yehuda Katz\"\n```\n\nThe last argument is a hash of options.\n\nSee https://handlebarsjs.com/guide/#custom-helpers.\n\n### Block Helpers\n\nBlock helpers make it possible to define custom iterators and other\nfunctionality that can invoke the passed block with a new context.\n\nCurrently, there is a limitation with the underlying JavaScript engine: it does\nnot allow for reentrant calls from within attached Ruby functions: see\n[MiniRacer#225](https://github.com/rubyjs/mini_racer/issues/225). Thus, the\nblock function returned to the helper (in `options.fn`) cannot be  invoked.\n\nThus, for block helpers, a string of JavaScript must define the helper function:\n```ruby\nhandlebars = Handlebars::Engine.new\nhandlebars.register_helper(map: \u003c\u003c~JS)\n  function(...args) {\n    const ctx = this;\n    const opts = args.pop();\n    const items = args[0];\n    const separator = args[1];\n    const mapped = items.map((item) =\u003e opts.fn(item));\n    return mapped.join(separator);\n  }\nJS\ntemplate = handlebars.compile(\"{{#map items '|'}}'{{this}}'{{/map}}\")\ntemplate.call({ items: [1, 2, 3] })\n# =\u003e \"'1'|2'|'3'\"\n```\n\nSee https://handlebarsjs.com/guide/#block-helpers.\n\n### Partials\n\nHandlebars partials allow for code reuse by creating shared templates.\n\nYou can register a partial using the `register_partial` method:\n\n```ruby\nhandlebars = Handlebars::Engine.new\nhandlebars.register_partial(:person, \"{{person.name}} is {{person.age}}.\")\ntemplate = handlebars.compile(\"{{\u003e person person=.}}\")\ntemplate.call({ name: \"Yehuda Katz\", age: 20 })\n# =\u003e \"Yehuda Katz is 20.\"\n```\n\nSee https://handlebarsjs.com/guide/#partials.\nSee https://handlebarsjs.com/guide/partials.html.\n\n### Hooks\n\n#### Helper Missing\n\nThis hook is called for a mustache or a block-statement when\n* a simple mustache-expression is not a registered helper, *and*\n* it is not a property of the current evaluation context.\n\nYou can add custom handling for those situations by registering a helper with\nthe `register_helper_missing` method:\n\n```ruby\nhandlebars = Handlebars::Engine.new\nhandlebars.register_helper_missing do |ctx, *args, opts|\n  \"Missing: #{opts[\"name\"]}(#{args.join(\", \")})\"\nend\n\ntemplate = handlebars.compile(\"{{foo 2 true}}\")\ntemplate.call\n# =\u003e \"Missing: foo(2, true)\"\n\ntemplate = handlebars.compile(\"{{#foo true}}{{/foo}}\")\ntemplate.call\n# =\u003e \"Missing: foo(true)\"\n```\n\nSee https://handlebarsjs.com/guide/hooks.html#helpermissing.\n\n##### Blocks\n\nThis hook is called for a block-statement when\n* a block-expression calls a helper that is not registered, *and*\n* the name is a property of the current evaluation context.\n\nYou can add custom handling for those situations by registering a helper with\nthe `register_helper_missing` method (with a `:block` argument):\n\n```ruby\nhandlebars = Handlebars::Engine.new\nhandlebars.register_helper_missing(:block) do |ctx, *args, opts|\n  \"Missing: #{opts[\"name\"]}(#{args.join(\", \")})\"\nend\n\ntemplate = handlebars.compile(\"{{#person}}{{name}}{{/person}}\")\ntemplate.call({ person: { name: \"Yehuda Katz\" } })\n# =\u003e \"Missing: person\"\n```\n\nSee https://handlebarsjs.com/guide/hooks.html#blockhelpermissing.\n\n#### Partial Missing\n\nThis hook is called for a partial that is not registered.\n\n```ruby\nhandlebars = Handlebars::Engine.new\nhandlebars.register_partial_missing do |name|\n  \"partial: #{name}\"\nend\n```\n\nNote: This is not a part of the offical Handlebars API. It is provided for\nconvenience.\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for more details.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub:\nhttps://github.com/gi/handlebars-ruby.\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for more details.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgi%2Fhandlebars-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgi%2Fhandlebars-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgi%2Fhandlebars-ruby/lists"}