diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/constants/configDefault.js | 6 | ||||
-rw-r--r-- | lib/models/config.js | 3 | ||||
-rw-r--r-- | lib/models/file.js | 9 | ||||
-rw-r--r-- | lib/parse/__tests__/parseGlossary.js | 37 | ||||
-rw-r--r-- | lib/parse/parseGlossary.js | 1 |
5 files changed, 54 insertions, 2 deletions
diff --git a/lib/constants/configDefault.js b/lib/constants/configDefault.js new file mode 100644 index 0000000..0d95883 --- /dev/null +++ b/lib/constants/configDefault.js @@ -0,0 +1,6 @@ +var Immutable = require('immutable'); +var jsonSchemaDefaults = require('json-schema-defaults'); + +var schema = require('./configSchema'); + +module.exports = Immutable.fromJS(jsonSchemaDefaults(schema)); diff --git a/lib/models/config.js b/lib/models/config.js index 8684a03..720ac57 100644 --- a/lib/models/config.js +++ b/lib/models/config.js @@ -2,10 +2,11 @@ var is = require('is'); var Immutable = require('immutable'); var File = require('./file'); +var configDefault = require('../constants/configDefault'); var Config = Immutable.Record({ file: File(), - values: Immutable.Map() + values: configDefault }, 'Config'); Config.prototype.getPath = function() { diff --git a/lib/models/file.js b/lib/models/file.js index b6b06ee..ff7b899 100644 --- a/lib/models/file.js +++ b/lib/models/file.js @@ -20,6 +20,15 @@ File.prototype.getMTime = function() { }; /** + Does the file exists / is set + + @return {Boolean} +*/ +File.prototype.exists = function() { + return Boolean(this.getPath()); +}; + +/** Return type of file ('markdown' or 'asciidoc') @return {String} diff --git a/lib/parse/__tests__/parseGlossary.js b/lib/parse/__tests__/parseGlossary.js new file mode 100644 index 0000000..1cb813c --- /dev/null +++ b/lib/parse/__tests__/parseGlossary.js @@ -0,0 +1,37 @@ +jest.autoMockOff(); + +describe('parseGlossary', function() { + var parseGlossary = require('../parseGlossary'); + var Book = require('../../models/book'); + var createMockFS = require('../../fs/mock'); + + pit('should parse glossary if exists', function() { + var fs = createMockFS({ + 'GLOSSARY.md': '# Glossary\n\n## Hello\nDescription for hello' + }); + var book = Book.createForFS(fs); + + return parseGlossary(book) + .then(function(resultBook) { + var glossary = resultBook.getGlossary(); + var file = glossary.getFile(); + var entries = glossary.getEntries(); + + expect(file.exists()).toBeTruthy(); + expect(entries.size).toBe(1); + }); + }); + + pit('should not fail if doesn\'t exist', function() { + var fs = createMockFS({}); + var book = Book.createForFS(fs); + + return parseGlossary(book) + .then(function(resultBook) { + var glossary = resultBook.getGlossary(); + var file = glossary.getFile(); + + expect(file.exists()).toBeFalsy(); + }); + }); +}); diff --git a/lib/parse/parseGlossary.js b/lib/parse/parseGlossary.js index 1dbfbe0..a96e5fc 100644 --- a/lib/parse/parseGlossary.js +++ b/lib/parse/parseGlossary.js @@ -16,7 +16,6 @@ function parseGlossary(book) { return book; } - logger.debug.ln('glossary index file found at', file.getPath()); var glossary = Glossary.createFromEntries(file, entries); |