Skip to content

Commit 7a5fc0d

Browse files
committed
more tests. node refactor
started help logic started patterns only logic built out more tests and some file reorganization!
1 parent 3c975df commit 7a5fc0d

File tree

10 files changed

+195
-99
lines changed

10 files changed

+195
-99
lines changed

Gruntfile.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ module.exports = function(grunt) {
1212
stripBanners: true,
1313
banner: '/* \n * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %> \n * \n * <%= pkg.author %>, and the web community.\n * Licensed under the <%= pkg.license %> license. \n * \n * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. \n *\n */\n\n',
1414
},
15-
dist: {
15+
patternlab: {
1616
src: './builder/patternlab.js',
1717
dest: './builder/patternlab.js'
18+
},
19+
object_factory: {
20+
src: './builder/object_factory.js',
21+
dest: './builder/object_factory.js'
1822
}
1923
},
2024
copy: {
@@ -68,12 +72,8 @@ module.exports = function(grunt) {
6872
}
6973
}
7074
},
71-
qunit: {
72-
all:{
73-
options:{
74-
urls: ['./test/tests.html']
75-
}
76-
}
75+
nodeunit: {
76+
all: ['test/*_tests.js']
7777
}
7878
});
7979

@@ -87,5 +87,5 @@ module.exports = function(grunt) {
8787
grunt.registerTask('default', ['clean', 'concat', 'patternlab', /*'sass',*/ 'copy']);
8888

8989
//travis CI task
90-
grunt.registerTask('travis', ['clean', 'concat', 'patternlab', /*'sass',*/ 'copy', 'qunit'])
90+
grunt.registerTask('travis', ['clean', 'concat', 'patternlab', /*'sass',*/ 'copy', 'nodeunit'])
9191
};

