{"bin":{"generate":"./bin/generate"},"bugs":{"url":"https://github.com/rpflorence/loom/issues"},"dist":{"shasum":"3405c6ad3371a5da72639a5d345af3b1c0c6563a","tarball":"https://registry.npmjs.org/loom/-/loom-2.0.0.tgz","integrity":"sha512-J3Pmct8pTfHa8EBVVWDcUWeciWzBV4hptxSaX1ZbIO/I6TBZQ1dJGtrsJRjZ56esZ7nx+TyI4dCO9xuJ5Sbtgg==","signatures":[{"sig":"MEUCID/DtezhJ9W0Kl/t/p00Xa8GI8dDIRWb2YSeUonZQi8kAiEA2luBF6BzXVCPEGG/uBfJGspHMpZzW6O9sbqm9IyHq10=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}]},"main":"loom.js","name":"loom","_from":".","author":{"name":"Ryan Florence"},"readme":"Loom\n====\n\nWeave your wefts betwixt the warps of loom generators and scaffolds.\n\n![wefts and warps](http://ryanflorence.com/gifs/warp-weft.gif)\n\n**Loom makes it easy to share best-practices and common patterns for app\ndevelopment.**\n\n- build a set of generators for public consumption based on some\n  framework or library (like ember, angular, backbone, etc.)\n- consume those sets of generators\n- override those generators\n- build your own generators for your specific app\n\nUsing Loom Generator Packages from NPM\n--------------------------------------\n\nUsing generator packages from npm is easy:\n\n```sh\nnpm install loom-generators-ember --save\ngenerate model user name:string age:number\n```\n\nThen refer to the documentation for the generators you've installed.\n\nYou must install with `--save` or add the module to your package.json\ninstead (that's how loom knows how to use them).\n\nCreating Your Own Generators\n----------------------------\n\nAlso, see [the full generator API below](#generator-api)\n\nWhile using generators others have created for you is great, its awesome\nto have a simple way to make generators for our own apps. Even if you're\nusing a set of generators from npm, defining your own generators will\noverride them.\n\n### Installation\n\n```sh\nnpm install loom -g\ngenerate --init\n```\n\n### Templates\n\nInitializing loom simply creates some directories in your project. After\nthat, all you need is a template in `./loom/templates/`:\n\nLets say we have a lot of \"meal\" objects in our app, lets make a\ntemplate for what one of these objects looks like:\n\n_loom/templates/app/meal.js.hbs_\n\n```mustache\nfunction {{objectName}}() {\n  this.food = '{{params.food}}';\n  this.venue = '{{params.venue}}';\n}\n```\n\nAnd then you can generate files based on the template:\n\n```sh\ngenerate app/meal.js lunch food:taco venue:cart\n```\n\nThis will create a file at `app/lunch.js` that looks like:\n\n```js\nfunction lunch() {\n  this.food = 'taco';\n  this.venue = 'cart';\n}\n```\n\nLoom, by default, will save files to your app in the same relative\nlocation they were found in your templates directory.\n\n### Generators\n\nWe can define a generator to make everything a little nicer. First we'll\ncreate a `present` method that determines what data goes to the\ntemplate. Then we'll tell it where to find the template so we can\nsimplify the generator command.\n\n_loom/generators/meal.js_\n\n```js\nexports.present = function(name, params) {\n  params.constructorName = name.charAt(0).toUpperCase() + name.slice(1);\n  return params;\n};\n\nexports.template = 'app/meal.js.hbs';\n```\n\nNow our template is simpler, no more `{{params.food}}` and it\ncapitalizes our constructor like a propery lady or gent.\n\n_loom/templates/meal.js.hbs_\n\n```mustache\nfunction {{constructorName}}() {\n  this.food = '{{food}}';\n  this.venue = '{{venue}}';\n}\n```\n\nAnd finally our command is simpler, it now just matches a generator\nnamed `meal` instead of a template found at `app/meal.js`.\n\n`generate meal lunch food:taco venue:cart`\n\n### Engines\n\nThe default generator uses handlebars, but we can swap it out for ejs by\ncreating a very simple \"engine\":\n\n_loom/engines/ejs.js_\n\n```js\nvar _ = require('underscore');\n// module.exports = _.template\n// that works, but for clarity:\n\nmodule.exports = function(src, locals) {\n  return _.template(src, locals);\n};\n```\n\nRename your template to `meal.js.ejs` and edit it:\n\n```ejs\nfunction <%= constructorName %>() {\n  this.food = '<%= food %>';\n  this.venue = '<%= venue %>';\n}\n```\n\nUpdate your generator to point to the proper template:\n\n```js\nexports.template = 'app/meal.js.ejs';\n```\n\nLoom looks at the file extension of the template (in this case `ejs`)\nand then tries to find a template engine named `ejs.js`.\n\nNow generate your newly configured template:\n\n`generate meal lunch food:taco venue:cart`\n\n### Multiple templates for one generator\n\nIts very common for a generator to create several files, like unit tests\nand scaffoling. Lets add a unit test template to our meal generator.\n\n_loom/templates/test/unit/meal.spec.js.ejs_\n\n```ejs\ndescribe('<%= constructorName %>', function() {\n  it('sets food to \"<%= food %>\"', function() {\n    var meal = new <%= constructorName %>();\n    expect(meal.food).to.equal('<%= food %>');\n  });\n});\n```\n\nAnd add the template path to your generator, note the rename from\n`exports.template` to `export.templates`.\n\n```js\nexports.templates = [\n  'app/meal.js.ejs',\n  'test/unit/meal.spec.js.ejs'\n];\n```\n\nBoth templates will get the same data from `generator.present` and the\nfiles will be saved to the same relative path in your app as they are\ndefined in your templates directory.\n\n### Default Generators\n\nIf you define `loom/generators/default.js`, loom will use it when a\nspecific generator is not found.\n\nPublishing Generators to NPM for Everybody\n------------------------------------------\n\nName your module `loom-generators-<name>` (like\n`loom-generators-ember`), place generators, templates, and engines in\n`./loom`, and then publish.  That's it. People can simply `npm install\nloom-generators-<name> --save` and start using them.\n\nPublishing Template Engines to NPM for Everybody\n------------------------------------------------\n\nTo add support for your favorite templating engine you can either add a\nfile to `loom/engines` or publish a module to npm named\n`loom-engine-<ext>`. Loom will attempt to require the engine if it\ndoesn't find it in your project.\n\nGenerator API\n-------------\n\nLoom has a generic generator that can be overridden to meet your specific\nuse case. Generators can export a few methods that loom will use.\n\nYour generator can implement as many methods as you need, loom will\nmerge in the `generic_generator` methods that you don't provide.\n\nHere's a generator that does nothing:\n\n_loom/generators/noop.js_\n\n```js\nexports.before = function(){};\nexports.present = function(){};\nexports.savePath = function(){};\nexports.write = function(){};\nexports.render = function(){};\nexports.template = '';\n// exports.template = function(){};\n// exports.templates = [];\n// exports.templates = function(){};\n```\n\nBelow is documentation on generator API, also, check out the [generic\ngenerator](lib/generic_generator).\n\n### generator.before\n\nExecutes before anything else happens. Useful if you need to set or\nchange some things on `env` before it moves through the other methods of\nyour generator.\n\n#### signature\n\n`function(env)`\n\n#### arguments\n\n1. env (Object) - the loom environment object.\n\n\n### generator.present\n\n#### signature\n\n`function([argN] [, params], env)`\n\n#### arguments\n\n1. argN (String) - the space separated values used in the loom command\n2. params (Object) - the key:value pairs used in the loom command\n3. env (Object) - the loom environment object\n\n#### examples\n\nLets make a generator that logs the arguments to explore how this works.\n\n_loom/generators/user.js_\n\n```js\nexports.present = function() {\n  console.log(arguments);\n};\n```\n\nThe following are commands followed by what is logged for the arguments:\n\n```sh\ngenerate model user name:string age:number\n{ '0': 'user', '2': { name: 'string', age: 'number' } }\n\ngenerate model foo bar baz qux:1 quux:2\n{ '0': 'foo',\n  '1': 'bar',\n  '2': 'baz',\n  '3': { qux: '1', quux: '2' } }\n```\n\nAs you can see, the space separated values become the arguments and the\nkey=value pairs are wrapped up into an object for the final `params` argument.\n\n\n### generator.template\n\nDetermines which template to render.\n\n`exports.template` can simply be a string, or a function if you need to\ncompute it.\n\nPaths are relative to the `./loom/templates` directory.\n\n#### example\n\nTo use a template found at\n`loom/templates/spec/models/model.spec.js.hbs`:\n\n```js\nexports.template = 'spec/models/model.spec.js.hbs';\nexports.template = function() {\n  // some computation\n  return 'spec/models/model.spec.js.hbs';\n};\n```\n\n#### notes\n\nUnless you override `generator.write` the generated file will be saved\nin the mirrored location in `loom/templates`, so the example above will\nbe saved to `spec/models/<name>.spec.js`.\n\n### generator.templates\n\nSame as `template` but is an array of template paths that take\nprecendence over `template`. Each template will receive the same locals\nreturned from `present`. Can also be a function that returns an array.\n\n#### examples\n\n```js\nexports.templates = [\n  'app/models/model.js.ejs',\n  'spec/models/model.spec.js.ejs'\n];\n\nexports.templates = function() {\n  return [\n    'app/models/model.js.ejs',\n    'spec/models/model.spec.js.ejs'\n  ];\n};\n```\n\n### generator.savePath\n\nDetermines the path in which to save a template.\n\n#### signature\n\n`function(template, env)`\n\n#### arguments\n\n1. template (String) - the path of the template being rendered\n2. env (Object) - the loom environment object\n\n### generator.write\n\nWrites a rendered template to the file system, its unlikely you'll want\nto override this.\n\n#### signature\n\n`function(templateName, src, env)`\n\n### generator.render\n\nDetermines how to render the template, its unlinkely you'll want to\noverride this.\n\n#### signature\n\n`function(engine, templatePath, locals)`\n\nTODO\n====\n\n- --force option to overwrite files (better for scripting so you don't\n  get the prompt)\n- async compatibility, right now all generator operations must be\n  sync\n\n","license":"MIT","scripts":{"test":"node_modules/.bin/mocha --require should --reporter dot --ui bdd $(find test -name \"*.spec.js\")"},"_npmUser":{"name":"ryanflorence","email":"rpflorence@gmail.com"},"homepage":"https://github.com/rpflorence/loom","keywords":["generator","scaffold","template","templating"],"repository":{"url":"git://github.com/rpflorence/loom","type":"git"},"_npmVersion":"1.3.14","description":"Weave your wefts betwixt the warps of loom generators and scaffolds.","directories":{},"maintainers":[{"name":"ryanflorence","email":"rpflorence+npm@gmail.com"}],"dependencies":{"fs-extra":"~0.6.3","cli-color":"~0.2.2","commander":"~2.0.0","sync-prompt":"~0.1.0","loom-engine-hbs":"1.0.0"},"readmeFilename":"README.md","devDependencies":{"mocha":"~1.12.0","sinon":"~1.7.3","should":"~1.2.2"},"_id":"loom@2.0.0","version":"2.0.0"}