Commit e7f82e5c authored by Björn Bartels's avatar Björn Bartels 👩🏻
Browse files

added config checks, updated and added more tests

parent 888df487
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line

//
// @SOON: split up into testsass, testjs, testui
//
var fs          = require('fs');

module.exports = function(value, config, cb, pl) {
+9 −1
Original line number Diff line number Diff line
@@ -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" : "**",
@@ -121,6 +125,10 @@ var Patternlibrary_Defaults = {
    "sassdoc" : {
    },

    // internal JS Doc options
    "galen" : {
    },
    
    // internal Supercollider options
    "adapters" : {
    }/*,
+10 −10
Original line number Diff line number Diff line
@@ -6,13 +6,13 @@ 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._layoutTemplate = null;
	    this.time            = null;
	    
	    this.searchOptions   = {
@@ -26,7 +26,7 @@ class Patternlibrary {
	}
	
	/**
	 * resets/clears all data
	 * resets/clears all (pattern) data
	 */
	reset () {
	    this.data = {
+175 −6
Original line number Diff line number Diff line
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;
}
+23 −7
Original line number Diff line number Diff line
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'));
	// load optional custom Handlebars helpers
	if (this.options.helpers) {
		this.loadhelpers(this.options.helpers);
	}
	
	// init MarkdownIt and plugins
	this.markdown = require('../vendor/markdown-it');
	
	// set default doc parser adapters
	this.adapter('js')
	    .adapter('sass')
	    .adapter('specs')
Loading