{"_id":"tinytim","_rev":"306566","name":"tinytim","description":"Node.js port of tinytim (A tiny, secure JavaScript micro-templating script)","dist-tags":{"latest":"0.1.1"},"maintainers":[{"name":"baryon","email":"lilong@gmail.com"}],"time":{"modified":"2021-06-03T19:33:24.000Z","created":"2012-03-13T06:12:33.319Z","0.1.1":"2014-12-10T01:05:38.990Z","0.1.0":"2012-03-13T09:34:35.352Z","0.0.2":"2012-03-13T08:14:22.297Z","0.0.1":"2012-03-13T06:12:33.319Z"},"users":{},"author":{"name":"LI Long","email":"lilong@gmail.com"},"repository":{"type":"git","url":"https://github.com/baryon/node-tinytim"},"versions":{"0.1.1":{"name":"tinytim","description":"Node.js port of tinytim (A tiny, secure JavaScript micro-templating script)","homepage":"http://github.com/baryon/node-tinytim","repository":{"type":"git","url":"https://github.com/baryon/node-tinytim"},"version":"0.1.1","author":{"name":"LI Long","email":"lilong@gmail.com"},"license":"MIT","contributors":[{"name":"Premasagar Rose","email":"p@dharmafly.com"}],"dependencies":{},"devDependencies":{"mocha":"1.20.x"},"main":"./lib/index","keywords":["template","micro template","tim"],"scripts":{"test":"mocha test/*"},"engines":{"node":">= 0.2.0"},"bugs":{"url":"https://github.com/baryon/node-tinytim/issues"},"_id":"tinytim@0.1.1","dist":{"shasum":"c968a1e5559ad9553224ef7627bab34e3caef8a8","size":5256,"noattachment":false,"key":"/tinytim/-/tinytim-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/tinytim/download/tinytim-0.1.1.tgz"},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"baryon","email":"lilong@gmail.com"},"maintainers":[{"name":"baryon","email":"lilong@gmail.com"}],"directories":{},"publish_time":1418173538990,"_cnpm_publish_time":1418173538990,"_hasShrinkwrap":false},"0.1.0":{"name":"tinytim","description":"Node.js port of tinytim (A tiny, secure JavaScript micro-templating script)","homepage":"http://github.com/baryon/node-tinytim","version":"0.1.0","author":{"name":"LI Long","email":"lilong@gmail.com"},"contributors":[{"name":"Premasagar Rose","email":"p@dharmafly.com"}],"dependencies":{},"devDependencies":{"expresso":"0.9.2"},"main":"./lib/index","keywords":["template","micro template","tim"],"scripts":{"test":"expresso test/*"},"engines":{"node":">= 0.2.0"},"_npmUser":{"name":"baryon","email":"lilong@gmail.com"},"_id":"tinytim@0.1.0","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.0-2","_nodeVersion":"v0.6.8","_defaultsLoaded":true,"dist":{"shasum":"e52ecf9cd1d152063c7a8cddc0e3d1066ffa6386","size":5141,"noattachment":false,"key":"/tinytim/-/tinytim-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/tinytim/download/tinytim-0.1.0.tgz"},"maintainers":[{"name":"baryon","email":"lilong@gmail.com"}],"directories":{},"publish_time":1331631275352,"_cnpm_publish_time":1331631275352,"_hasShrinkwrap":false},"0.0.2":{"name":"tinytim","description":"Node.js port of tinytim (A tiny, secure JavaScript micro-templating script)","homepage":"http://github.com/baryon/node-tinytim","version":"0.0.2","author":{"name":"LI Long","email":"lilong@gmail.com"},"contributors":[{"name":"Premasagar Rose","email":"p@dharmafly.com"}],"dependencies":{},"devDependencies":{"expresso":"0.9.2"},"main":"./lib/tinytim","keywords":["template","micro template","tim"],"scripts":{"test":"expresso test/*"},"engines":{"node":">= 0.2.0"},"_npmUser":{"name":"baryon","email":"lilong@gmail.com"},"_id":"tinytim@0.0.2","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.0-2","_nodeVersion":"v0.6.8","_defaultsLoaded":true,"dist":{"shasum":"0618041402e6da428a4aa23eb10c41d73b55a11e","size":4345,"noattachment":false,"key":"/tinytim/-/tinytim-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/tinytim/download/tinytim-0.0.2.tgz"},"maintainers":[{"name":"baryon","email":"lilong@gmail.com"}],"directories":{},"publish_time":1331626462297,"_cnpm_publish_time":1331626462297,"_hasShrinkwrap":false},"0.0.1":{"name":"tinytim","description":"Node.js port of tinytim (A tiny, secure JavaScript micro-templating script)","homepage":"http://github.com/baryon/node-tinytim","version":"0.0.1","author":{"name":"LI Long","email":"lilong@gmail.com"},"contributors":[{"name":"Premasagar Rose","email":"p@dharmafly.com"}],"dependencies":{},"devDependencies":{"expresso":"0.9.2"},"main":"./lib/tinytim","keywords":["template","micro template","tim"],"scripts":{"test":"expresso test/*"},"engines":{"node":">= 0.2.0"},"_npmUser":{"name":"baryon","email":"lilong@gmail.com"},"_id":"tinytim@0.0.1","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.0-2","_nodeVersion":"v0.6.8","_defaultsLoaded":true,"dist":{"shasum":"f3d796739f6677f2b040d9f606e0bcd1e5bda13a","size":4132,"noattachment":false,"key":"/tinytim/-/tinytim-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/tinytim/download/tinytim-0.0.1.tgz"},"maintainers":[{"name":"baryon","email":"lilong@gmail.com"}],"directories":{},"publish_time":1331619153319,"_cnpm_publish_time":1331619153319,"_hasShrinkwrap":false}},"readme":"#tinytim for node.js  [![Build Status](https://secure.travis-ci.org/baryon/node-tinytim.png)](http://travis-ci.org/baryon/node-tinytim)\n\nNode.js port of [tinytim](https://github.com/premasagar/tim/) (A tiny, secure JavaScript micro-templating script)\n\n\n##Install\n-----\n```javascript\nnpm install tinytim\n```\n\nUsage\n-----\nAdd to your code:\n\n```javascript\n\tvar tim = require('tinytim').tim;\n\tvar result = tim(\"Hello {{place}}\", {place: \"world\"});\n\tconsole.log(result); // Hello world\n```\n\nSee [test/tim-replace.js](https://github.com/baryon/node-tinytim/blob/master/test/tim-replace.js) as example\n\nand support render and renderFile methods.  \nSee [test/render-replace.js](https://github.com/baryon/node-tinytim/blob/master/test/render-replace.js) and [test/render-file-replace.js](https://github.com/baryon/node-tinytim/blob/master/test/render-file-replace.js)  for details.\n\n```javascript\n\tvar tinytim = require('tinytim');\n\tvar result = tinytim.render(\"Hello {{place}}\", {place: \"world\"});\n\tconsole.log(result); // Hello world\n```\n\n```javascript\n\tvar tinytim = require('tinytim');\n\tvar result1 = tinytim.renderFile(\"./hello.tim\", {place: \"world\"}); \n\tconsole.log(result1); // Hello world\n\n\tvar result2 = tinytim.renderFile(\"./hello.tim\", {place: \"world\"}, true); //use cache to render \n\tconsole.log(result2); // Hello world\n```\n\n\n# Tim\n\nA tiny, secure JavaScript micro-templating script.\n\nTim lets you write simple templates that uses JavaScript's familiar dot notation. You pass in a JavaScript object that contains all the relevant strings, and they are then substituted into the template. For example:\n\n    tim(\"Hello {{place}}\", {place: \"world\"});\n    // \"Hello world\"\n\n* by [Premasagar Rose](http://premasagar.com) \n    ([Dharmafly](http://dharmafly.com))\n* source: [github.com/premasagar/tim](http://github.com/premasagar/tim) ([MIT license](http://opensource.org/licenses/mit-license.php))\n* ~200 bytes minified & gzipped\n\n\n## Why is micro-templating useful?\nDon't you just hate having to write HTML with a mess of string concatenation that clutters up your JavaScript?:\n\n    var myHTML = \"<ul class='\" + myClass + \"'>\" +\n        \"<li id='\" + theId + \"'>\" + liContents + \"</li>\" +\n        // etc, etc, etc\n        \nYuck. There's no need to do this. Simply prepare a JavaScript object with the required properties, and inject it into a simple template string. The templates can all be tidily kept together with the rest of the markup in an HTML document (see below).\n\n\n## How is Tim different from other templating scripts?\nIt is safe and secure: it doesn't use eval or (new Function), so it cannot execute malicious code. As such, it can be used in secure widgets and apps that disallow eval - e.g. Adobe Air sandboxes, AdSafe ads, etc.\n\nIt doesn't include a whole bloat load of features that are unlikely to get used when you just want to get some simple templating up and running.\n\nIt comes in two versions: \"tinytim.js\" (<200kb), and \"standard\", which has advanced functionality and allows extensibility with plugins.\n\nIt's easy to debug.\n\nFor these reasons, it is now in use in Sqwidget, the JavaScript widget library: [github.com/premasagar/sqwidget](http://github.com/premasagar/sqwidget)\n\n\n## Tim & tinytim.js: Core Functionality\nThere are two versions of Tim: the \"standard\" (full) version, and a stripped down \"tinytim.js\" version.  The core functionality of both versions is identical, and is described below.  \n\n\nTim can be used to replace tokens within a text string with specified data.\n\nFor example: \n\n    var template = \"Hello {{place}}. My name is {{person.name}}.\",\n        data = {\n            place: \"Brighton\",\n            person: {\n                name: \"Prem\"\n            }\n        };\n        \n    tim(template, data);\n    // \"Hello Brighton. My name is Prem.\"\n\n\nIn addition to plain and simple text, you can use Tim to populate HTML or other types of template.\n\nFor example:\n\n    var template = \"<p><a href='{{url}}'>{{title}}</a></p>\",\n        data = {\n            title: \"Dharmafly\",\n            url:   \"http://dharmafly.com\"\n        };\n        \n    tim(myTemplate, data);\n    // \"<p><a href='http://dharmafly.com'>Dharmafly</a></p>\"\n    \n...and so on, all the way up to a full-blown HTML document.\n\n\n### Nested templates\nSometimes, you will want to reuse the same template multiple times in a loop, and then wrapped within a bigger template - e.g. when creating an HTML `<ul>` list tag.\n\nThis is easily achieved:\n\n    var ul = \"<ul>{{list}}</ul>\",\n        li = \"<li>{{contents}}</li>\",\n        myList = \"\",\n        i;\n        \n    for (i=100; i<103; i++){\n        myList += tim(li, {contents: i});\n    }\n    tim(ul, {list: myList});\n    // \"<ul><li>100</li><li>101</li><li>102</li></ul>\"\n        \n\n### Debugging\nIf your template references a path in the data object that could not actually be found, then Tim will throw an error, to help with debugging:\n\n    tim(\"Hello {{config.foo.bar}}\", {config: {moo: \"blah\"}});\n    // tim: 'foo' not found in {{config.foo.bar}}\n\n\n### Using arrays\nThe data can be, or can include, an array. Use dot notation to access the array elements.\n\ne.g:\n\n    tim(\"Hello {{0}}\", [\"world\"]);\n    // \"Hello world\"\n    \nor:\n\n    tim(\"Hello {{places.0}}\", {places: [\"world\"]});\n    // \"Hello world\"\n    \nFurther examples are discussed in the section \"iterating through arrays\" below.\n\n\n### Changing the {{curly braces}} delimiter\nBy default, template tags are delimited by \"`{{`\" and \"`}}`\" tokens.\nTo change this, edit the `start` and `end` vars in the code.\n*** this will affect all module use tinytim, because node.js cache this package.\n\n```javascript\n\tvar tinytim = require('tinytim');\n\ttinytim.start = \"<%\";\n\ttinytim.end = \"%>\";\n\tvar result = tinytim.tim(\"Hello <%place%>\", {place: \"world\"});\n\tconsole.log(result); // Hello world\n```\n\n# mustache.js and Handlebars.js\ntinytim is very simple, if you need a more powerful template library, see [mustache.js](http://mustache.github.com/) and [Handlebars.js](https://github.com/wycats/handlebars.js/)\n\n\n## History\n\n### 0.1.0\n\n* support render and renderFile methods.  \n\n### 0.0.2\n\n* throw an new Error when not found.  \n\n### 0.0.1\n\n* Initial port.  \n\n## License \n\n(The MIT License)\n\nCopyright (c) Premasagar Rose  &lt;p@dharmafly.com&gt;\n\nCopyright (c) 2012 LI Long  &lt;lilong@gmail.com&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","_attachments":{},"homepage":"http://github.com/baryon/node-tinytim","bugs":{"url":"https://github.com/baryon/node-tinytim/issues"},"license":"MIT"}