{"name":"themeleon","version":"0.2.0","repository":{"type":"git","url":"https://github.com/valeriangalliat/themeleon.git"},"scripts":{"test":"jshint *.js"},"dependencies":{"fs-extra":"0.*","q":"1.*"},"devDependencies":{"jshint":"2.*"},"gitHead":"3d4121e80fbb511f1223040d02b93b83a4ac5ded","description":"Themeleon =========","bugs":{"url":"https://github.com/valeriangalliat/themeleon/issues"},"homepage":"https://github.com/valeriangalliat/themeleon","_id":"themeleon@0.2.0","_shasum":"8281410e642b71ad000e0a92e58ce6b4c55beb91","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"valeriangalliat","email":"vava720@gmail.com"},"maintainers":[{"name":"valeriangalliat","email":"vava720@gmail.com"}],"dist":{"shasum":"8281410e642b71ad000e0a92e58ce6b4c55beb91","tarball":"http://registry-npm.ywwl.com/themeleon/download/themeleon-0.2.0.tgz","integrity":"sha512-wwLZCmB9ZY8OS0zUzi2Vjt93daETuaTMBzA1HcEh41wA5M8rdiMNlAiQtpv1a2evQrWMnuCNXtL5mIeU97+BvA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCQpt1hNK3FZkK1l6Zr6iGKmmrrZ6u1v66BA+guamw66gIhALq6sYYF4/IgpVMfWd+CBC2weaz+Vq9Z/lkMCiIUq9Is"}],"size":2488,"noattachment":false,"key":"/themeleon/-/themeleon-0.2.0.tgz"},"directories":{},"readme":"# Themeleon [![npm version](http://img.shields.io/npm/v/themeleon.svg?style=flat-square)](https://www.npmjs.org/package/themeleon)\n\n> A lightweight Node.js theme engine.\n\n* [Overview](#overview)\n  * [Interface](#interface)\n    * [Publication](#publication)\n    * [Inclusion](#inclusion)\n  * [Framework](#framework)\n* [Usage](#usage)\n  * [As a theme maker](#as-a-theme-maker)\n  * [As a theme user](#as-a-theme-user)\n* [Template engines](#template-engines)\n* [Examples](#examples)\n\nOverview\n--------\n\nThemeleon is two things:\n\n1. a conventional interface to build themes with Node.js,\n1. a tiny and modular framework to implement the interface.\n\n### Interface\n\nA theme is a simple JavaScript function. The purpose of this function\nis to render a **context** in a **destination**.\n\nThe **context** is a JavaScript object. It typically contains the\nvariables and configuration you will use to render the theme in the\n**destination** directory.\n\nA theme is also asynchronous, and relies on [Promises/A+] for this.\n\n[Promises/A+]: http://promises-aplus.github.io/promises-spec/\n\nThe following JSDoc comment describes the theme interface:\n\n```js\n/**\n * @param {String} destination\n *   Destination directory to render the theme in. The directory must\n *   already exist, be empty, and be writable.\n *\n * @param {Object} context\n *   An object passed to the template engine to render the theme. Usually,\n *   each key of the context object will be a variable in the template.\n *\n * @return {Promise}\n *   Any compatible implementation of the Promises/A+ specification.\n */\nfunction render(destination, context) {}\n```\n\nSo, if you want to create a *Themeleon compatible* theme, you can\nimplement this interface by hand without relying on the `themeleon`\nNode.js package.\n\nThe behavior is undefined if the destination directory doesn't exists or\nis not empty.\n\n*Note: Themeleon does not document anything about the context object\nstructure. This is left to the project that will be themed. It means\nthat a Themeleon theme is strongly tied with the context it is designed\nfor.*\n\n#### Publication\n\nYou will probably be publishing themes *for a context*, since you need a\npredictable idea of what will contain the context data.\n\nThe convention is to name the Node.js package like this:\n\n```\n{{context}}-theme-{{theme}}\n```\n\nThe `{{context}}` variable is the context name, an identifier that\nqualifies the kind of data the context object will contain, and\n`{{theme}}` is the name of your theme.\n\nSee a practical example in the [Examples](#examples) section below.\n\nYou're not required to publish the theme on npm, anything that can be\n`require`d will do the job, so downloading a theme archive, extracting\nit in a folder, and including its `index.js` is also an acceptable\nsolution. I believe it's more practical to use a package manager for\nthis though.\n\n#### Inclusion\n\nIf you want to make your project themable, all you'll need to do is to\ndynamically `require` a theme module, an call it with a destination and\ncontext object.\n\nThemeleon doesn't enforces anything about this, but the recommended way\nis the following:\n\n1. Let your users configure a theme name (or even directly a theme\n   function if you expose a Node.js API).\n1. If the theme is not a function but a single identifier (something\n   like `[a-z-]+`, but you can be less strict), `require` the prefixed\n   name (`{{context}}-theme-{{theme}}`).\n1. Otherwise, `require` the whole name (it might be a path), resolved to\n   `process.cwd()` (it might be relative too).\n\n### Framework\n\nThemeleon also acts as a theme creation framework, to ease the\ninterface implementation by hiding relatively low-level considerations,\nlike reading and writing files, handling promises, and using a raw\ntemplate engine.\n\nWhen using the framework, you only have to define a render function,\nthat will describe the high-level tasks needed to render the theme.\n\nThese tasks are in fact mixins that you include in your Themeleon\ninstance. It's easy to define and share custom mixins, and that's how\n[template engines](#template-engines) are brought to Themeleon.\n\nThe mixins makes it easy to abstract the theme directory, destination\ndirectory and the context data. For example, a mixin can decide to make\na given path relative to the theme or destination directory when it\nmakes sense, instead of the CWD, and a template engine mixin can\nimplicitely pass the context object to the templates.\n\nUsage\n-----\n\n### As a theme maker\n\nFirst, install Themeleon in your `package.json`:\n\n```sh\nnpm install themeleon --save\n```\n\n```json\n{\n  \"dependencies\": {\n    \"themeleon\": \"1.*\"\n  }\n}\n```\n\nYou will be using Themeleon in the `index.js` of your theme package.\n\nFirst, create a Themeleon instance:\n\n```js\nvar themeleon = require('themeleon')();\n```\n\nYou can then use some mixins, for example see the\n[supported template engines](#template-engines).\n\n```js\n// Use consolidate.js for templating\nthemeleon.use('consolidate');\n```\n\nYou may also add your own mixin:\n\n```js\nthemeleon.use({\n\n  /**\n   * Log current source directory, destination directory, and context\n   * variables.\n   */\n  log: function () {\n    console.log(this.src, this.dest, this.ctx);\n  },\n});\n```\n\nNow everything is initialized, you can begin to describe your theme.\n\nFor this, you define a function taking a Themeleon instance `t` as\nparameter, and you give this function to the `themeleon` function,\ntogether with the theme directory (certainly `__dirname` if you're in\nthe `index.js`):\n\n```js\nmodule.exports = themeleon(__dirname, function (t) {\n  // Theme render logic here\n});\n```\n\nThe `themeleon` function will take care of the\n[interface implementation](#interface), and will call your render\nfunction on demand. That's where the magic resides:\n\n```js\nmodule.exports = themeleon(__dirname, function (t) {\n  t.copy('assets'); // Will copy `assets` in destination directory\n  // t.copy('assets', 'foo'); // Other name in destination directory\n\n  // Compile a Swig view as `index.html` in destination directory\n  t.swig('views/index.html.swig', 'index.html');\n\n  // Call the custom mixin defined above\n  t.log();\n});\n```\n\nAnd that's all! Themeleon will run all the tasks and return a promise\nwaiting for them all to complete.\n\n### As a theme user\n\nUse the above theme (assuming it's named `project-theme-foo`) in a\nproject:\n\n```js\nvar theme = require('project-theme-foo');\n\n// Render the theme in `dest` directory with given variables\ntheme('dest', {\n  some: 'variables',\n  that: 'will be',\n  passed: 2,\n  the: 'theme',\n});\n```\n\nTemplate engines\n----------------\n\nThemeleon provides a native mixin for [consolidate.js], an awesome\nlibrary to get an unified interface for a bunch of template engines.\n\n[consolidate.js]: https://github.com/tj/consolidate.js\n\nBasically, `t.{{engine}}` is an adapter for `consolidate.{{engine}}`,\ntaking care of passing the context and writing the destination file for\nyou. All you have to do is run `t.{{engine}}(src, dest)`.\n\nIf you want to add more variables to the context object (passed to the\ntemplates) for a specific file, you can pass an object as third\nargument, which will be merged with the global context before rendering.\nThis is also used by consolidate.js to define partials for some template\nengines.\n\nExamples\n--------\n\nThe best production example for Themeleon is [SassDoc]. In fact,\nThemeleon was created *for SassDoc* because we wanted to support custom\nthemes, without having any theming logic inside SassDoc.\n\nSassDoc describes a [theme context interface][theme-context]. This\ndocuments the context object passed to SassDoc themes. So, if you want\nto write a theme for SassDoc, all you have to do is to provide a\nfunction implementing the [Themeleon interface](#interface), and making\nsense of the context data passed by SassDoc.\n\nSince the context is specific to SassDoc, all themes are prefixed with\n`sassdoc-theme-`. Thus, the [default theme][sassdoc-theme-default] is\npublished as `sassdoc-theme-default`. This theme uses Swig to render a\nsingle HTML page from multiple Swig partials, built around the\ndocumented SassDoc context.\n\n[SassDoc]: https://github.com/SassDoc/sassdoc\n[theme-context]: http://sassdoc.com/data-interface/\n[sassdoc-theme-default]: https://github.com/SassDoc/sassdoc-theme-default\n","publish_time":1405763346249,"_cnpm_publish_time":1405763346249,"dist-tags":{"beta":"3.0.0-rc.4","latest":"3.0.2"}}