{"id":16001201,"url":"https://github.com/gimenete/emmental","last_synced_at":"2025-06-29T17:35:04.243Z","repository":{"id":1896430,"uuid":"2822886","full_name":"gimenete/emmental","owner":"gimenete","description":"Template engine for Nodejs","archived":false,"fork":false,"pushed_at":"2015-10-13T16:33:53.000Z","size":148,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T23:15:30.665Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gimenete.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-11-21T20:44:02.000Z","updated_at":"2015-10-13T16:33:54.000Z","dependencies_parsed_at":"2022-09-08T15:30:18.982Z","dependency_job_id":null,"html_url":"https://github.com/gimenete/emmental","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/gimenete/emmental","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gimenete%2Femmental","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gimenete%2Femmental/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gimenete%2Femmental/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gimenete%2Femmental/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gimenete","download_url":"https://codeload.github.com/gimenete/emmental/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gimenete%2Femmental/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262638400,"owners_count":23341289,"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-08T09:40:42.572Z","updated_at":"2025-06-29T17:35:04.187Z","avatar_url":"https://github.com/gimenete.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Goal\n\nEmmental is a simple server-side template engine with one goal in mind: to be able to use the same file as a mockup and as a template as well. Usually designers create HTML mockups and then developers copy those files to another directory and start to insert things like ${} \u003c?php?\u003e \u003c%=%\u003e,… breaking the HTML syntax, and making it impossible to be edited for a designer.\n\nThe idea of emmental is to create a template engine that doesn't break the HTML. So the designer can keep using their tools, and the file is always capable to be rendered by a web browser.\n\n# How?\n\nThe emmental purpose is to use non-standard HTML attributes that the web browser ignores but the template engine interprets.\n\n# Example\n\nFor example you have the following markup:\n\n\t\u003cp\u003eThere are 3 fruits in the basket:\u003c/p\u003e\n\n\t\u003cul\u003e\n\t\t\u003cli\u003efruit1\u003c/li\u003e\n\t\t\u003cli\u003efruit2\u003c/li\u003e\n\t\t\u003cli\u003efruit3\u003c/li\u003e\n\t\u003c/ul\u003e\n\nThis is dummy text. And now you would like to fill this HTML with real data (maybe fetched from a database or any other data source). For simplicity think that we have this data:\n\n    var fruits = ['apple', 'pear', 'banana', 'pineapple']\n\nWith emmental is easy to convert the previous mackup in a real template capable to be filled with data.\n\n## The simplest attribute: \"put\"\n\nUse \"put\" to change the text contained within an HTML element. For example:\n\n    \u003cp\u003eThere are \u003cspan put=\"fruits.length\"\u003e3\u003c/span\u003e fruits in the baket:\u003c/p\u003e\n\nAs you can see you can use any javascript expression in the \"put\" attribute.\n\n## Loops: \"loop\" and \"as\" attributes\n\nTo loop over a collection you will use the \"loop\" and \"as\" attributes. Example:\n\n\t\t\u003cul\u003e\n\t\t\t\u003cli loop=\"fruits\" as=\"fruit\"\u003efoo\u003c/li\u003e\n\t\t\t\u003cli\u003ebar\u003c/li\u003e\n\t\t\t\u003cli\u003ebaz\u003c/li\u003e\n\t\t\u003c/ul\u003e\n\nWith the \"loop\" attribute you define which collection will be iterated. With the \"as\" attribute you define the variable name to access each item in the collection while iterating.\n\nThe previous code will generate just four \\\u003cli\u003efoo\u003c/li\u003e elements which is not very useful. The complete example could be:\n\n\t\t\u003cul\u003e\n\t\t\t\u003cli loop=\"fruits\" as=\"fruit\" put=\"fruit\"\u003efoo\u003c/li\u003e\n\t\t\t\u003cli\u003ebar\u003c/li\u003e\n\t\t\t\u003cli\u003ebaz\u003c/li\u003e\n\t\t\u003c/ul\u003e\n\nNow you want to remove the last two \u003cli\u003e elements because they are dummy data. You can do the following\n\n\t\t\u003cul\u003e\n\t\t\t\u003cli loop=\"fruits\" as=\"fruit\" put=\"fruit\"\u003efoo\u003c/li\u003e\n\t\t\t\u003cli if=\"0\"\u003ebar\u003c/li\u003e\n\t\t\t\u003cli if=\"0\"\u003ebaz\u003c/li\u003e\n\t\t\u003c/ul\u003e\n\n## Conditional rendering\n\nYou can use the \"if\" attribute to do conditional rendering. The expression result is a falsy value then the element is removed. For example:\n\n    \u003cp if=\"fruits.length === 0\"\u003eThere are no fruits.\u003c/p\u003e\n\nThere is no \"else\" support and not is planned.\n\n## Attribute override\n\nYou can override attributes with \"put-*\". For example, if you have this markup:\n\n    \u003ca href=\"detail-mockup.html\"\u003emore info\u003c/a\u003e\n\nYou can override the href attribute with \"put-href\". Example:\n\n    \u003ca href=\"detail-mockup.html\" put-href=\"'/film/'+film.id\"\u003emore info\u003c/a\u003e\n\nAgain, you can use any javascript expression.\n\n# Usage\n\nUsage:\n\n\tvar emmental = require('emmental')\n\tvar html = fs.readFileSync('./example.html', 'utf8')\n\tvar out = emmental.processTemplate(html, data, function(err, out) {\n\t\tconsole.log(out) // \"out\" is a string with the HTML output\n\t})\n\nYou can find a complete example inside the \"examples\" folder in this repository.\n\n# LICENSE\n\n\tCopyright (c) 2011 Alberto Gimeno Brieba \u003cgimenete@gmail.com\u003e\n\t\n\tPermission is hereby granted, free of charge, to any\n\tperson obtaining a copy of this software and associated\n\tdocumentation files (the \"Software\"), to deal in the\n\tSoftware without restriction, including without limitation\n\tthe rights to use, copy, modify, merge, publish,\n\tdistribute, sublicense, and/or sell copies of the\n\tSoftware, and to permit persons to whom the Software is\n\tfurnished to do so, subject to the following conditions:\n\t\n\tThe above copyright notice and this permission notice\n\tshall be included in all copies or substantial portions of\n\tthe Software.\n\t\n\tTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n\tKIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n\tWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\n\tPURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n\tOR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n\tOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n\tOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n\tSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgimenete%2Femmental","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgimenete%2Femmental","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgimenete%2Femmental/lists"}