{"name":"bracket-template","version":"1.0.0","description":"Javascript templates","repository":{"type":"git","url":"git+https://github.com/danlevan/bracket.git"},"main":"./dist/bracket.js","scripts":{"test":"eslint ./src/**/* ./tools/**/* ./tests/**/* && ./node_modules/.bin/babel-node ./tests/run.js && ./node_modules/.bin/babel-node ./tests/runBrowser.js","lint":"eslint ./src/**/* ./tools/**/* ./tests/**/*","start":"node examples/node/simple.js","build":"babel-node ./tools/build.js","prepublish":"babel-node ./tools/build.js"},"keywords":["template","javascript","node","frontend","backend"],"author":{"name":"Dan Le Van"},"license":"MIT","devDependencies":{"babel-cli":"^6.18.0","babel-core":"^6.18.2","babel-eslint":"^7.1.0","babel-loader":"^6.2.7","babel-plugin-transform-runtime":"^6.15.0","babel-preset-es2015":"^6.18.0","babel-preset-stage-0":"^6.16.0","eslint":"^3.9.1","eslint-config-airbnb":"^13.0.0","eslint-plugin-import":"^2.2.0","eslint-plugin-jsx-a11y":"^2.2.3","eslint-plugin-react":"^6.6.0","express":"^4.14.0","jasmine":"^2.5.2","json-loader":"^0.5.4","karma":"^1.3.0","karma-chrome-launcher":"^2.0.0","karma-jasmine":"^1.0.2","webpack":"^1.13.3"},"gitHead":"6690c9f0521c506f8b543c90f1645f0bd1126d1a","bugs":{"url":"https://github.com/danlevan/bracket/issues"},"homepage":"https://github.com/danlevan/bracket#readme","_id":"bracket-template@1.0.0","_shasum":"5fab9d8fb0269838d015207bc117b266973d22d8","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"danlevan","email":"danlevan@gmail.com"},"dist":{"shasum":"5fab9d8fb0269838d015207bc117b266973d22d8","tarball":"http://registry-npm.ywwl.com/bracket-template/download/bracket-template-1.0.0.tgz","integrity":"sha512-SX+CUCeysI1u8rlqHcz2pAIwNojyuZ+a/PgzA3fwFoiZgvNaSKpMGs2FbQRJZALsgw7z9uEqR6VztKRzNQTB6Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCftYm5vCjWOSk6wWZYjGhMJODU/FX1Kw7t5fPjOI3HJwIgeE081mYdgKcEAYgvXovafBAHMubvO0Ma0xJxGYUbRWg="}],"size":45609,"noattachment":false,"key":"/bracket-template/-/bracket-template-1.0.0.tgz"},"maintainers":[{"name":"danlevan","email":"danlevan@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/bracket-template-1.0.0.tgz_1479270516569_0.17501455242745578"},"directories":{},"readme":"# Braket-template\n\n[![GitHub version](https://badge.fury.io/gh/danlevan%2Fbracket-template.svg)](http://badge.fury.io/gh/danlevan%2Fbracket-template)\n[![npm version](https://badge.fury.io/js/bracket-template.svg)](http://badge.fury.io/js/bracket-template)\n\n> Minimal (über fast) Javascript engine compatible with node.js and browsers.\n\n## TL;DR\n\n- Javascript templating lib for node and modern browsers \n- Ultra fast, ultra small, ultra fast to learn \n- Uses `[[ ]]` by default (customizable), so plays well with `{{ }}` (Angular, Ember...)\n- Define and call your own block definition (functions) for reuse\n- Node: Parent layout and include files supported\n\n## Getting started\n\n`$ npm i bracket-template`\n\nor \n\n`$ yarn add bracket-template`\n\nor\n\nfork on [github](https://github.com/danlevan/bracket-template)\n\n## Express\n\nIf you want to use bracket with express, it's recommended to use [consolidate.js](https://www.npmjs.com/package/consolidate) as it makes is easy to change engine and implements a cache.\n\n[example](examples/node/consolidate)\n\n## Node (API)\n\nIf you want to use bracket in your node project for building your email templates for example, you can use it directly. (For Express, it's recommended to use [consolidate.js](https://www.npmjs.com/package/consolidate))\n\n[example](examples/node/simple)\n\n## Browser\n\nBracket works great with modern browsers. The tests are run on the latest chrome browser (more browser tests to come).\n\n[example](examples/browser)\n\n## Language definition\n\n### Javascript execution\n\n* Anything between `[[ ... ]]` is executed as javascript.\n* Anything bewteen `[[= ... ]]` is interpolated (i.e. print string values)\n\nFor example\n\n```\n[[ var test = 'wor'; ]]\nHello [[= test + '..ld' ]]\n```\n\n→ **Result** `Hello wor..ld`\n\n### Block definition\n\n* Block definition `[[## someFunc(someArg...) ... #]]`\n* Call blocks with `[[# someFunc(...) ]]`\n\nFor example\n\n```html\n<!-- Call block -->\nHello [[# block1('world') ]]\n\n<!-- Block definition -->\n[[## block1(arg1)\n  from block1 (with '[[= arg1 ]]')\n#]]\n```\n\n→ **Result** `Hello from block 1 (with 'world')`\n\n### Helper methods\n\nHelper methods can be passed during the compilation of the template. This is especially useful for passing a translation method for example.\n\nExample\n\n```javascript\nvar template = bracket.compile(\n  \"Hello world: [[# translate('Hello world') ]]\",\n  {\n    helpers: {\n      translate: function(text) {\n        return 'Bonjour le monde';\n      }\n    }\n  }\n);\ntemplate();\n```\n\n→ **Result** `Hello world: Bonjour le monde`\n\n## Extras for node\n\nWhen used in node, you can define a master layout and include partial files.\n\n### Layout \n\nLayout declarations are done in [yaml](http://yaml.org) at the beginning of the template file.\n\n**index.brkt.html**\n\n```html\n---\nmaster: master.brkt.html\ntitle: Index page\n---\n\n<!-- Define blocks used in master.brkt.html -->\n\n[[## body()\n  Hello from index.brkt.html\n#]]\n\n[[## body2()\n  Hello from index.brkt.html again\n#]]\n```\n\n**master.brkt.html**\n\n```html\n<!doctype html>\n<html lang=\"en\">\n  <head>\n    <title>[[= layout.title || 'default title' ]]</title>\n  </head>\n  <body>\n    Hello from master.brkt.html <br />\n    [[# body() ]] <br />\n    [[# body2() ]]\n  </body>\n</html>\n```\n\n→ **Result**\n\n```html\n<!doctype html>\n<html lang=\"en\">\n  <head>\n    <title>Index page</title>\n  </head>\n  <body>\n    Hello from master.brkt.html <br />\n    Hello from index.brkt.html <br />\n    Hello from index.brkt.html again\n  </body>\n</html>\n```\n\nThe master file specified can be\n- relative to the current file `../_layout/master.brkt.html`\n- relative to the views set in express `app.set('views', path.resolve(__dirname, 'views'));`\n\n**Pro tip**\n- Custom variables can be defined in the yaml (like title in the example) and used in the master.\n- Default values in this format `[[= layout.title || 'default title' ]]`\n\n### Partials\n\nYou can include another file in your template file.\n\n**index.brkt.html**\n\n```html\n<!doctype html>\n<html lang=\"en\">\n  <head>\n    <title>Example</title>\n  </head>\n  <body>\n    [[# partial('header.brkt.html', { current: 'contact' }) ]]\n  </body>\n</html>\n```\n\n**header.brkt.html**\n\n```html\n<nav>\n  <ul>\n    <li>Home</li>\n    <li>Contact</li>\n  </ul>\n</nav>\n```\n\n→ **Result**\n\n```html\n<!doctype html>\n<html lang=\"en\">\n  <head>\n    <title>Example</title>\n  </head>\n  <body>\n    <nav>\n      <ul>\n        <li>Home</li>\n        <li>Contact</li>\n      </ul>\n    </nav>\n  </body>\n</html>\n```\n\n## Customization\n\nYou can customize all the settings and regex used by bracket. \n\n**Default settings**\n\n```js\nconst settings = {\n  // Extract anything inside [[ ]] to be evaluated as js\n  evaluate: /\\[\\[([\\s\\S]+?(\\}?)+)]]/g,\n\n  // Extract anything in the form [[= model ]]\n  interpolate: /\\[\\[=([\\s\\S]+?)]]/g,\n\n  // Extract any block call [[# block1('arg') ]]\n  block: /\\[\\[#\\s*([\\w]+)\\(([\\s\\S]*?)\\)\\s*]]/g,\n\n  // Extract any block definition [[## block1(arg) #]]\n  blockDef: /\\[\\[##\\s*([\\w]+)\\(([\\s\\w,]*)\\)\\s*[\\n]([\\s\\S]*?)\\s*#]]/g,\n\n  // extract the argument values from a function call\n  // e.g. { test1: '123', test2: 456, test3: true }, 'aaa', true, {}, ''\n  argValues: /\\s*({[\\s\\S]*?}|[^,]+)/g,\n\n  // The params to pass to the template function\n  // For multiple params, comma delimited e.g. 'model,model2,model3...'\n  varname: 'model',\n};\n```\n\n**Pro tip** If you want to pass more than one model, change the varname to 'model, model2' and your template function will accept 2 models.\n","publish_time":1479270517130,"_cnpm_publish_time":1479270517130,"dist-tags":{"latest":"1.1.5"}}