1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var path = require('path');
|
8 | var Core = require('assemble-core');
|
9 | var plugins = require('./lib/plugins');
|
10 | var utils = require('./lib/utils');
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function Assemble(options) {
|
25 | if (!(this instanceof Assemble)) {
|
26 | return new Assemble(options);
|
27 | }
|
28 | Core.call(this, options);
|
29 | this.is('assemble');
|
30 | this.initAssemble();
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | Core.extend(Assemble);
|
38 | Core.bubble(Assemble);
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | Assemble.prototype.initAssemble = function() {
|
45 | Assemble.emit('assemble.preInit', this);
|
46 | Assemble.initAssemble(this);
|
47 | Assemble.emit('assemble.postInit', this);
|
48 | };
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | Assemble.initAssemble = function(app) {
|
55 | Assemble.initDefaults(app);
|
56 | Assemble.initPlugins(app);
|
57 | Assemble.initViews(app);
|
58 | };
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | Assemble.initDefaults = function(app) {
|
65 | var exts = app.options.exts || ['md', 'hbs', 'html'];
|
66 |
|
67 | |
68 |
|
69 |
|
70 |
|
71 | app.engine(exts, require('engine-handlebars'));
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 | app.onLoad(utils.extRegex(exts), function(view, next) {
|
78 |
|
79 | if (view.options.frontMatter === false) {
|
80 | next();
|
81 | return;
|
82 | }
|
83 | if (app.options.frontMatter === false) {
|
84 | next();
|
85 | return;
|
86 | }
|
87 | utils.matter.parse(view, next);
|
88 | });
|
89 | };
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | Assemble.initPlugins = function(app) {
|
106 | enable('logger', plugins.logger);
|
107 | enable('loader', plugins.loader);
|
108 | enable('config', plugins.config);
|
109 | enable('argv', plugins.argv);
|
110 | enable('cli', plugins.cli);
|
111 |
|
112 | function enable(name, fn) {
|
113 | if (app.option('plugins') === false) return;
|
114 | if (app.option('plugins.' + name) !== false) {
|
115 | app.use(fn());
|
116 | }
|
117 | }
|
118 | };
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | Assemble.initViews = function(app) {
|
128 | if (app.isFalse('collections')) return;
|
129 |
|
130 | app.create('partials', {
|
131 | engine: app.options.engine || 'hbs',
|
132 | viewType: 'partial',
|
133 | renameKey: function(fp) {
|
134 | return path.basename(fp, path.extname(fp));
|
135 | }
|
136 | });
|
137 |
|
138 | app.create('layouts', {
|
139 | engine: app.options.engine || 'hbs',
|
140 | viewType: 'layout',
|
141 | renameKey: function(fp) {
|
142 | return path.basename(fp, path.extname(fp));
|
143 | }
|
144 | });
|
145 |
|
146 | app.create('pages', {
|
147 | engine: app.options.engine || 'hbs'
|
148 | });
|
149 | };
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 | module.exports = Assemble;
|