builder/object_factory.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* patternlab-node - v0.1.1 - 2014-05-07
3+
*
4+
* Brian Muenzenmeyer, and the web community.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
8+
*
9+
*/
10+
11+
(function () {
12+
"use strict";
13+
14+
var oPattern = function(name, subdir, filename, data){
15+
this.name = name; //this is the unique name with the subDir
16+
this.subdir = subdir;
17+
this.filename = filename;
18+
this.data = data;
19+
this.template = '';
20+
this.patternPartial = '';
21+
this.patternName = ''; //this is the display name for the ui
22+
this.patternLink = '';
23+
this.patternGroup = name.substring(name.indexOf('-') + 1, name.indexOf('-', 4) + 1 - name.indexOf('-') + 1);
24+
this.patternSubGroup = subdir.substring(subdir.indexOf('/') + 4);
25+
this.flatPatternPath = subdir.replace(/\//g, '-');
26+
};
27+
28+
var oBucket = function(name){
29+
this.bucketNameLC = name;
30+
this.bucketNameUC = name.charAt(0).toUpperCase() + name.slice(1);
31+
this.navItems = [];
32+
this.navItemsIndex = [];
33+
this.patternItems = [];
34+
this.patternItemsIndex = [];
35+
};
36+
37+
var oNavItem = function(name){
38+
this.sectionNameLC = name;
39+
this.sectionNameUC = name.charAt(0).toUpperCase() + name.slice(1);
40+
this.navSubItems = [];
41+
this.navSubItemsIndex = [];
42+
};
43+
44+
var oNavSubItem = function(name){
45+
this.patternPath = '';
46+
this.patternPartial = '';
47+
this.patternName = name.charAt(0).toUpperCase() + name.slice(1);
48+
};
49+
50+
var oPatternItem = function(){
51+
this.patternPath = '';
52+
this.patternPartial = '';
53+
this.patternName = '';
54+
};
55+
56+
module.exports = {
57+
oPattern: oPattern,
58+
oBucket: oBucket,
59+
oNavItem: oNavItem,
60+
oNavSubItem: oNavSubItem,
61+
oPatternItem: oPatternItem
62+
};
63+
64+
}());

builder/pattern_assembler.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(function () {
2+
"use strict";
3+
4+
5+
}());

builder/patternlab.js

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v0.1.1 - 2014-05-06
2+
* patternlab-node - v0.1.1 - 2014-05-07
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -11,56 +11,20 @@
1111
var plnode = function(grunt){
1212
var path = require('path'),
1313
mustache = require('mustache'),
14+
of = require('./object_factory'),
15+
pa = require('./pattern_assembler'),
1416
patternlab = {};
1517

1618
patternlab.package = grunt.file.readJSON('package.json');
1719

18-
var oPattern = function(name, subdir, filename, data){
19-
this.name = name; //this is the unique name with the subDir
20-
this.subdir = subdir;
21-
this.filename = filename;
22-
this.data = data;
23-
this.template = '';
24-
this.patternPartial = '';
25-
this.patternName = ''; //this is the display name for the ui
26-
this.patternLink = '';
27-
this.patternGroup = name.substring(name.indexOf('-') + 1, name.indexOf('-', 4) + 1 - name.indexOf('-') + 1);
28-
this.patternSubGroup = subdir.substring(subdir.indexOf('/') + 4);
29-
this.flatPatternPath = subdir.replace(/\//g, '-');
30-
};
31-
32-
var oBucket = function(name){
33-
this.bucketNameLC = name;
34-
this.bucketNameUC = name.charAt(0).toUpperCase() + name.slice(1);
35-
this.navItems = [];
36-
this.navItemsIndex = [];
37-
this.patternItems = [];
38-
this.patternItemsIndex = [];
39-
};
40-
41-
var oNavItem = function(name){
42-
this.sectionNameLC = name;
43-
this.sectionNameUC = name.charAt(0).toUpperCase() + name.slice(1);
44-
this.navSubItems = [];
45-
this.navSubItemsIndex = [];
46-
};
47-
48-
var oNavSubItem = function(name){
49-
this.patternPath = '';
50-
this.patternPartial = '';
51-
this.patternName = name.charAt(0).toUpperCase() + name.slice(1);
52-
};
53-
54-
var oPatternItem = function(){
55-
this.patternPath = '';
56-
this.patternPartial = '';
57-
this.patternName = '';
58-
};
59-
6020
function getVersion() {
6121
grunt.log.ok(patternlab.package.version);
6222
}
6323

24+
function help(){
25+
grunt.log.ok('patternlab help coming soon');
26+
}
27+
6428
function build(){
6529

6630
patternlab.data = grunt.file.readJSON('./source/_data/data.json');
@@ -91,18 +55,18 @@ var plnode = function(grunt){
9155
//returns -1 if patterns does not exist, otherwise returns the index
9256
//add the pattern array if first time, otherwise pull it up
9357
if(patternIndex === -1){
94-
grunt.log.ok('pattern not found, adding to array');
58+
grunt.verbose.ok('pattern not found, adding to array');
9559
var flatPatternName = subdir.replace(/\//g, '-') + '-' + patternName;
9660
flatPatternName = flatPatternName.replace(/\//g, '-');
97-
currentPattern = new oPattern(flatPatternName, subdir, filename, {});
61+
currentPattern = new of.oPattern(flatPatternName, subdir, filename, {});
9862
currentPattern.patternName = patternName.substring(patternName.indexOf('-') + 1);
9963

10064
if(grunt.util._.str.include(filename, 'json')){
101-
grunt.log.writeln('json file found first, so add it to the pattern and continuing');
65+
grunt.verbose.ok('json file found first, so add it to the pattern and continuing');
10266
currentPattern.data = grunt.file.readJSON(abspath);
10367
//done
10468
} else{
105-
grunt.log.writeln('mustache file found, assume no data, so compile it right away');
69+
grunt.verbose.ok('mustache file found, assume no data, so compile it right away');
10670
currentPattern.template = grunt.file.read(abspath);
10771

10872
//render the pattern. pass partials object just in case.
@@ -138,15 +102,15 @@ var plnode = function(grunt){
138102
} else{
139103
//if we get here, we can almost ensure we found the json first, so render the template and pass in the unique json
140104
currentPattern = patternlab.patterns[patternIndex];
141-
grunt.log.ok('pattern found, loaded');
105+
grunt.verbose.ok('pattern found, loaded');
142106
//determine if this file is data or pattern
143107
if(grunt.util._.str.include(filename, 'mustache')){
144108

145109
currentPattern.template = grunt.file.read(abspath);
146110

147111
//render the pattern. pass partials object just in case.
148112
currentPattern.patternPartial = mustache.render(currentPattern.template, currentPattern.data, patternlab.partials);
149-
grunt.log.writeln('template compiled with data!');
113+
grunt.verbose.ok('template compiled with data!');
150114

151115
//write the compiled template to the public patterns directory
152116
flatPatternPath = currentPattern.name + '/' + currentPattern.name + '.html';
@@ -183,7 +147,7 @@ var plnode = function(grunt){
183147
var bucketIndex = patternlab.bucketIndex.indexOf(bucketName);
184148
if(bucketIndex === -1){
185149
//add the bucket
186-
var bucket = new oBucket(bucketName);
150+
var bucket = new of.oBucket(bucketName);
187151

188152
//add paternPath
189153
patternlab.patternPaths[bucketName] = {};
@@ -203,10 +167,10 @@ var plnode = function(grunt){
203167
}
204168

205169
//assume the navItem does not exist.
206-
var navItem = new oNavItem(navItemName);
170+
var navItem = new of.oNavItem(navItemName);
207171

208172
//assume the navSubItem does not exist.
209-
var navSubItem = new oNavSubItem(navSubItemName);
173+
var navSubItem = new of.oNavSubItem(navSubItemName);
210174
navSubItem.patternPath = pattern.patternLink;
211175
navSubItem.patternPartial = bucketName + "-" + pattern.patternName; //add the hyphenated name
212176

@@ -247,7 +211,7 @@ var plnode = function(grunt){
247211
var navSubItemName = pattern.patternName.replace(/-/g, ' ');
248212

249213
//assume the navSubItem does not exist.
250-
var navSubItem = new oNavSubItem(navSubItemName);
214+
var navSubItem = new of.oNavSubItem(navSubItemName);
251215
navSubItem.patternPath = pattern.patternLink;
252216
navSubItem.patternPartial = bucketName + "-" + pattern.patternName; //add the hyphenated name
253217

@@ -271,7 +235,7 @@ var plnode = function(grunt){
271235
var navItemIndex = bucket.navItemsIndex.indexOf(navItemName);
272236
if(navItemIndex === -1){
273237

274-
var navItem = new oNavItem(navItemName);
238+
var navItem = new of.oNavItem(navItemName);
275239

276240
//add the navItem and navSubItem
277241
navItem.navSubItems.push(navSubItem);
@@ -344,6 +308,12 @@ var plnode = function(grunt){
344308
},
345309
build: function(){
346310
build();
311+
},
312+
help: function(){
313+
help();
314+
},
315+
build_patterns_only: function(){
316+
grunt.log.ok('only_patterns argument not yet implemented');
347317
}
348318
};
349319

@@ -352,14 +322,28 @@ var plnode = function(grunt){
352322
module.exports = plnode;
353323

354324
module.exports = function(grunt) {
355-
grunt.registerTask('patternlab', 'create design systems with atomic design', function(v) {
325+
grunt.registerTask('patternlab', 'create design systems with atomic design', function(arg) {
356326

357327
var pl = plnode(grunt);
358328

359-
if(v && v === 'v'){
360-
pl.version();
361-
} else{
329+
if(arguments.length === 0){
362330
pl.build();
331+
}
332+
333+
if(arg && arg === 'v'){
334+
pl.version();
335+
}
336+
337+
if(arg && arg === "only_patterns"){
338+
pl.build_patterns_only();
339+
}
340+
341+
if(arg && arg === "help"){
342+
pl.help();
343+
}
344+
345+
if(arg && (arg !== "v" && arg !=="only_patterns")){
346+
pl.help();
363347
}
364348

365349
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"grunt-contrib-jshint": "~0.4.0",
1111
"grunt-contrib-clean": "~0.5.0",
1212
"grunt-contrib-concat": "~0.3.0",
13-
"grunt-contrib-qunit": "~0.4.0",
13+
"grunt-contrib-nodeunit": "~0.3.0",
1414
"mustache": "~0.8.1",
1515
"matchdep": "~0.3.0"
1616
},

test/object_factory_tests.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
(function () {
2+
"use strict";
3+
4+
var of = require('../builder/object_factory');
5+
6+
exports['oPattern initialization'] = {
7+
'test oPattern initializes correctly' : function(test){
8+
var p = new of.oPattern('00-atoms-00-global-00-colors', '00-atoms/00-global', 'file.txt', { d: 123});
9+
test.equals(p.name, '00-atoms-00-global-00-colors');
10+
test.equals(p.subdir, '00-atoms/00-global');
11+
test.equals(p.filename, 'file.txt');
12+
test.equals(p.data.d, 123);
13+
test.equals(p.template, '');
14+
test.equals(p.patternPartial, '');
15+
test.equals(p.patternName, '');
16+
test.equals(p.patternLink, '');
17+
test.equals(p.patternGroup, 'atoms');
18+
test.equals(p.patternSubGroup, 'global');
19+
test.equals(p.flatPatternPath, '00-atoms-00-global');
20+
test.done();
21+
}
22+
};
23+
24+
exports['oBucket initialization'] = {
25+
'test oBucket initializes correctly' : function(test){
26+
var b = new of.oBucket('test');
27+
test.equals(b.bucketNameLC, 'test');
28+
test.equals(b.bucketNameUC, 'Test');
29+
test.equals(b.navItems.length, 0);
30+
test.equals(b.navItemsIndex.length, 0);
31+
test.equals(b.patternItems.length, 0);
32+
test.equals(b.patternItemsIndex.length, 0);
33+
test.done();
34+
}
35+
};
36+
37+
exports['oNavItem initialization'] = {
38+
'test oNavItem initializes correctly' : function(test){
39+
var ni = new of.oNavItem('test');
40+
test.equals(ni.sectionNameLC, 'test');
41+
test.equals(ni.navSubItems.length, 0);
42+
test.equals(ni.navSubItemsIndex.length, 0);
43+
test.done();
44+
}
45+
};
46+
47+
exports['oSubNavItem initialization'] = {
48+
'test oSubNavItem initializes correctly' : function(test){
49+
var sni = new of.oNavSubItem('test');
50+
test.equals(sni.patternName, 'Test');
51+
test.equals(sni.patternPath, '');
52+
test.equals(sni.patternPartial, '');
53+
test.done();
54+
}
55+
};
56+
57+
exports['oPatternItem initialization'] = {
58+
'test oPatternItem initializes correctly' : function(test){
59+
var pi = new of.oPatternItem();
60+
test.equals(pi.patternName, '');
61+
test.equals(pi.patternPath, '');
62+
test.equals(pi.patternPartial, '');
63+
test.done();
64+
}
65+
};
66+
67+
}());

test/patternlab_tests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
exports['test nodeunit'] = {
4+
'hello world' : function(test){
5+
test.equals(1,1);
6+
test.done();
7+
}
8+
};

0 commit comments

Comments
 (0)