Add base utils for generation

This commit is contained in:
Samy Pessé
2016-04-22 22:21:34 +02:00
parent 4f86a9978b
commit fb0ea4610d
21 changed files with 341 additions and 91 deletions
+33
View File
@@ -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();
});
});
});
+17
View File
@@ -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');
});
});
});
-13
View File
@@ -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;
+2 -4
View File
@@ -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);
};
+47
View File
@@ -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;