{"id":16846882,"url":"https://github.com/othree/sandbox-hogan","last_synced_at":"2025-03-18T07:16:27.006Z","repository":{"id":9454440,"uuid":"11334497","full_name":"othree/sandbox-hogan","owner":"othree","description":"Hogan in sandbox, simple interface design","archived":false,"fork":false,"pushed_at":"2013-09-26T04:16:42.000Z","size":164,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-13T13:05:50.365Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/othree.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-11T06:24:07.000Z","updated_at":"2014-05-27T23:43:52.000Z","dependencies_parsed_at":"2022-07-13T04:20:47.160Z","dependency_job_id":null,"html_url":"https://github.com/othree/sandbox-hogan","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/othree%2Fsandbox-hogan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othree%2Fsandbox-hogan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othree%2Fsandbox-hogan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othree%2Fsandbox-hogan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/othree","download_url":"https://codeload.github.com/othree/sandbox-hogan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244173553,"owners_count":20410300,"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-13T13:05:41.770Z","updated_at":"2025-03-18T07:16:26.953Z","avatar_url":"https://github.com/othree.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Sandbox-Hogan\n=============\n\nHogan uses `new Function`, which is eval code. And for security concern. Some environment didn't allow\neval code, ex: Chrome's extension environment. But it allows eval inside sandbox.\nAnd you can use postMessage to communicate between your normal page and sandbox page.\n\nThis project defines a simple interface for compile and render mustache template via Hogan engine through postMessage.\nYou can use this not only in iframe. Every window you can postMessage to it. Can use this.\n    \nUSAGE\n-----\n\npostMessage data should use an object and contains a property called 'hogan':\n\n    sandboxHogan.postMessage({\n        hogan: {\n      \n        }\n    }, '*');\n\nThe object 'hogan' can contains two properties: 'compile', 'render':\n\n    sandboxHogan.postMessage({\n        hogan: {\n            compile: 'template string'     \n        }\n    }, '*');\n\n    sandboxHogan.postMessage({\n        hogan: {\n            render: {\n                this_is: 'data object'\n            }\n        }\n    }, '*');\n\nAnd when work complete. The sandboxHogan will send message and result back:\n\n    var handler = {\n        compileDone: function () {\n            console.log('template ready');\n        },\n        renderDone: function (result) {\n            document.getElementById('share_txt').innerHTML = result;\n        }\n    };\n\n    window.addEventListener('message', function (event) {\n        var data = event.data.hogan;\n        if (!data) { return; }\n        var hand = handler[data.event];\n        if (typeof hand === 'function') { hand(data.value); }\n    }, false);\n\nResult will wrapped in 'hogan' object, so you can detect it to see is it hogan's reply.\nIf you have multiple templates to use, you can give them name:\n\n    sandboxHogan.postMessage({\n        hogan: {\n            compile: ['template name', 'template string']\n        }\n    }, '*');\n\n    sandboxHogan.postMessage({\n        hogan: {\n            render: ['template name', {\n                this_is: 'data object'\n            }]\n        }\n    }, '*');\n\nAnd when result returns, you can access the template name:\n\n    var handler = {\n        renderDone: function (result) {\n            if (result.name === 'template name') {\n                document.getElementById('share_txt').innerHTML = result;\n            }\n        }\n    };\n\nHogan compile, render might fail. If fail, the response event will go to 'Fail' one. Ex: compileFail, renderFail.\n\nStatus\n------\n\n[![Build Status](https://travis-ci.org/othree/sandbox-hogan.png?branch=master)](https://travis-ci.org/othree/sandbox-hogan)\n\nLicense\n-------\n\nCopyright (C) 2013 Wei-Ko Kao\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothree%2Fsandbox-hogan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fothree%2Fsandbox-hogan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothree%2Fsandbox-hogan/lists"}