1 | loaddir.js
|
2 | ==========
|
3 |
|
4 | Asset watching, handling, and compiling for node.js
|
5 |
|
6 | To install run `npm install loaddir`
|
7 |
|
8 | Some examples
|
9 | =============
|
10 |
|
11 | ```javascript
|
12 | // load server side templates into object for use: template.index()
|
13 | loaddir = require('loaddir');
|
14 | jade = require('jade');
|
15 |
|
16 | loaddir({
|
17 |
|
18 | // defaults
|
19 | //
|
20 | // watch: true
|
21 | // compile / callback will be called again when file changes
|
22 |
|
23 | // instead of { 'full/path/to' : 'fileContents' }
|
24 | // returns recursive objects { full : { path : { to : 'fileContents' } } }
|
25 | asObject: true,
|
26 |
|
27 | path: __dirname + '/templates',
|
28 |
|
29 | // compile runs before callback
|
30 | compile: function(fileContents){
|
31 |
|
32 | // this == loaddir file instance
|
33 |
|
34 | // this.fileContents == fileContents
|
35 |
|
36 | // the return becomes the new fileContents
|
37 | return jade.compile(fileContents);
|
38 | },
|
39 | callback: function(thisContext){
|
40 |
|
41 | // thisContext == this == loaddir file instance
|
42 |
|
43 | // compile and callback are similar with different args
|
44 | return this.fileContents.replace(/__hostname/g, 'http://google.com');
|
45 | },
|
46 |
|
47 | }).then(function(templates) {
|
48 |
|
49 | // templates == { account: {index: ..., change_password: ...}, index: ... }
|
50 | });
|
51 |
|
52 | ```
|
53 |
|
54 | `callback` will be ran each time the file changes, keeping the returned `templates` object updated.
|
55 |
|
56 |
|
57 | PATCH NOTES
|
58 | ===========
|
59 |
|
60 | `1.0.0`
|
61 | Added promises, and async handling
|
62 |
|
63 |
|
64 | `0.2.12`
|
65 | Everything got changed to be class based -- use `expose_hooks: true` to get instances of the classes rather than just the outputted results
|
66 |
|
67 | `0.0.21`
|
68 | fixed an issue where deleted files were throwing an error to what was watching them
|
69 | `0.0.20`
|
70 | removed in issue where files were being watched multiple times if a directory had new files being created or destroyed in it(even swp files were breaking it)
|
71 |
|
72 | ## License
|
73 |
|
74 | (The MIT License)
|
75 |
|
76 | Copyright (c) 2014 Dan Schumann
|
77 |
|
78 | Permission is hereby granted, free of charge, to any person obtaining
|
79 | a copy of this software and associated documentation files (the
|
80 | 'Software'), to deal in the Software without restriction, including
|
81 | without limitation the rights to use, copy, modify, merge, publish,
|
82 | distribute, sublicense, and/or sell copies of the Software, and to
|
83 | permit persons to whom the Software is furnished to do so, subject to
|
84 | the following conditions:
|
85 |
|
86 | The above copyright notice and this permission notice shall be
|
87 | included in all copies or substantial portions of the Software.
|
88 |
|
89 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
90 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
91 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
92 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
93 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
94 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
95 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|