mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-04 04:21:33 +00:00
Add base utils for generation
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user