fabricator-assemble
Advanced tools
Comparing version 0.1.3 to 0.1.5
25
index.js
@@ -357,3 +357,28 @@ // modules | ||
// get helper files | ||
var resolveHelper = path.join.bind(null, __dirname, 'helpers'); | ||
var localHelpers = fs.readdirSync(resolveHelper()); | ||
var userHelpers = options.helpers; | ||
// register local helpers | ||
localHelpers.map(function (helper) { | ||
var key = helper.match(/(^\w+?-)(.+)(\.\w+)/)[2]; | ||
var path = resolveHelper(helper); | ||
Handlebars.registerHelper(key, require(path)); | ||
}); | ||
// register user helpers | ||
for (var helper in userHelpers) { | ||
if (userHelpers.hasOwnProperty(helper)) { | ||
Handlebars.registerHelper(helper, userHelpers[helper]); | ||
} | ||
} | ||
/** | ||
* Helpers that require local functions like `buildContext()` | ||
*/ | ||
/** | ||
* `material` | ||
@@ -360,0 +385,0 @@ * @description Like a normal partial include (`{{> partialName }}`), |
{ | ||
"name": "fabricator-assemble", | ||
"version": "0.1.3", | ||
"version": "0.1.5", | ||
"description": "The assembly engine behind Fabricator", | ||
@@ -34,4 +34,5 @@ "main": "index.js", | ||
"del": "^1.1.1", | ||
"helper-markdown": "^0.1.1", | ||
"mocha": "^2.1.0" | ||
} | ||
} |
@@ -81,2 +81,3 @@ # Fabricator Assemble | ||
docs: 'src/docs/**/*.md', | ||
helpers: {}, | ||
dest: 'dist' | ||
@@ -135,2 +136,25 @@ } | ||
### options.helpers | ||
Type: `Object` | ||
Default: `{}` | ||
User-defined helpers. E.g.: | ||
```javascript | ||
helpers: { | ||
markdown: require('helper-markdown'), | ||
foo: function () { | ||
return 'bar'; | ||
} | ||
} | ||
``` | ||
### options.dest | ||
Type: `String` | ||
Default: `dist` | ||
Destination of compiled views (where files are saved to) | ||
## API | ||
@@ -137,0 +161,0 @@ |
@@ -18,3 +18,6 @@ var assert = require('assert'); | ||
docs: './test/fixtures/docs/**/*', | ||
dest: './test/output' | ||
dest: './test/output', | ||
helpers: { | ||
markdown: require('helper-markdown') | ||
} | ||
}; | ||
@@ -30,9 +33,10 @@ | ||
assemble(options).done(function (data) { | ||
var output = minify(fs.readFileSync('./test/output/index.html', 'utf-8'), { collapseWhitespace: true }); | ||
var expected = minify(fs.readFileSync('./test/expected/index.html', 'utf-8'), { collapseWhitespace: true }); | ||
assert.equal(output, expected); | ||
done(); | ||
}); | ||
assemble(options); | ||
var output = minify(fs.readFileSync('./test/output/index.html', 'utf-8'), { collapseWhitespace: true }); | ||
var expected = minify(fs.readFileSync('./test/expected/index.html', 'utf-8'), { collapseWhitespace: true }); | ||
assert.equal(output, expected); | ||
done(); | ||
}); | ||
@@ -43,9 +47,10 @@ | ||
assemble(options).done(function (data) { | ||
var output = minify(fs.readFileSync('./test/output/docs.html', 'utf-8'), { collapseWhitespace: true }); | ||
var expected = minify(fs.readFileSync('./test/expected/docs.html', 'utf-8'), { collapseWhitespace: true }); | ||
assert.equal(output, expected); | ||
done(); | ||
}); | ||
assemble(options); | ||
var output = minify(fs.readFileSync('./test/output/docs.html', 'utf-8'), { collapseWhitespace: true }); | ||
var expected = minify(fs.readFileSync('./test/expected/docs.html', 'utf-8'), { collapseWhitespace: true }); | ||
assert.equal(output, expected); | ||
done(); | ||
}); | ||
@@ -56,9 +61,10 @@ | ||
assemble(options).done(function (data) { | ||
var output = minify(fs.readFileSync('./test/output/pages/home.html', 'utf-8'), { collapseWhitespace: true }); | ||
var expected = minify(fs.readFileSync('./test/expected/home.html', 'utf-8'), { collapseWhitespace: true }); | ||
assert.equal(output, expected); | ||
done(); | ||
}); | ||
assemble(options); | ||
var output = minify(fs.readFileSync('./test/output/pages/home.html', 'utf-8'), { collapseWhitespace: true }); | ||
var expected = minify(fs.readFileSync('./test/expected/home.html', 'utf-8'), { collapseWhitespace: true }); | ||
assert.equal(output, expected); | ||
done(); | ||
}); | ||
@@ -69,14 +75,25 @@ | ||
assemble(options).done(function (data) { | ||
var output = minify(fs.readFileSync('./test/output/includes.html', 'utf-8'), { collapseWhitespace: true }); | ||
var expected = minify(fs.readFileSync('./test/expected/includes.html', 'utf-8'), { collapseWhitespace: true }); | ||
assert.equal(output, expected); | ||
done(); | ||
}); | ||
assemble(options); | ||
var output = minify(fs.readFileSync('./test/output/includes.html', 'utf-8'), { collapseWhitespace: true }); | ||
var expected = minify(fs.readFileSync('./test/expected/includes.html', 'utf-8'), { collapseWhitespace: true }); | ||
assert.equal(output, expected); | ||
done(); | ||
}); | ||
}); | ||
it('should assemble with helpers', function (done) { | ||
assemble(options); | ||
var output = minify(fs.readFileSync('./test/output/helpers.html', 'utf-8'), { collapseWhitespace: true }); | ||
var expected = minify(fs.readFileSync('./test/expected/helpers.html', 'utf-8'), { collapseWhitespace: true }); | ||
assert.equal(output, expected); | ||
done(); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25536
28
453
288
3
4