Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
87 lines (73 loc) · 1.96 KB
/
Copy pathindex.js
File metadata and controls
87 lines (73 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict';
var fuse = require('fusing')
, path = require('path')
, fs = require('fs');
//
// Defaults.
//
var Assets = require('./assets')
, available = [ 'nodejitsu', 'npm' ];
/**
* Contour will register several default HTML5 templates of Nodejitsu. These
* templates can used from inside views of other projects.
*
* Options that can be supplied
* - brand {String} framework or brand to use, e.g nodejitsu or opsmezzo
* - mode {String} bigpipe or standalone, defaults to bigpipe
*
* @Constructor
* @param {Object} options optional, see above
* @api public
*/
function Contour(options) {
var contour = this
, assets;
this.fuse();
//
// Add the pagelets of the required framework.
//
options = options || {};
//
// Load and optimize the pagelets, extend contour but acknowledge external
// listeners when all pagelets have been fully initialized.
//
assets = new Assets(options.brand, options.mode || 'bigpipe');
assets.on('optimized', this.emits('init'));
this.mixin(this, assets);
}
//
// Add EventEmitter and Predefine functionality.
//
fuse(Contour, require('events').EventEmitter);
/**
* Small helper function that exposes the core per brand.
*
* @param {String} brand available brands
* @return {String} path to the core stylus file
* @api public
*/
Contour.get = function get(brand) {
if (!~available.indexOf(brand)) brand = 'nodejitsu';
var base = path.join(__dirname, 'pagelets', brand);
return fs.readdirSync(base).reduce(function reduce(memo, file) {
if ('.styl' !== path.extname(file)) return memo;
memo[path.basename(file, '.styl')] = path.join(base, file);
return memo;
}, { js: path.join(base, 'core.js') });
};
//
// Proxy method to get.
//
Contour.readable('get', Contour.get);
//
// Expose the brands that are available.
//
Contour.readable('available', available);
//
// Expose the Assets constructor.
//
Contour.readable('Assets', Assets);
//
// Expose constructor.
//
module.exports = Contour;