aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-01-07 22:29:04 +0000
committerMichael Williamson <mike@zwobble.org>2014-01-07 22:29:04 +0000
commitbfc33eec2b0a22e4bb0ee2412ec22df636134330 (patch)
tree065db6da90cbdc17ddc85d38e2f8e8303dc33ee1
parentbc6e9ac4ee638fdc11019c979e3f03b9d7098e3f (diff)
Append standard style map to custom style map
-rw-r--r--lib/options-reader.js23
-rw-r--r--tests/options-reader.tests.js13
2 files changed, 32 insertions, 4 deletions
diff --git a/lib/options-reader.js b/lib/options-reader.js
index 3cac969..fa215f4 100644
--- a/lib/options-reader.js
+++ b/lib/options-reader.js
@@ -28,13 +28,28 @@ var standardOptions = exports._standardOptions = {
function readOptions(options) {
options = options || {};
- if (options.styleMap && _.isString(options.styleMap)) {
- options.styleMap = options.styleMap.split("\n").map(function(line) {
+ var fullOptions = extend(standardOptions, options);
+
+ fullOptions.styleMap = readStyleMap(options).concat(standardOptions.styleMap);
+
+ return fullOptions;
+}
+
+function readStyleMap(options) {
+ var customStyleMap = readCustomStyleMap(options.styleMap);
+ return customStyleMap;
+}
+
+function readCustomStyleMap(styleMap) {
+ if (!styleMap) {
+ return [];
+ } else if (_.isString(styleMap)) {
+ return styleMap.split("\n").map(function(line) {
return style(line.trim());
});
+ } else {
+ return styleMap;
}
-
- return extend(standardOptions, options);
}
diff --git a/tests/options-reader.tests.js b/tests/options-reader.tests.js
index d493ae6..073b3a5 100644
--- a/tests/options-reader.tests.js
+++ b/tests/options-reader.tests.js
@@ -1,5 +1,6 @@
var assert = require("assert");
+var style = require("../").style;
var optionsReader = require("../lib/options-reader");
var standardOptions = optionsReader._standardOptions;
var readOptions = optionsReader.readOptions;
@@ -13,4 +14,16 @@ describe('readOptions', function() {
it('standard options are used if options is empty', function() {
assert.deepEqual(standardOptions, readOptions({}));
});
+
+ it('custom style mappings are prepended to standard style mappings', function() {
+ var options = readOptions({
+ styleMap: "p.SectionTitle => h2"
+ });
+ assert.deepEqual(style("p.SectionTitle => h2"), options.styleMap[0]);
+ assert.deepEqual(standardOptions.styleMap, options.styleMap.slice(1));
+ });
});
+
+function last(array) {
+ return array[array.length - 1];
+}