├── .npmignore ├── README.org ├── index.js ├── node_modules ├── nodewatch │ ├── docs │ │ ├── docco.css │ │ └── watch.html │ ├── lib │ │ └── watch │ │ │ └── watch.js │ └── package.json ├── simple-logger │ ├── .npmignore │ ├── README.md │ ├── index.js │ └── package.json └── underscore │ ├── .npmignore │ ├── LICENSE │ ├── README │ ├── index.html │ ├── index.js │ ├── package.json │ ├── underscore-min.js │ └── underscore.js ├── package.json ├── samples ├── nodeinterval.js └── nodeinterval.sh └── tests ├── assets └── index.html ├── listen.js ├── node_modules ├── .bin │ └── vows ├── nodeinterval │ ├── index.js │ └── node_modules │ │ ├── nodewatch │ │ ├── docs │ │ │ ├── docco.css │ │ │ └── watch.html │ │ ├── lib │ │ │ └── watch │ │ │ │ └── watch.js │ │ └── package.json │ │ ├── simple-logger │ │ ├── .npmignore │ │ ├── README.md │ │ ├── index.js │ │ └── package.json │ │ └── underscore │ │ ├── .npmignore │ │ ├── LICENSE │ │ ├── README │ │ ├── index.html │ │ ├── index.js │ │ ├── package.json │ │ ├── underscore-min.js │ │ └── underscore.js └── vows │ ├── .gitignore │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── bin │ └── vows │ ├── lib │ ├── assert │ │ ├── error.js │ │ ├── macros.js │ │ └── utils.js │ ├── vows.js │ └── vows │ │ ├── console.js │ │ ├── context.js │ │ ├── coverage │ │ ├── file.js │ │ ├── fragments │ │ │ ├── coverage-foot.html │ │ │ └── coverage-head.html │ │ ├── report-html.js │ │ ├── report-json.js │ │ └── report-plain.js │ │ ├── extras.js │ │ ├── reporters │ │ ├── dot-matrix.js │ │ ├── json.js │ │ ├── silent.js │ │ ├── spec.js │ │ ├── watch.js │ │ └── xunit.js │ │ └── suite.js │ ├── package.json │ └── test │ ├── assert-test.js │ ├── fixtures │ └── isolate │ │ ├── failing.js │ │ ├── log.js │ │ ├── passing.js │ │ └── stderr.js │ ├── isolate-test.js │ ├── testInherit.js │ ├── vows-error-test.js │ └── vows-test.js ├── run-tests.js └── src ├── index.html └── templates ├── .bob ├── dir_level_2 ├── .doggies │ └── file1 ├── dir_level_3 │ └── template09.tmpl ├── template07.tmpl └── template08.tmpl ├── template01.tmpl ├── template02.tmpl ├── template03.tmpl ├── template04.tmpl ├── template05.tmpl └── template06.tmpl /.npmignore: -------------------------------------------------------------------------------- 1 | tests 2 | .npmignore 3 | 4 | 5 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | : _ _ _ _ 2 | : _ __ ___ __| | ___(_)_ __ | |_ ___ _ ____ ____ _| | 3 | : | '_ \ / _ \ / _` |/ _ \ | '_ \| __/ _ \ '__\ \ / / _` | | 4 | : | | | | (_) | (_| | __/ | | | | || __/ | \ V / (_| | | 5 | : |_| |_|\___/ \__,_|\___|_|_| |_|\__\___|_| \_/ \__,_|_| 6 | : 7 | : Automation for lazy people. 8 | 9 | * What it does 10 | 11 | NodeInterval promotes code organization by allowing you to move your JavaScript 12 | templates out of your html page and into organized files and folders. When ran, 13 | it collects all the files in your templates folders, orders them alphabetically 14 | by script id, and inserts them into a text document(s) of your choice. 15 | 16 | NodeInterval contains a watch option that enables you to leave it running in a 17 | seperate tab to automatically run the above process anytime a template has been 18 | modified. 19 | 20 | NodeInterval is commonly used in [[http://documentcloud.github.com/backbone/][Backbone]], [[http://maccman.github.com/spine/][Spine]], and similiar web application 21 | frameworks that rely heavily on embedded templates. 22 | 23 | Think of it as a simple version of [[http://sass-lang.com/][Sass]] for your JavaScript templates. 24 | 25 | * Features 26 | 27 | 1. Works with all templating solutions including [[http://documentcloud.github.com/underscore/][underscore.js]] and [[http://api.jquery.com/category/plugins/templates/][jQuery templates]]. (The only requirement is that the template needs to have an id property since they are oganized alphabetically.) 28 | 2. Hidden files inside of template folder (files that begin with "." like .git, .svn, and .DS_Store) are automatically ignored. 29 | 3. Profiles the time it takes to render all templates. 30 | 4. Supports multiple sets of input and output files (see example in =sample/nodeinterval.js=). 31 | 5. Can be used with build tools like [[http://www.gnu.org/software/make/][Gnu Make]] and [[http://ant.apache.org/][Apache Ant]]. 32 | 6. Has clean, date-stamped, and color-coded command-line output: 33 | : $ node nodeinterval.js 34 | : 18 Aug 01:47:49 - INFO: NodeInterval is watching for changes. Press Ctrl-C to stop. 35 | : 18 Aug 01:47:49 - INFO: overwrite ../assets/index.html 36 | : 18 Aug 01:47:49 - INFO: Completed in 0.001 seconds. 37 | : 18 Aug 01:48:04 - INFO: >>> Change detected to: ~/git/projectName/src/templates/signon/signon.tmpl 38 | : 18 Aug 01:48:04 - INFO: overwrite ../assets/index.html 39 | : 18 Aug 01:48:04 - INFO: Completed in 0.002 seconds. 40 | 41 | * Requirements 42 | - You must have [[http://nodejs.org/][nodejs]] installed. 43 | - [[http://npmjs.org/][NPM]] (Node package Manager) if you want to install this package using it. 44 | * Installing and using 45 | 46 | Note: Your application should have a clean folders architecture differentiating 47 | compiled vs source files. See the section below on "Sample web application 48 | layout" for a decent one. It's a lot simpler than it sounds. 49 | 50 | There are two ways to install: Cloning this repo or using [[http://npmjs.org/][npm]]. Once you have the 51 | package installed feel free to modify and use the sample script in the =samples= 52 | directory. 53 | 54 | : cd bin # Your scripts directory. 55 | : npm install NodeInterval 56 | : cp node_modules/nodeinterval/samples/nodeinterval.sh . 57 | : emacs nodeinterval.sh # Setup your variable paths with your favorite editor. 58 | : chmod u+x nodeinterval.sh 59 | : ./nodeinterval.sh # Start watching your files 60 | 61 | Alternatively, you can use the sample .js file instead of the .sh version and 62 | run it like so: 63 | 64 | : node nodeinterval.js 65 | 66 | * Usage 67 | 68 | It's best to create a Node or shell script that you can call via command line. A 69 | copy of this example is included in the =samples= directory. 70 | 71 | : var Nodeinterval = require('nodeinterval'), 72 | : ni = new Nodeinterval.Watcher({ 73 | : inputFile: '../path/to/raw/index.html', 74 | : outputFile: '../path/to/rendered/index.html', 75 | : replacementString: '@templates@', 76 | : watchFolder: '../path/to/templates/' 77 | : }).startWatch(); 78 | 79 | Options you can pass to =new Nodeinterval.Watcher= are: 80 | 81 | | Option | Description | default | 82 | |---------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------| 83 | | =inputFile= | is the main template you want to duplicate. | '../src/index.html' | 84 | | =outputFile= | is the relative or absolute path to the file you want to create (that's a copy of =inputFile= with the =replacementString= replaced with all your templates. | '../assets/index.html' | 85 | | =replacementString= | is the string inside of =inputFile= that you want to replace with all your templates. | '@templates@' | 86 | | =watchFolder= | is the relative or absolute path to the folder you want to monitor. | '../src/templates/' | 87 | 88 | Once a new =Nodeinterval.Watcher= is created. It has the additional api methods. Some methods are chainable. 89 | 90 | | Method | Description | 91 | |-------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 92 | | startWatch | Turns on the monitoring service. All files in =watchFolder= are now being watched for changes. Chainable. | 93 | | stopWatch | All files in =watchFolder= are now not being watched. Chainable. | 94 | | updateIndex | This is called internally anytime a change is detected. Replaces =outputFile= with a version of =inputFile= with =replacementString= replaced with contents of =watchFolder=. | 95 | | | | 96 | 97 | NodeInterval can also watch multiple input and output files. Just use an array 98 | to specify filenames under =inputFile= and =outputFile=. This is good, for 99 | example, where you have two sets of html files, one for uncompressed js and css 100 | and one for compressed css and js, and you want both files to render your 101 | templates on change. 102 | 103 | * Sample web application layout 104 | 105 | If you don't have a good web application layout. Here's a good one to follow: 106 | 107 | : . 108 | : ├── assets <== Your compressed assets, ready for production. 109 | : │ ├── images 110 | : │ ├── index.html <== "Built" html file with your rendered templates. 111 | : │ ├── js 112 | : │ └── css 113 | : ├── bin <== Shell scripts. "npm install nodeinterval" here. 114 | : │ ├── node_modules <== This folder will automatically be created. 115 | : │ │ └── nodeinterval <== nodeinterval and it's dependencies will be 116 | : │ │ installed here. 117 | : │ ├── nodeinterval.sh <== This sample file (and the .js) version is inside 118 | : │ │ of nodeinterval/samples/. Use it if you like. 119 | : │ └── sasswatch.sh <== I like to create a Sass executable for watching 120 | : │ my CSS files as well. (not part of this project) 121 | : └── src <== Raw uncompressed code here, where you should be 122 | : │ editing your codez. 123 | : ├── index.html <== Raw index.html files with "replacementString" 124 | : │ where you want the templates. 125 | : ├── css <== Uncompressed CSS assets. 126 | : ├── js <== Uncompressed JS assets. 127 | : └── templates <== Your .js templates. These can be all in one 128 | : folder or seperated out into many folder deep, 129 | : according to section. Incude the 12 | 13 | 16 | 17 | 20 | 21 | 24 | 25 | 28 | 29 | 32 | 33 | 36 | 37 | 40 | 41 | 42 |
My templates above
43 |