{"id":14986808,"url":"https://github.com/nickjer/handlebars_switch","last_synced_at":"2025-04-11T23:09:42.944Z","repository":{"id":62439934,"uuid":"115875872","full_name":"nickjer/handlebars_switch","owner":"nickjer","description":"Adds a `{{#switch}}` helper to handlebars-rust","archived":false,"fork":false,"pushed_at":"2024-01-05T13:20:16.000Z","size":15,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T06:20:41.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/nickjer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2017-12-31T17:10:29.000Z","updated_at":"2024-07-22T13:54:17.243Z","dependencies_parsed_at":"2024-07-22T13:53:55.121Z","dependency_job_id":"8a26bcb2-b62e-4207-87bf-3485f637f36a","html_url":"https://github.com/nickjer/handlebars_switch","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickjer%2Fhandlebars_switch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickjer%2Fhandlebars_switch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickjer%2Fhandlebars_switch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickjer%2Fhandlebars_switch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nickjer","download_url":"https://codeload.github.com/nickjer/handlebars_switch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239805935,"owners_count":19700219,"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-09-24T14:13:35.006Z","updated_at":"2025-02-20T08:31:44.583Z","avatar_url":"https://github.com/nickjer.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Handlebars Switch Helper\n\n[![Latest Version](https://img.shields.io/crates/v/handlebars_switch.svg)](https://crates.io/crates/handlebars_switch)\n[![Downloads](https://img.shields.io/crates/d/handlebars_switch.svg)](https://crates.io/crates/handlebars_switch)\n[![License](https://img.shields.io/github/license/nickjer/handlebars_switch.svg)](https://github.com/nickjer/handlebars_switch)\n[![Docs](https://docs.rs/handlebars_switch/badge.svg)](https://docs.rs/handlebars_switch/)\n\nThis provides a [Handlebars](http://handlebarsjs.com/) `{{#switch}}` helper to\nthe already incredible [handlebars-rust](https://github.com/sunng87/handlebars-rust)\ncrate.\n\nLinks of interest:\n\n- [Documentation](https://docs.rs/handlebars_switch)\n- [handlebars-rust](https://github.com/sunng87/handlebars-rust)\n- [Handlebars](http://handlebarsjs.com)\n\n## Quick Start\n\nYou can easily add the ``{{#switch}}`` helper to a rust Handlebars object using\nthe `Handlebars#register_helper` method:\n\n```rust\nuse handlebars::Handlebars;\nuse handlebars_switch::SwitchHelper;\n\nlet mut handlebars = Handlebars::new();\nhandlebars.register_helper(\"switch\", Box::new(SwitchHelper));\n```\n\n### Example\n\nBelow is an example that renders a different page depending on the user's\naccess level:\n\n\n```rust\nextern crate handlebars_switch;\nextern crate handlebars;\n#[macro_use] extern crate serde_json;\n\nuse handlebars::Handlebars;\nuse handlebars_switch::SwitchHelper;\n\nfn main() {\n  let mut handlebars = Handlebars::new();\n  handlebars.register_helper(\"switch\", Box::new(SwitchHelper));\n\n  let tpl = \"\\\n      {{#switch access}}\\\n          {{#case \\\"admin\\\"}}Admin{{/case}}\\\n          {{#default}}User{{/default}}\\\n      {{/switch}}\\\n  \";\n\n  assert_eq!(\n      handlebars.template_render(tpl, \u0026json!({\"access\": \"admin\"})).unwrap(),\n      \"Admin\"\n  );\n\n  assert_eq!(\n      handlebars.template_render(tpl, \u0026json!({\"access\": \"nobody\"})).unwrap(),\n      \"User\"\n  );\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickjer%2Fhandlebars_switch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnickjer%2Fhandlebars_switch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickjer%2Fhandlebars_switch/lists"}