1 |
|
2 | 'use strict';
|
3 |
|
4 | var path = require('path');
|
5 | var eachModule = require('each-module');
|
6 |
|
7 | module.exports = function (config) {
|
8 | var filters = [];
|
9 |
|
10 | var modulePaths = config.modules.map(function (module) {
|
11 | return path.join(config.path.root, 'node_modules', module);
|
12 | });
|
13 | modulePaths.push(config.path.root);
|
14 | modulePaths.unshift(config.path.shunterRoot);
|
15 |
|
16 | modulePaths.forEach(function (modulePath) {
|
17 | var filterPath = path.join(modulePath, config.structure.filters, config.structure.filtersOutput);
|
18 | eachModule(filterPath, function (name, runFilter) {
|
19 | filters.push(runFilter);
|
20 | });
|
21 | });
|
22 |
|
23 | return function (content, contentType, req) {
|
24 | var output;
|
25 |
|
26 | for (var i = 0; filters[i]; ++i) {
|
27 | output = filters[i](content, contentType, req, config);
|
28 | if (typeof output === 'string') {
|
29 | content = output;
|
30 | }
|
31 | }
|
32 | return content;
|
33 | };
|
34 | };
|