Issues (117)

lib/patternlibrary/build-gui.js (2 issues)

Severity
1 1
var path = require('path');
2 1
var mkdirp = require('mkdirp');
3 1
var globAll         = require('glob-all');
4 1
var resolvePath     = require('../util/module-or-process-path');
5 1
var sanatizeType = require('../util/sanatize-patterntype');
6
7
/**
8
 * Builds dashboard page
9
 * @returns
10
 */
11
function dashboard () {
12
    this.pagetemplate = this.options.gui.dashboard;
13
    var target = path.join(this.options.basepath, 'index.html');
14
    var source = path.join(this.options.gui.pages, this.options.basepath, this.options.gui.dashboard);
15
    this.renderpage(source, target);
16
    this.log.process("dashboard page", null, process.hrtime(this.time));	
17
}
18
19
/**
20
 * Builds category index pages
21
 * @returns
22
 */
23
function categories () {
24
    this.pagetemplate = this.options.gui.categorylist;
25
    
26
    var source = path.join(this.options.gui.pages, this.options.basepath, this.options.gui.categorylist);
27
    var target = path.join(this.options.basepath, this.options.categoriespath, 'index.html');
28
    this.renderpage(source, target);
29
    
30
    var categories = this.listcategories();
31
    this.pagetemplate = this.options.gui.patternlist;
32
    source = path.join(this.options.gui.pages, this.options.basepath, this.options.gui.patternlist);
33
    for (var cat in categories) {
0 ignored issues
show
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
34
        target = path.join(this.options.basepath, this.options.categoriespath, categories[cat].slug, 'index.html');
35
        mkdirp(path.dirname(target));
36
        this.renderpage(source, target, {
37
        	patternlist: this.listpatterns(categories[cat].slug)
38
        });
39
    }
40
41
    this.log.process("category index pages", null, process.hrtime(this.time));
42
}
43
44
/**
45
 * Builds pattern index list pages
46
 * @returns
47
 */
48
function patternlists () {
49
    this.pagetemplate = this.options.gui.patternlist;
50
    
51
    // main pattern index (all patterns)
52
    var target = path.join(this.options.basepath, this.options.patternspath, this.options.gui.patternlist);
53
    var source = path.join(this.options.gui.pages, this.options.basepath, this.options.gui.patternlist);
54
    this.renderpage(source, target);
55
56
    var patterntypes = ['atom','molecule','organism','templates','pages'];
57
    for (var i in patterntypes) {
0 ignored issues
show
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
58
        target = path.join(this.options.basepath, this.options.patternspath, sanatizeType(patterntypes[i]+'/', true), 'index.html');
59
        mkdirp(path.dirname(target));
60
        this.renderpage(source, target, {
61
        	patternlist: this.listpatterns(patterntypes[i])
62
        });
63
    }
64
    
65
    this.log.process("pattern index list pages", null, process.hrtime(this.time));
66
}
67
68
/**
69
 * Builds patternlibrary help pages
70
 * @returns
71
 */
72
function helpdocs () {
73
74
	var _this = this;
75
	// build patternlibrary help pages
76
    var helppages = this.buildpages(globAll.sync(
77
    	[path.join(resolvePath(this.options.gui.pages),'pl/{help,pages}/**/*.{md,markdown,html,hbs,handlebars}')]
78
    ), path.join(this.options.dest, this.options.basepath));
79
    helppages.on('finish', function () {
80
		_this.log.process('help pages', _this.data, process.hrtime(_this.time));
81
	});
82
    
83
84
}
85
86
87
/**
88
 * Builds GUI pages...
89
 */
90 1
module.exports = function () {
91
	
92
    // set gui layout
93
    this.layout       = this.options.gui.layout;
94
    
95
	// dashboard
96
    this.buildgui.dashboard.apply(this);
97
    
98
    // categories
99
    this.buildgui.categories.apply(this);
100
101
	// pattern indexes
102
    this.buildgui.patternlists.apply(this);
103
104
	// patternlibrary help
105
    this.buildgui.helpdocs.apply(this);
106
107
	
108
};
109
110 1
module.exports.dashboard    = dashboard;
111 1
module.exports.categories   = categories;
112 1
module.exports.patternlists = patternlists;
113 1
module.exports.helpdocs     = helpdocs;
114
115