{"id":15314723,"url":"https://github.com/unframework/indentation","last_synced_at":"2025-10-22T15:23:21.310Z","repository":{"id":18279714,"uuid":"21445598","full_name":"unframework/indentation","owner":"unframework","description":null,"archived":true,"fork":false,"pushed_at":"2014-07-03T01:17:55.000Z","size":132,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-14T18:22:16.239Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unframework.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":"2014-07-03T01:13:58.000Z","updated_at":"2023-01-03T17:59:06.000Z","dependencies_parsed_at":"2022-08-28T08:41:16.468Z","dependency_job_id":null,"html_url":"https://github.com/unframework/indentation","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unframework%2Findentation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unframework%2Findentation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unframework%2Findentation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unframework%2Findentation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unframework","download_url":"https://codeload.github.com/unframework/indentation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219877247,"owners_count":16554912,"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-01T08:46:48.589Z","updated_at":"2025-10-09T00:32:43.154Z","avatar_url":"https://github.com/unframework.png","language":"JavaScript","readme":"\n# Indentation\n[![Build Status](https://travis-ci.org/unframework/indentation.svg?branch=master)](https://travis-ci.org/unframework/indentation)\n\n## DSL Implementation Helper\n\nCombine Unix style \"fork\" with JS prototypal inheritance to easily implement DSLs for templating.\n\nBoth Javascript and CoffeeScript are supported.\n\nTypical template (e.g. Mustache or anything else) can be considered as a *constructor* of a view-model instance. Each level of indentation - a sub-template - is then its own constructor of a sub-instance for a view-model. So in order to implement a template-like DSL, we need to allow syntactic sugar that allows both:\n\n* creating independent sub-instances that mostly don't share state with the current instance\n* providing similar environment as well as sharing *some* state with the sub-instance constructor\n\nWe achieve that with simple prototypal inheritance and syntactic sugar to \"fork\" (create a clean new object) a sub-instance.\n\nThis allows for libraries to work with the following template-like code:\n\n```js\nthis.element('bar', function () {\n    this.element('h1#sampleHeading', function () {\n        this.text(tmpl('Hello, world {{ app.itemList.length }}'));\n    });\n});\n\nthis.element('a', { href: '#' }, function () {\n    this.text('Add Item');\n\n    this.on('click', function () {\n        this.app.addItem();\n    }.bind(this));\n});\n```\n\n... although it looks much better in CoffeeScript:\n\n```coffee\n@when @eval('app.itemList.length'), -\u003e\n  @element 'h1#sampleHeading', -\u003e\n    @text @tmpl('Hello, world {{ app.itemList.length }}')\n\n  @element 'ul', -\u003e\n    @each @eval('app.itemList'), 'item', -\u003e\n      @element 'li', -\u003e\n        @text @tmpl('This is: {{ item.label }} eh')\n\n        testAction = ((label, cb) -\u003e setTimeout (-\u003e cb('Error processing action')), 500)\n        @form { action: testAction }, [ 'itemLabel' ], -\u003e\n          @when @eval('form.action.incomplete'), -\u003e\n            @text 'Loading...'\n\n          @when @eval('form.action.error'), -\u003e\n            @text @tmpl('{{ form.action.error }}')\n\n          @field 'itemLabel', -\u003e\n            @element 'label', -\u003e\n              @text 'Enter new item label'\n              @element 'input[type=text]', -\u003e\n                @fieldValue (=\u003e @value())\n\n          @element 'button[type=submit]', -\u003e @text 'Save'\n\n@element 'a', { href: '#' }, -\u003e\n  @text 'Add Item'\n  @on 'click', =\u003e @app.addItem()\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funframework%2Findentation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funframework%2Findentation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funframework%2Findentation/lists"}