{"id":20963851,"url":"https://github.com/codemix/htmling","last_synced_at":"2025-04-06T09:07:30.256Z","repository":{"id":17955982,"uuid":"20942507","full_name":"codemix/htmling","owner":"codemix","description":"Polymer / HTML5 templating syntax for node.js","archived":false,"fork":false,"pushed_at":"2020-10-17T14:03:18.000Z","size":221,"stargazers_count":177,"open_issues_count":14,"forks_count":32,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-30T08:09:23.383Z","etag":null,"topics":[],"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/codemix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-17T23:12:07.000Z","updated_at":"2025-03-28T13:54:34.000Z","dependencies_parsed_at":"2022-09-24T20:12:45.219Z","dependency_job_id":null,"html_url":"https://github.com/codemix/htmling","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/codemix%2Fhtmling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2Fhtmling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2Fhtmling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemix%2Fhtmling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemix","download_url":"https://codeload.github.com/codemix/htmling/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457800,"owners_count":20941906,"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-11-19T02:48:37.048Z","updated_at":"2025-04-06T09:07:30.236Z","avatar_url":"https://github.com/codemix.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTMLing\n\n[![Build Status](https://travis-ci.org/codemix/htmling.svg?branch=master)](https://travis-ci.org/codemix/htmling)\n\n[Polymer](http://polymer-project.org/) compatible HTML5 based templating syntax for node.js.\nRender your templates server-side using the same syntax as in the browser, with no virtual DOM trickery required.\n\nFor a full demonstration, please see [htmling-demo-app](https://github.com/codemix/htmling-demo-app).\n\n## Installation\n\nvia [npm](https://npmjs.org/package/htmling)\n\n```\nnpm install htmling\n```\n\n## Example\n\nTurns this:\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003e{{title}}\u003c/title\u003e\n    \u003cmeta name=\"description\" content=\"{{description}}\"\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003e{{title}}\u003c/h1\u003e\n    \u003cul\u003e\n    \u003ctemplate repeat=\"{{user in users}}\"\u003e\n      \u003cli\u003e{{user.name}}\u003c/li\u003e\n    \u003c/template\u003e\n    \u003c/ul\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nplus this:\n\n```json\n{\n  \"title\": \"User List\",\n  \"description\": \"A list of users\",\n  \"users\": [\n    {\n      \"name\": \"Alice\"\n    },\n    {\n      \"name\": \"George\"\n    }\n  ]\n}\n```\n\ninto this:\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eUser List\u003c/title\u003e\n    \u003cmeta name=\"description\" content=\"A list of users\"\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003ch1\u003eUser List\u003c/h1\u003e\n    \u003cul\u003e\n      \u003cli\u003eAlice\u003c/li\u003e\n      \u003cli\u003eGeorge\u003c/li\u003e\n    \u003c/ul\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n\n\n## How it works\n\nUnlike similar libraries, HTMLing does not require a virtual DOM such as jsDOM. Instead, HTMLing\nparses `.html` files and transforms them into very efficient executable JavaScript functions.\nIt uses a [parser](./src/parser.pegjs) written in [PEG.js](https://github.com/dmajda/pegjs) which emits a standard [Mozilla Parser API](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Parser_API) [AST](http://en.wikipedia.org/wiki/Abstract_syntax_tree) with some custom node types. The [compiler](./lib/compiler.js) then uses [estraverse](https://github.com/Constellation/estraverse) to convert these custom node types to standard JavaScript expressions. Finally, the result is passed to [escodegen](https://github.com/Constellation/escodegen) which converts the AST into executable JavaScript.\n\nThis compilation process happens only once, and the resulting JavaScript is extremely efficient.\n\n\n## Usage\n\nHTMLing is easy to integrate with your existing build process, either via the command line or library interfaces.\n\n## CLI\n\nHTMLing ships with a small command line interface:\n\n### Compile an individual file\nThe compiled output will be written to STDOUT\n\n```\nhtmling ./file.html\n```\n\n\n### Compile an individual file to a destination\nThe compiled output will be written to `compiled.js`.\n\n```\nhtmling -o ./compiled.js ./file.html\n```\n\n### Compile a directory hierarchy\nCompile a nested directory structure to a directory called `compiled`. The output\ndirectory will be created if it does not already exist, and the resulting folder structure will\nmatch that of the input.\n\n```\nhtmling -o ./compiled ./pages\n```\n\n### Compile a directory hierarchy to a single file\nCompile a nested directory structure to a single called `compiled.js`\n\n```\nhtmling -c -o ./compiled.js ./pages\n```\n\n\n## As a Library\n\nIt's also possible to use HTMLing as a library:\n\n### Compile a string\n\n```js\nvar HTMLing = require('htmling');\n\nvar template = HTMLing.string('Hello {{name}}');\n\nconsole.log(template.render({name: 'Charles'})); // \"Hello Charles\"\n```\n\n### Compile a file\n\n```js\nvar template = HTMLing.file('./index.html');\nconsole.log(template.render());\n```\n\n### Compile a directory\n\n```js\nvar templates = HTMLing.dir('./pages');\nconsole.log(templates.render('index.html', {}))\n```\n\n### Using as an express view engine\n\nHTMLing has support for [express.js](http://expressjs.com/).\n\n```js\nvar HTMLing = require('htmling');\napp.configure(function(){\n  app.engine('html', HTMLing.express(__dirname + '/views/'));\n  app.set('view engine', 'html');\n});\n```\n\nIn development mode, you'll probably want to enable the `watch` option. This will reload your\ntemplates when they change on disk:\n\n```js\nvar HTMLing = require('htmling');\napp.configure(function(){\n  app.engine('html', HTMLing.express(__dirname + '/views/', {watch: true}));\n  app.set('view engine', 'html');\n});\n```\n\n## License\n\nMIT, see [LICENSE.md](./LICENSE.md).\n\n## Docker environment\n\nAll you need is [Docker](https://www.docker.com/) with `docker-compose` available from your terminal.\n\n\nWe have a fancy shortcut to get your application up and running, and you also get access to the container terminal:\n\n```console\n$ make build\n$ make run\n```\n\nFrom this point, it's just a matter of starting the application from within the container shell:\n\n```console\nhtmling:~/app(master)$ npm test\n```\n\n#### Other fancy shortcuts we have for Docker fans\n\n* `$ make in` to open a new container terminal\n* `$ make stop` to stop all containers\n* `$ make clean` to clean the Docker environment\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemix%2Fhtmling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemix%2Fhtmling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemix%2Fhtmling/lists"}