{"id":19837415,"url":"https://github.com/mdvanes/grunt-kot2js","last_synced_at":"2025-07-09T18:32:21.374Z","repository":{"id":29250968,"uuid":"32783306","full_name":"mdvanes/grunt-kot2js","owner":"mdvanes","description":"Grunt task to convert Knockout templates to a string in a JavaScript file for the String Template Engine.","archived":false,"fork":false,"pushed_at":"2022-09-20T06:33:15.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-03T23:40:27.890Z","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/mdvanes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-24T07:46:53.000Z","updated_at":"2022-09-20T06:33:20.000Z","dependencies_parsed_at":"2022-08-31T08:21:15.393Z","dependency_job_id":null,"html_url":"https://github.com/mdvanes/grunt-kot2js","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/mdvanes/grunt-kot2js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdvanes%2Fgrunt-kot2js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdvanes%2Fgrunt-kot2js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdvanes%2Fgrunt-kot2js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdvanes%2Fgrunt-kot2js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdvanes","download_url":"https://codeload.github.com/mdvanes/grunt-kot2js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdvanes%2Fgrunt-kot2js/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260586146,"owners_count":23032253,"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-12T12:14:21.402Z","updated_at":"2025-07-09T18:32:21.322Z","avatar_url":"https://github.com/mdvanes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build Status](https://travis-ci.org/mdvanes/grunt-kot2js.svg?branch=master) [![npm version](https://badge.fury.io/js/grunt-kot2js.svg)](https://badge.fury.io/js/grunt-kot2js)\n\n# grunt-kot2js\n\n\u003e Grunt task to convert Knockout templates to a string in a JavaScript file for the String Template Engine.\n\nBased on [https://blog.safaribooksonline.com/2014/01/31/using-external-templates-knockout-js/ and https://github.com/rniemeyer/SamplePresentation/blob/master/js/stringTemplateEngine.js](https://blog.safaribooksonline.com/2014/01/31/using-external-templates-knockout-js/ and https://github.com/rniemeyer/SamplePresentation/blob/master/js/stringTemplateEngine.js)\n\nA version of the String Template Engine is included. It's located in `grunt-kot2js/lib/stringTemplateEngine.js`.\n\nUsage of the stringTemplateEngine:\n\n```js\nfunction DebugViewModel() {\n    this.testValues = {foo: 'bar'};\n}\nstringTemplateEngine.init(koTemplates);\nko.applyBindings(new DebugViewModel(), $('#wrapper')); // Where \u003cdiv id=\"wrapper\" data-bind=\"template: { name: 'TemplateA' }\"\u003e\u003c/div\u003e\n```\n\nSee also [grunt-kot2html](https://github.com/mdvanes/grunt-kot2html).\n\n## Getting Started\nThis plugin requires Grunt `~0.4.5`\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install grunt-kot2js --save-dev\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-kot2js');\n```\n\nAlthough I recommend using [load-grunt-tasks](https://www.npmjs.com/package/load-grunt-tasks)\n\n## The \"kot2js\" task\n\n### Overview\nIn your project's Gruntfile, add a section named `kot2js` to the data object passed into `grunt.initConfig()`.\n\n```js\ngrunt.initConfig({\n    kot2js: {\n        dev: {\n            src: 'templates/*.html',\n            dest: 'templates.js',\n            namespace: 'foo'\n        }\n    }\n});\n```\n\nExample output:\n\n```js\n(function () {\n    'use strict';\n    window.koTemplates = {};\n    window.koTemplates[\"main\"] = \"\u003cdiv class=\\x22rdt\\x22 id=\\x22rdt\\x22\u003e\u003c/div\u003e\";\n})();\n```\n\nThe path to the template is used as a template ID (in this case \"main\").\n\n### Properties\n\n#### src\nType: `String`\n\nInput path. Location of the HTML Knockout Templates. Expects template files to have the .html extension\n\n#### dest\nType: `String`\n\nOutput path. Location of the generated JavaScript file.\n\n#### namespace\nType: `String`\nDefault value: `'window.koTemplates'`\n\nOptional. The variable to which the string array will be assigned. This has to be a global variable.\n\n### Usage Examples\n\n#### Default Options\nIn this example, the sources are files with the .html extension in the `templates` dir and the generated file is `templates.js` in the root dir. The namespace is the default `window.koTemplates`.\n\n```js\ngrunt.initConfig({\n    kot2js: {\n        dev: {\n            src: 'templates/*.html',\n            dest: 'templates.js'\n        }\n    }\n});\n```\n\n## Contributing\nFollow the jshintrc settings for the code style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Release History\n\n* 2016-07-07    v0.5.0     merged pull request for paths as template ID.\n* 2015-11-03    v0.4.2     merged pull request for namespaces\n* 2015-03-25    v0.4.0     added lib/stringTemplateEngine.js\n* 2015-03-25    v0.3.0     added unit tests\n* 2015-03-24    v0.2.0     input, output and namespace configurable\n* 2015-03-24    v0.1.0     initial release\n\n## To Do\n\n* When committing got: warning: LF will be replaced by CRLF in test/expected/dev. This means that the unit test will fail.\n* Add lintspaces\n* Add unit test for stringTemplateEngine","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdvanes%2Fgrunt-kot2js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdvanes%2Fgrunt-kot2js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdvanes%2Fgrunt-kot2js/lists"}