├── README.md ├── package.json ├── .gitignore ├── LICENSE └── index.js /README.md: -------------------------------------------------------------------------------- 1 | duct 2 | ==== 3 | 4 | Document generation framework 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "duct" 3 | , "version": "0.0.1" 4 | , "license": "MIT" 5 | , "dependencies": { 6 | "isarray": "0.0.1" 7 | , "jquery": "2.1.1" 8 | } 9 | , "bin": { 10 | "duct": "./duct-cli.js" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Deployed apps should consider commenting this line out: 24 | # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git 25 | node_modules 26 | 27 | TODO.txt 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Robin Berjon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | var jquery = require("jquery") 3 | , isArray = require("isarray") 4 | , duct = { 5 | nowModules: null 6 | , onloadModules: null 7 | , $: jquery 8 | , doc: document 9 | , conf: null 10 | } 11 | ; 12 | 13 | function extractConfiguration () { 14 | if (duct.conf) return; 15 | duct.conf = {}; 16 | try { 17 | jquery("script[type='application/duct+json']") 18 | .each(function () { 19 | jquery.extend(duct.conf, JSON.parse($(this).text())); 20 | }); 21 | } 22 | catch (e) { 23 | // XXX error 24 | } 25 | } 26 | 27 | function runPipe (pipe) { 28 | var step = 0 29 | , doNext = function () { 30 | if (step === pipe.length) return; 31 | step++; 32 | try { 33 | pipe[step - 1](duct, doNext); 34 | } 35 | catch (e) { 36 | // XXX error 37 | } 38 | } 39 | ; 40 | doNext(); 41 | } 42 | 43 | // these get run ASAP (e.g. to avoid FOUC) 44 | // the DOM may not be available 45 | exports.now = function (mods) { 46 | if (!mods) return; 47 | duct.nowModules = isArray(mods) ? mods : [mods]; 48 | extractConfiguration(); 49 | runPipe(duct.nowModules); 50 | }; 51 | 52 | // these get run at load 53 | exports.onload = function (mods) { 54 | if (!mods) return; 55 | duct.onloadModules = isArray(mods) ? mods : [mods]; 56 | }; 57 | 58 | 59 | jquery(function () { 60 | extractConfiguration(); 61 | runPipe(duct.onloadModules); 62 | }); 63 | --------------------------------------------------------------------------------