Commit e7f82e5c authored by Björn Bartels's avatar Björn Bartels

added config checks, updated and added more tests

parent 888df487
//
// @SOON: split up into testsass, testjs, testui
//
var fs = require('fs');
module.exports = function(value, config, cb, pl) {
......
......@@ -47,8 +47,12 @@ var Patternlibrary_Defaults = {
"readme" : "{readme,info}.{md,markdown}", // "*.md", // {readme,info}.{md,markdown}
"javascript" : "*.js", // {index,module}
"scss" : "*.{scss,sass,css}", // {style,styles,pattern}
"tests" : "{test,tests,visual,visualtest,visualtests}.js",
"changelog" : "changelog.{md,markdown}",
"tests" : "{test,tests,visual,visualtest,visualtests}.js",
// @SOON:...
"testsass" : "test.sass.js",
"testjs" : "test.javascript.js",
"testui" : "{test.visual.js,*.gspec}",
// search sub-path, default '**' = all sub-paths
"searchpath" : "**",
......@@ -120,6 +124,10 @@ var Patternlibrary_Defaults = {
// internal JS Doc options
"sassdoc" : {
},
// internal JS Doc options
"galen" : {
},
// internal Supercollider options
"adapters" : {
......
......@@ -6,16 +6,16 @@ var resolvePath = require('./util/module-or-process-path');
class Patternlibrary {
constructor (opts) {
this.options = {};
this.adapters = {};
this.handlebars = null;
this.markdown = null;
this.template = null;
this.time = null;
this.options = {};
this.adapters = {};
this.handlebars = null;
this.markdown = null;
this.template = null;
this._layoutTemplate = null;
this.time = null;
this.searchOptions = {
this.searchOptions = {
extra : [],
sort : [],
pageTypes : {}
......@@ -26,7 +26,7 @@ class Patternlibrary {
}
/**
* resets/clears all data
* resets/clears all (pattern) data
*/
reset () {
this.data = {
......
var extend = require('util')._extend;
//var extend = require('util')._extend;
var extend = require('deep-extend');
var fs = require('fs');
var path = require('path');
var fm = require('front-matter');
/**
* checks for pattern doc options
* @param {Patternlibrary} $pl
* @returns
*/
function checkBase ( $pl ) {
// patterns dir
if (!$pl.options.partials || ($pl.options.partials == '')) {
throw new Error('To generate pattern documentation a source "partials" path option must be set.');
}
// destination dir
if (!$pl.options.dest || ($pl.options.dest == '')) {
throw new Error('A destination directory "dest" option must be set.');
}
// serving basepath
if (!$pl.options.basepath || ($pl.options.basepath == '')) {
throw new Error('An URL "basepath" sub-path option must be set.');
}
// serving patterns sub-path
if (!$pl.options.patternspath || ($pl.options.patternspath == '')) {
throw new Error('An URL "patternspath" sub-path option must be set.');
}
// serving categories sub-path
if (!$pl.options.categoriespath || ($pl.options.categoriespath == '')) {
throw new Error('An URL "categoriespath" sub-path option must be set.');
}
}
/**
* checks for patterns options
* @param {Patternlibrary} $pl
* @returns
*/
function checkPatterns ( $pl ) {
if (!$pl.options.pattern) {
throw new Error('The pattern\'s options must be defined.');
}
if (!$pl.options.pattern.dirs) {
throw new Error('The patterns\' "dirs" sub-path option must be set.');
}
if (!$pl.options.pattern.dirs.atoms) {
throw new Error('The patterns\' "atoms" sub-path option must be set.');
}
if (!$pl.options.pattern.dirs.molecules) {
throw new Error('The patterns\' "molecules" sub-path option must be set.');
}
if (!$pl.options.pattern.dirs.organisms) {
throw new Error('The patterns\' "molecules" sub-path option must be set.');
}
if (!$pl.options.pattern.dirs.templates) {
throw new Error('The patterns\' "molecules" sub-path option must be set.');
}
if (!$pl.options.pattern.dirs.pages) {
throw new Error('The patterns\' "molecules" sub-path option must be set.');
}
if (!$pl.options.pattern.searchpath) {
throw new Error('The patterns\' "searchpath" sub-path pattern option must be set.');
}
if (!$pl.options.pattern.target) {
throw new Error('The patterns\' "target" filename option must be set.');
}
}
/**
* checks for patterns default doc adapter search-patterns options
* @param {Patternlibrary} $pl
* @returns
*/
function checkPatternsAdapterPatterns ( $pl ) {
if (!$pl.options.pattern.source) {
throw new Error('The patterns\' default adapter "source" search pattern option must be set.');
}
if (!$pl.options.pattern.readme) {
throw new Error('The patterns\' default adapter "readme" search pattern option must be set.');
}
if (!$pl.options.pattern.scss) {
throw new Error('The patterns\' default adapter "scss" search pattern option must be set.');
}
if (!$pl.options.pattern.javascript) {
throw new Error('The patterns\' default adapter "javascript" search pattern option must be set.');
}
if (!$pl.options.pattern.tests) {
throw new Error('The patterns\' default adapter "tests" search pattern option must be set.');
}
if (!$pl.options.pattern.changelog) {
throw new Error('The patterns\' default adapter "changelog" search pattern option must be set.');
}
}
/**
* checks for gui options
* @param {Patternlibrary} $pl
* @returns
*/
function checkGUI ( $pl ) {
if ($pl.options.nogui !== false) {
if (!$pl.options.gui) {
throw new Error('GUI options must be defined.');
}
if (!$pl.options.gui.pages) {
throw new Error('To generate GUI a source "pages" path option must be set.');
}
if (!$pl.options.gui.partials) {
throw new Error('To generate GUI a source "partials" path option must be set.');
}
if (!$pl.options.gui.layouts) {
throw new Error('To generate GUI a source "layouts" path option must be set.');
}
if (!$pl.options.gui.layout) {
throw new Error('To generate GUI a default "layout" template option must be set.');
}
if (!$pl.options.gui.docpage) {
throw new Error('To generate GUI a default "docpage" template option must be set.');
}
if (!$pl.options.gui.dashboard) {
throw new Error('To generate GUI a default "dashboard" template option must be set.');
}
if (!$pl.options.gui.patternlist) {
throw new Error('To generate GUI a default "patternlist" template option must be set.');
}
if (!$pl.options.gui.categorylist) {
throw new Error('To generate GUI a default "categorylist" template option must be set.');
}
}
}
/**
* checks for static pages options
* @param {Patternlibrary} $pl
* @returns
*/
function checkStaticPages ( $pl ) {
if ($pl.options.staticpages !== false) {
if (!$pl.options.root) {
throw new Error('To generate static pages a source "root" path option must be set.');
}
if (!$pl.options.layouts) {
throw new Error('To generate static pages a source "layouts" path option must be set.');
}
}
}
module.exports = function(opts) {
if (!opts) {
opts = {};
}
this.options = extend(this.options, {
data : {},
pageRoot : process.cwd()
}, opts);
checkBase(this);
checkPatterns(this);
checkPatternsAdapterPatterns(this);
checkGUI(this);
checkStaticPages(this);
// initialises doc page as body-partial and compiled template
if (this.options.pattern.layout) {
if (this.options.pattern.docpage) {
/*if (this.options.gui.layout) {
if (this.options.gui.docpage) {
try {
var pagefile = path.join(this.options.root, this.options.basepath, this.options.pattern.docpage);
var pageSource = fs.readFileSync(pagefile);
......@@ -35,7 +204,7 @@ module.exports = function(opts) {
}
} else {
throw new Error('No path to a layout was set in Patternlibrary.config().');
}
}*/
return this;
}
var extend = require('extend');
var extend = require('deep-extend');
var path = require('path');
// initialize stuff...
/**
* initializes core components and set options
*
* - Handlebars instance and helpers
* - MarkdownIt instance and plugins
* - default doc parser adapters
* - logger
*
*/
module.exports = function (opts) {
if (!opts) {
opts = {};
}
this._layoutTemplate = null;
this.options = extend({}, require('../config/defaults'), opts);
// set default options
this.options = extend(this.options, require('../config/defaults'), opts);
this.config();
// init logger
this.log = require('../util/log');
this.log.options = this.options;
// init Handlebars
this.handlebars = require('../vendor/handlebars');
//this.loadhelpers(path.join(__dirname,'../handlebars'));
this.loadhelpers(this.options.helpers);
// load optional custom Handlebars helpers
if (this.options.helpers) {
this.loadhelpers(this.options.helpers);
}
this.markdown = require('../vendor/markdown-it');
// init MarkdownIt and plugins
this.markdown = require('../vendor/markdown-it');
// set default doc parser adapters
this.adapter('js')
.adapter('sass')
.adapter('specs')
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,7 +4,7 @@
"description": "a tiny flat file pattern-library generator",
"main": "index.js",
"scripts": {
"test": "mocha --compilers js:babel-register",
"test": "mocha --require babel-register",
"dev": "gulp",
"build": "gulp",
"demo": "gulp --demo"
......@@ -14,7 +14,7 @@
"bin": {},
"dependencies": {
"assert-dir-equal": "^1",
"chalk": "^2.3.2",
"chalk": "^2",
"cheerio": "^0.22",
"coveralls": "^3",
"curl": "^0.1",
......@@ -22,6 +22,7 @@
"deep-extend": "^0.5",
"front-matter": "^2",
"fs-extra": "^5",
"galenframework": "^2",
"glob": "^7",
"handlebars": "^4",
"highlight.js": "^9",
......
import Patternlibrary from '..';
var extend = require('deep-extend');
var expect = require('chai').expect;
describe('Patternlibrary constructor', function() {
it('creates a new instance of Patternlibrary', function() {
var p = new Patternlibrary.Patternlibrary();
expect(p).to.be.an.instanceOf(Patternlibrary.Patternlibrary);
});
describe('Patternlibrary instanciation and configuration:', function() {
it('sets blank defaults for config settings', function() {
var p = new Patternlibrary.Patternlibrary();
describe('Patternlibrary constructor', function() {
it('creates a new instance of Patternlibrary', function() {
var p = new Patternlibrary.Patternlibrary();
expect(p).to.be.an.instanceOf(Patternlibrary.Patternlibrary);
});
it('sets blank defaults for config settings', function() {
var p = new Patternlibrary.Patternlibrary();
expect(p.options).to.be.an('object');
expect(p.searchOptions).to.be.an('object');
expect(p.searchOptions).to.have.all.keys(['extra', 'sort', 'pageTypes']);
expect(p.adapters).to.be.an('object');
expect(p.data).to.be.an('object');
expect(p.data.patterns).to.be.an('object');
expect(p.data.categories).to.be.an('object');
expect(p.template).to.be.null;
});
});
describe('Patternlibrary.config()', function() {
var defaults = require('../lib/config/defaults');
it('merges default and user configuration objects', function() {
var p = new Patternlibrary.Patternlibrary();
p.config({
'my-key': 'my-value',
somekey : 'some value'
});
expect(p.options).to.be.an('object');
expect(p.options).to.have.a.property('my-key');
expect(p.options['my-key']).to.equal('my-value');
expect(p.options).to.have.a.property('somekey');
expect(p.options.somekey).to.equal('some value');
});
it('throws error if the "partials" source path option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.partials = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the destination directory "dest" option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.dest = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the URL "basepath" sub-path option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.basepath = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the URL "patternspath" sub-path option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.patternspath = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the URL "categoriespath" sub-path option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.categoriespath = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the pattern\'s "pattern" option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the pattern\'s "dirs" option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.dirs = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the pattern\'s "atoms" sub-path option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.dirs.atoms = '';
console.log('pattern dirs', cfg.pattern);
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the pattern\'s "molecules" sub-path option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.dirs.molecules = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the pattern\'s "organisms" sub-path option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.dirs.organisms = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the pattern\'s "templates" sub-path option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.dirs.templates = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the pattern\'s "pages" sub-path option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.dirs.pages = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the pattern\'s "searchpath" sub-path pattern option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.searchpath = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
it('throws error if the pattern\'s "target" filename option is missing', function() {
var p = new Patternlibrary.Patternlibrary();
var cfg = extend({}, defaults);
cfg.pattern.target = null;
expect(function() {
p.config(cfg);
}).to.throw(Error);
});
});
describe('Patternlibrary.adapter()', function() {
it('loads built-in adapters', function() {
var p = new Patternlibrary.Patternlibrary();
p = p.adapter('sass');
expect(p).to.be.an.instanceOf(Patternlibrary.Patternlibrary);
expect(p.adapters).to.have.a.property('sass');
expect(p.adapters.sass.config).to.exist;
});
it('throws an error if you try to load a non-existant built-in adapter', function() {
var p = new Patternlibrary.Patternlibrary();
expect(function() {
p.adapter('kitten');
}).to.throw(Error);
});
it('loads custom adapters', function() {
var p = new Patternlibrary.Patternlibrary();
p = p.adapter('custom', function() {});
expect(p.adapters).to.have.a.property('custom');
expect(p.adapters.custom).to.be.a('function');
});
it('throws an error if you use a reserved keyword as an adapter name', function() {
var p = new Patternlibrary.Patternlibrary();
expect(function() {
p.adapter('docs', function() {});
}).to.throw(Error);
});
it('throws an error if you try to pass something other than a function as an adapter', function() {
var s = new Patternlibrary.Patternlibrary();
expect(function() {
p.adapter('docs', 'kittens');
}).to.throw(Error);
});
});
expect(p.options).to.be.an('object');
expect(p.searchOptions).to.be.an('object');
expect(p.searchOptions).to.have.all.keys(['extra', 'sort', 'pageTypes']);
expect(p.adapters).to.be.an('object');
expect(p.data).to.be.an('object');
expect(p.template).to.be.null;
});
});
import Patternlibrary from '..';
var expect = require('chai').expect;
describe('Patternlibrary.adapter()', function() {
it('loads built-in adapters', function() {
var p = new Patternlibrary.Patternlibrary();
p = p.adapter('sass');
expect(p).to.be.an.instanceOf(Patternlibrary.Patternlibrary);
expect(p.adapters).to.have.a.property('sass');
expect(p.adapters.sass.config).to.exist;
});
it('throws an error if you try to load a non-existant built-in adapter', function() {
var p = new Patternlibrary.Patternlibrary();
expect(function() {
p.adapter('kitten');
}).to.throw(Error);
});
it('loads custom adapters', function() {
var p = new Patternlibrary.Patternlibrary();
p = p.adapter('custom', function() {});
expect(p.adapters).to.have.a.property('custom');
expect(p.adapters.custom).to.be.a('function');
});
it('throws an error if you use a reserved keyword as an adapter name', function() {
var p = new Patternlibrary.Patternlibrary();
expect(function() {
p.adapter('docs', function() {});
}).to.throw(Error);
});
it('throws an error if you try to pass something other than a function as an adapter', function() {
var s = new Patternlibrary.Patternlibrary();
expect(function() {
p.adapter('docs', 'kittens');
}).to.throw(Error);
});
});
import { src, dest } from 'vinyl-fs';
import assert from 'assert';
//import assert from 'assert';
import equal from 'assert-dir-equal';
import Patternlibrary from '..';
import rimraf from 'rimraf';
......@@ -18,7 +18,7 @@ var patternlibraryOptions = {
}
describe('Patternlibrary, the basic page genarator, ', () => {
describe('Patternlibrary static page genarator:', () => {
beforeEach(function(done) {
this.timeout(5000); // A very long environment setup.
......@@ -359,7 +359,7 @@ describe('Patternlibrary, assigning', () => {
});
/*
describe('Patternlibrary built-in', () => {
it('#code helper that renders code blocks', function (done) {
......@@ -509,4 +509,4 @@ describe('Patternlibrary built-in', () => {
});
});
*/
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment