UNPKG

2.85 kBMarkdownView Raw
1loaddir.js
2==========
3
4Asset watching, handling, and compiling for node.js
5
6To install run `npm install loaddir`
7
8Some examples
9=============
10
11```javascript
12// load server side templates into object for use: template.index()
13loaddir = require('loaddir');
14jade = require('jade');
15
16loaddir({
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
57PATCH NOTES
58===========
59
60`1.0.0`
61Added promises, and async handling
62
63
64`0.2.12`
65Everything 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`
68fixed an issue where deleted files were throwing an error to what was watching them
69`0.0.20`
70removed 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
76Copyright (c) 2014 Dan Schumann
77
78Permission is hereby granted, free of charge, to any person obtaining
79a copy of this software and associated documentation files (the
80'Software'), to deal in the Software without restriction, including
81without limitation the rights to use, copy, modify, merge, publish,
82distribute, sublicense, and/or sell copies of the Software, and to
83permit persons to whom the Software is furnished to do so, subject to
84the following conditions:
85
86The above copyright notice and this permission notice shall be
87included in all copies or substantial portions of the Software.
88
89THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
90EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
91MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
92IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
93CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
94TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
95SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.