diff options
Diffstat (limited to 'lib/models')
-rw-r--r-- | lib/models/__tests__/glossary.js | 33 | ||||
-rw-r--r-- | lib/models/__tests__/glossaryEntry.js | 17 | ||||
-rw-r--r-- | lib/models/generator.js | 13 | ||||
-rw-r--r-- | lib/models/glossaryEntry.js | 6 | ||||
-rw-r--r-- | lib/models/output.js | 47 |
5 files changed, 99 insertions, 17 deletions
diff --git a/lib/models/__tests__/glossary.js b/lib/models/__tests__/glossary.js new file mode 100644 index 0000000..0345627 --- /dev/null +++ b/lib/models/__tests__/glossary.js @@ -0,0 +1,33 @@ +jest.autoMockOff(); + +describe('Glossary', function() { + var File = require('../file'); + var Glossary = require('../glossary'); + var GlossaryEntry = require('../glossaryEntry'); + + describe('createFromEntries', function() { + var glossary = Glossary.createFromEntries(File(), [ + { + name: 'Hello World', + description: 'Awesome!' + }, + { + name: 'JavaScript', + description: 'This is a cool language' + } + ]); + + it('must add all entries', function() { + var entries = glossary.getEntries(); + expect(entries.size).toBe(2); + }); + + it('must add entries as GlossaryEntries', function() { + var entries = glossary.getEntries(); + var entry = entries.get('hello-world'); + expect(entry instanceof GlossaryEntry).toBeTruthy(); + }); + }); +}); + + diff --git a/lib/models/__tests__/glossaryEntry.js b/lib/models/__tests__/glossaryEntry.js new file mode 100644 index 0000000..9eabc68 --- /dev/null +++ b/lib/models/__tests__/glossaryEntry.js @@ -0,0 +1,17 @@ +jest.autoMockOff(); + +describe('GlossaryEntry', function() { + var GlossaryEntry = require('../glossaryEntry'); + + describe('getID', function() { + it('must return a normalized ID', function() { + var entry = new GlossaryEntry({ + name: 'Hello World' + }); + + expect(entry.getID()).toBe('hello-world'); + }); + }); +}); + + diff --git a/lib/models/generator.js b/lib/models/generator.js deleted file mode 100644 index afc65b1..0000000 --- a/lib/models/generator.js +++ /dev/null @@ -1,13 +0,0 @@ -var Immutable = require('immutable'); - -var Generator = Immutable.Record({ - name: String() -}); - - - -Generator.create = function(def) { - return new Generator(def); -}; - -module.exports = Generator; diff --git a/lib/models/glossaryEntry.js b/lib/models/glossaryEntry.js index 9c390c5..10791db 100644 --- a/lib/models/glossaryEntry.js +++ b/lib/models/glossaryEntry.js @@ -1,4 +1,5 @@ var Immutable = require('immutable'); +var slug = require('github-slugid'); /* A definition represents an entry in the glossary @@ -35,10 +36,7 @@ GlossaryEntry.prototype.getID = function() { @return {String} */ GlossaryEntry.nameToID = function nameToID(name) { - return name.toLowerCase() - .replace(/[\/\\\?\%\*\:\;\|\"\'\\<\\>\#\$\(\)\!\.\@]/g, '') - .replace(/ /g, '_') - .trim(); + return slug(name); }; diff --git a/lib/models/output.js b/lib/models/output.js new file mode 100644 index 0000000..957d9d3 --- /dev/null +++ b/lib/models/output.js @@ -0,0 +1,47 @@ +var Immutable = require('immutable'); + +var Book = require('./book'); + +var Output = Immutable.Record({ + book: Book(), + plugins: Immutable.OrderedMap(), + pages: Immutable.OrderedMap(), + assets: Immutable.List(), + options: Immutable.Map() +}); + +Output.prototype.getBook = function() { + return this.get('book'); +}; + +Output.prototype.getPlugins = function() { + return this.get('plugins'); +}; + +Output.prototype.getPages = function() { + return this.get('pages'); +}; + +Output.prototype.getOptions = function() { + return this.get('options'); +}; + +Output.prototype.getAssets = function() { + return this.get('assets'); +}; + +/** + Create an Output instance from a book and a set of options + + @param {Book} book + @param {Object} options + @return {Output} +*/ +Output.createForBook = function(book, options) { + return new Output({ + book: book, + options: options + }); +}; + +module.exports = Output; |