{"_id":"codie","_rev":"5-4f728e159264c8b8194aee745eb25fe8","name":"codie","description":"JavaScript template engine specialized in generating JavaScript code","dist-tags":{"latest":"1.1.0"},"versions":{"0.9.0":{"name":"codie","version":"0.9.0","description":"JavaScript template engine specialized in generating JavaScript code","homepage":"http://github.com/dmajda/codie","author":{"name":"David Majda","email":"david@majda.cz","url":"http://majda.cz/"},"files":["CHANGELOG","README.md","VERSION","lib/codie.js"],"main":"lib/codie","repository":{"type":"git","url":"git://github.com/dmajda/codie.git"},"devDependencies":{"jake":">= 0.1.14","jshint":">= 0.3.1"},"engines":{"node":">= 0.4.11"},"_npmJsonOpts":{"file":"/home/dmajda/.npm/codie/0.9.0/package/package.json","wscript":false,"contributors":false,"serverjs":false},"_id":"codie@0.9.0","dependencies":{},"_engineSupported":true,"_npmVersion":"1.0.27","_nodeVersion":"v0.4.11","_defaultsLoaded":true,"dist":{"shasum":"1c743bcb1c34f68d76f0b8d0cd5de0602213385a","tarball":"https://registry.npmjs.org/codie/-/codie-0.9.0.tgz","integrity":"sha512-MIrlihOguZ1HQtmMgQvGyDgigTP84jK6ii5wtMpn5tb+ew1wKGmrPVnvywKSCzFg8x420Qe4oZz7jlV2Z2jyRQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE7rcZJzbLbJYZrSlY6LOlV9pFb8T451WYniie24h4r6AiBeCIuksO4DcjTqPJcgYd/ID3nNe1U20OXS1CcXLrOgfw=="}]},"maintainers":[{"name":"dmajda","email":"david@majda.cz"}],"directories":{}},"1.0.0":{"name":"codie","version":"1.0.0","description":"JavaScript template engine specialized in generating JavaScript code","homepage":"http://github.com/dmajda/codie","author":{"name":"David Majda","email":"david@majda.cz","url":"http://majda.cz/"},"main":"lib/codie","repository":{"type":"git","url":"git://github.com/dmajda/codie.git"},"devDependencies":{"jshint":">= 0.5.5"},"engines":{"node":">= 0.6.6"},"_npmUser":{"name":"dmajda","email":"david@majda.cz"},"_id":"codie@1.0.0","dependencies":{},"_engineSupported":true,"_npmVersion":"1.1.0-beta-7","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"6fc3b668d72730748fb9802d8bddf1d0105aada1","tarball":"https://registry.npmjs.org/codie/-/codie-1.0.0.tgz","integrity":"sha512-SjJyHIluWzU1gnVicR9zRLTe0wOnnTFoPkVn8L+e1g98gK3p9dRyNQsbpoWyiZoNPRWzZWQv1m1jPuhulBhIRA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBOXcKRM5uNbRi9cjQV11jRby918ywG+LAndoP9OQGEdAiEAwkpam3Fk+yCPH7vrKj0QAvyh/zGYvg5lUNcICP5xtls="}]},"maintainers":[{"name":"dmajda","email":"david@majda.cz"}]},"1.0.1":{"name":"codie","version":"1.0.1","description":"JavaScript template engine specialized in generating JavaScript code","homepage":"http://github.com/dmajda/codie","author":{"name":"David Majda","email":"david@majda.cz","url":"http://majda.cz/"},"main":"lib/codie","repository":{"type":"git","url":"git://github.com/dmajda/codie.git"},"devDependencies":{"jshint":">= 0.5.5"},"engines":{"node":">= 0.6.6"},"_npmUser":{"name":"dmajda","email":"david@majda.cz"},"_id":"codie@1.0.1","dependencies":{},"_engineSupported":true,"_npmVersion":"1.1.0-beta-7","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"7d1a054b5b9355429e34cbca6f8b818c52282d53","tarball":"https://registry.npmjs.org/codie/-/codie-1.0.1.tgz","integrity":"sha512-suvUGFbJVu1XS65bqCKeLe3Nxf/9nr0f3ZfFDd0EdbtArnyvUgDitBU9i2kuOL2W7ElIlVZ75gHNhgGk/h04ww==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDgIDtgv1OoJFro+3Go/9OkBkTn0gCTvGkCceMpgjWWhgIhAM/7288hvHmFAm9UmUYHMLuhZ8rrk3JNJXSwEBKFQo0t"}]},"maintainers":[{"name":"dmajda","email":"david@majda.cz"}]},"1.1.0":{"name":"codie","version":"1.1.0","description":"JavaScript template engine specialized in generating JavaScript code","homepage":"http://github.com/dmajda/codie","author":{"name":"David Majda","email":"david@majda.cz","url":"http://majda.cz/"},"main":"lib/codie","repository":{"type":"git","url":"git://github.com/dmajda/codie.git"},"devDependencies":{"jshint":">= 0.5.5"},"engines":{"node":">= 0.6.6"},"_npmUser":{"name":"dmajda","email":"david@majda.cz"},"_id":"codie@1.1.0","dependencies":{},"_engineSupported":true,"_npmVersion":"1.1.0-beta-7","_nodeVersion":"v0.6.6","_defaultsLoaded":true,"dist":{"shasum":"626585c6f8535f89fad9c022da19ad077e92155c","tarball":"https://registry.npmjs.org/codie/-/codie-1.1.0.tgz","integrity":"sha512-fG3u+j3yk9FnUevWqsUALKjDoPC57IPLaH+/6Mv4sHUIYn4CY5E7pCdq8DOQ1mR0CJU6sSeOlidOY4wlwPxFSA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDDrS+RRUrp/bgURKpf1slBSbpsJlT9BrNXmL4rbEl71wIhAJgIvXQafUtNyi28W0fhOHx5KNN+vl2RwuRJhfJIsl1t"}]},"maintainers":[{"name":"dmajda","email":"david@majda.cz"}]}},"maintainers":[{"name":"dmajda","email":"david@majda.cz"}],"time":{"modified":"2022-06-13T06:27:04.356Z","created":"2011-09-29T13:57:12.321Z","0.9.0":"2011-09-29T13:57:13.818Z","1.0.0":"2011-12-30T13:06:45.616Z","1.0.1":"2012-01-09T18:50:46.965Z","1.1.0":"2012-04-16T09:56:06.592Z"},"author":{"name":"David Majda","email":"david@majda.cz","url":"http://majda.cz/"},"repository":{"type":"git","url":"git://github.com/dmajda/codie.git"},"readme":"Codie\n=====\n\nCodie is a simple JavaScript template engine specialized in generating code. Unlike other engines it really cares about newlines and indentation, allowing both the template and the generated code to be readable at the same time. You can use Codie to write tools such as compilers, template engines, various kinds of preprocessors or transformers — anything that produces more than a few lines of JavaScript.\n\nExample\n-------\n\nCodie template looks like this:\n\n    #for i in list\n      alert(\"Processing #{i}.\");\n      #if i % 2 == 0\n        alert(\"#{i} is even.\");\n      #else\n        alert(\"#{i} is odd.\");\n      #end\n    #end\n\nWith `{ list: [1, 2, 3] }` as data, this template produces:\n\n    alert(\"Processing 1.\");\n    alert(\"1 is odd.\");\n    alert(\"Processing 2.\");\n    alert(\"2 is even.\");\n    alert(\"Processing 3.\");\n    alert(\"3 is odd.\");\n\nNote that all `alert` calls are on the same indentation level (unlike in the template) because all indentation related to the #-commands is stripped.\n\nInstallation\n------------\n\n### Node.js\n\n    $ npm install codie\n\nDo not install Codie globally (using the `-g` option), otherwise you won’t be able to use the API.\n\n### Browser\n\nDownload the `lib/codie.js` file.\n\nUsage\n-----\n\nIn Node.js, require the Codie module:\n\n    var Codie = require(\"codie\");\n\nIn browser, include the Codie library in your web page or application using the `<script>` tag. Codie will be available in the `Codie` global object.\n\nUsing a template is a two-step process. First you need to compile the template text into a template function. Then you need to call this function with data to be filled into the template. Compiling saves time when you use the same template multiple times.\n\nTo compile a template, call the `Codie.template` method and pass the template text as a parameter. The method will return a template function or throw an exception if the template text is invalid:\n\n    var template = Codie.template('var #{name} = #{value};');\n\nTo fill the template, call the template function and pass an object with data. It’s properties will be available as variables in the template. The template function will return the filled template:\n\n    template({ name: \"result\", value: 42}); // Returns \"var result = 42;\".\n\nTo fill the template with different values, just call the template function again with a different data.\n\nTemplate Syntax\n---------------\n\nThe template is a string with embedded *expressions* and *commands*. Any text which is not an expression nor a command is just copied verbatim to the output.\n\n### Expressions\n\nExpressions are just regular JavaScript expressions wrapped into `#{` and `}`. They are evaluated and the result is emitted to the output.\n\n### Commands\n\nCommands start with a `#` character at the beginning of a line, prefixed only by optional whitespace, and followed by the command name and parameters (if any) separated by whitespace.\n\nThe following commands are available:\n\n#### #for / #end\n\nEmits code in its body repeatedly, assigning values from an array to the loop variable sequentially.\n\n    #for i in list\n      #{i}\n    #end\n\nWith `{ list: [1, 2, 3] }` as data, this template produces:\n\n    1\n    2\n    3\n\nAll lines in the loop body are unindented by `Codie.indentStep` characters in the output. This is necessary to allow  indentation to be used in the template and to make it disappear in the generated output.\n\n#### #if / #else / #end\n\nEmits code in one of its branches depending on the condition.\n\n    #if i % 2 == 0\n      alert(\"#{i} is even.\");\n    #else\n      alert(\"#{i} is odd.\");\n    #end\n\nWith `{ i: 42 }` as data, this template produces:\n\n    alert(\"42 is even.\");\n\nAll lines in the loop body are unindented by `Codie.indentStep` characters in the output. This is necessary to allow  indentation to be used in the template and to make it disappear in the generated output.\n\nThe `#else` branch is optional.\n\n#### #block\n\nEvaluates its parameter, converts it to a string using the `toString` method, indents the result to the same level as the `#block` command and emits the result.\n\n    function foo() {\n      #block body\n    }\n\nWith `{ body: \"bar();\\nbaz();\" }` as data, this template produces:\n\n    function foo() {\n      bar();\n      baz();\n    }\n\nThis command is useful mainly to combine parts of the generated output together.\n\n### More information\n\nFor more details about the syntax see the source code.\n\nCustomization\n-------------\n\nUnindenting inside `#if` and `#for` commands removes `Codie.indentStep` characters from the beginning of lines. This property is set to `2` by default. You can modify it to use a different indentation level. Note that Codie does not care whether you use tabs or spaces for indentation.\n\nExtension\n---------\n\nCodie is designed to be extensible, so it’s easy to add new commands. All commands are described by descriptors stored in properties of the `Codie.commands` object. To add a new command, just add its descriptor there. See the implementation of other commands and the `compileCommand` function to get an idea how commands work.\n\nFAQ\n---\n\n### Why did you choose \"#\" as a command and expression delimiter?\n\nI experimented with various means of delimiting. After a while I settled on line-oriented syntax with one-character delimiter. At that point, the \"#\" character won because it is easily recognizable, it’s not used in JavaScript, and commands prefixed by it resemble C preprocessor.\n\nThe only downside is that it is also used for interpolation in CoffeeScript. Should this be a problem, I’ll make the delimiter configurable.\n\nCompatibility\n-------------\n\nCodie should run well in the following environments:\n\n  * Node.js 0.6.6+\n  * IE 8+\n  * Firefox\n  * Chrome\n  * Safari\n  * Opera\n\nDevelopment\n-----------\n\nCodie is developed by [David Majda](http://majda.cz/) ([@dmajda](http://twitter.com/dmajda)). You are welcome to contribute code. Unless your contribution is really trivial you should get in touch with me first — this can prevent wasted effort on both sides. You can send code both as a patch or a GitHub pull request.\n","readmeFilename":""}