{"id":15046257,"url":"https://github.com/upmc-enterprises/captain-whisker","last_synced_at":"2025-09-10T19:34:15.652Z","repository":{"id":42258067,"uuid":"127033730","full_name":"upmc-enterprises/captain-whisker","owner":"upmc-enterprises","description":"JSON templating for node.js REST APIs","archived":false,"fork":false,"pushed_at":"2023-01-07T03:57:16.000Z","size":1106,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-01-31T20:52:06.475Z","etag":null,"topics":["handlebars","json","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/upmc-enterprises.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}},"created_at":"2018-03-27T19:06:50.000Z","updated_at":"2024-09-15T19:36:23.000Z","dependencies_parsed_at":"2023-02-06T11:16:23.149Z","dependency_job_id":null,"html_url":"https://github.com/upmc-enterprises/captain-whisker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upmc-enterprises%2Fcaptain-whisker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upmc-enterprises%2Fcaptain-whisker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upmc-enterprises%2Fcaptain-whisker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upmc-enterprises%2Fcaptain-whisker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/upmc-enterprises","download_url":"https://codeload.github.com/upmc-enterprises/captain-whisker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238347839,"owners_count":19457002,"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":["handlebars","json","nodejs"],"created_at":"2024-09-24T20:52:55.420Z","updated_at":"2025-02-11T18:32:36.368Z","avatar_url":"https://github.com/upmc-enterprises.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Captain Whisker\n\nCaptain Whisker leverages Handlebars to make JSON templating easy in Node.js.  Coming from rails, I really missed\n[Jbuilder](https://github.com/rails/jbuilder), and the existing similar solutions in Node.js were either abandoned or\nnot quite what I wanted.  It's probably overly simple and naive right now, but it works surprisingly well.\n\nHere is a simple example:\n\n```\n// view.hbs\n{{#jsonList users}}\n  {\n    \"id\": {{json id}},\n    \"firstName\": {{json firstName}},\n    \"lastName\": {{json lastName}}\n  }\n{{/jsonlist}}\n\n// app.js\nconst CaptainWhisker = require('captain-whisker');\nCaptainWhisker.initialize('./src');\nCaptainWhisker.build(\n  'view.hbs', \n  { \n    users: [\n      {\n        id: 1,\n        firstName: 'Jerry',\n        lastName: 'Seinfeld'\n      },\n      {\n        id: 2,\n        firstName: 'George',\n        lastName: 'Costanza'\n      },\n      {\n        id: 3,\n        firstName: undefined,\n        lastName: 'Kramer'\n      }\n    ]\n  }\n);\n```\n\nWould produce a JSON structure like this:\n\n```\n[\n  {\n    \"id\": 1,\n    \"firstName\": \"Jerry\",\n    \"lastName\": \"Seinfeld\"\n  },\n  {\n    \"id\": 2,\n    \"firstName\": \"George\",\n    \"lastName\": \"Costanza\"\n  },\n  {\n    \"id\": 3,\n    \"firstName\": null,\n    \"lastName\": \"Kramer\"\n  }\n]\n```\n\n## Finding template files\n\nCalling `CaptainWhisker.initialize('./root')` will search your source directory and all subdirectories for files with an\n`.hbs` extension.  This shold be done once per process; CaptainWhisker will store store the precompiled templates so\nthey don't need to be compiled with every use.  Any `.hbs` files it finds that don't start with `_` will be compiled and\nregistered as templates, usable with `CaptainWhisker.build('path/relative/to/root.hbs', context)`.  \n\nAny files that have names beginning with an underscore will be considered partials.\n\n## Partials support\n\nCaptainWhisker supports partials, so you can reuse pieces of templates across your views.  For example:\n\n```\n// _user.hbs\n{\n  \"id\": {{json id}},\n  \"firstName\": {{json firstName}},\n  \"lastName\": {{json lastName}}\n}\n\n// index.hbs\n{{#jsonList users}}\n  {{\u003e _user}}\n{{/jsonList}}\n\n// update.hbs - pass a context object and a param to the partial\n{{\u003e _user user id=foo.id}}\n```\n\nFor details on passing partial contexts and parameter, see the [Handlebars](http://handlebarsjs.com/partials.html)\ndocumentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupmc-enterprises%2Fcaptain-whisker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fupmc-enterprises%2Fcaptain-whisker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupmc-enterprises%2Fcaptain-whisker/lists"}