Skip to content

Commit aa521b9

Browse files
committed
Improvements to menu generation
closes #138 closes #160
1 parent 0c8a530 commit aa521b9

File tree

7 files changed

+76
-36
lines changed

7 files changed

+76
-36
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PL-node-v0.13.0
88
- THX: Thanks @e2tha-e for finding, fixing, and unit testing the data merge issue.
99
- ADD: Support for recursive partial inclusion
1010
- THX: Thanks @e2tha-e for making pattern inclusion a lot more robust. Great work!!!
11+
- FIX: Improvements to style guide menu generation and capitalization.
1112

1213
PL-node-v0.12.0
1314
- ADD: Gulp support arrives with an optional configuration

builder/object_factory.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.12.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.12.0 - 2015
3+
*
44
* 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.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -17,7 +17,10 @@
1717
this.subdir = subdir;
1818
this.name = subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName; //this is the unique name with the subDir
1919
this.jsonFileData = data || {};
20-
this.patternName = this.fileName.replace(/^\d*\-/, ''); //this is the display name for the ui. strip numeric + hyphen prefixes
20+
this.patternName = this.fileName.replace(/^\d*\-/, '');
21+
this.patternDisplayName = this.patternName.split('-').reduce(function(val, working){
22+
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
23+
}, '').trim(); //this is the display name for the ui. strip numeric + hyphen prefixes
2124
this.patternLink = this.name + '/' + this.name + '.html';
2225
this.patternGroup = this.name.substring(this.name.indexOf('-') + 1, this.name.indexOf('-', 4) + 1 - this.name.indexOf('-') + 1);
2326
this.patternSubGroup = subdir.substring(subdir.indexOf('/') + 4);
@@ -33,7 +36,9 @@
3336

3437
var oBucket = function(name){
3538
this.bucketNameLC = name;
36-
this.bucketNameUC = name.charAt(0).toUpperCase() + name.slice(1);
39+
this.bucketNameUC = name.split('-').reduce(function(val, working){
40+
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
41+
}, '').trim();
3742
this.navItems = [];
3843
this.navItemsIndex = [];
3944
this.patternItems = [];
@@ -42,15 +47,19 @@
4247

4348
var oNavItem = function(name){
4449
this.sectionNameLC = name;
45-
this.sectionNameUC = name.charAt(0).toUpperCase() + name.slice(1);
50+
this.sectionNameUC = name.split('-').reduce(function(val, working){
51+
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
52+
}, '').trim();
4653
this.navSubItems = [];
4754
this.navSubItemsIndex = [];
4855
};
4956

5057
var oNavSubItem = function(name){
5158
this.patternPath = '';
5259
this.patternPartial = '';
53-
this.patternName = name.charAt(0).toUpperCase() + name.slice(1);
60+
this.patternName = name.split(' ').reduce(function(val, working){
61+
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
62+
}, '').trim();
5463
};
5564

5665
module.exports = {

builder/pattern_assembler.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.12.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.12.0 - 2015
3+
*
44
* 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.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -113,7 +113,9 @@
113113
try {
114114
var jsonFilename = patternlab.config.patterns.source + currentPattern.subdir + '/' + currentPattern.fileName + ".json";
115115
currentPattern.jsonFileData = fs.readJSONSync(jsonFilename.substring(2));
116-
console.log('found pattern-specific data.json for ' + currentPattern.key);
116+
if(patternlab.config.debug){
117+
console.log('found pattern-specific data.json for ' + currentPattern.key);
118+
}
117119
}
118120
catch(e) {
119121
}
@@ -122,10 +124,12 @@
122124
try {
123125
var listJsonFileName = patternlab.config.patterns.source + currentPattern.subdir + '/' + currentPattern.fileName + ".listitems.json";
124126
currentPattern.patternSpecificListJson = fs.readJSONSync(listJsonFileName.substring(2));
125-
console.log('found pattern-specific listitems.json for ' + currentPattern.key);
127+
if(patternlab.config.debug){
128+
console.log('found pattern-specific listitems.json for ' + currentPattern.key);
129+
}
126130
}
127131
catch(e) {
128-
}
132+
}
129133

130134
//add the raw template to memory
131135
currentPattern.template = fs.readFileSync(file, 'utf8');

builder/patternlab.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ var patternlab_engine = function () {
217217
patternlab.viewAllPaths[bucketName] = {};
218218

219219
//get the navItem
220-
var navItemName = pattern.subdir.split('-').pop();
220+
var navItemName = pattern.subdir.split('/').pop();
221+
navItemName = navItemName.replace(/(\d).(-)/g, '');
221222

222223
//get the navSubItem
223224
var navSubItemName = pattern.patternName.replace(/-/g, ' ');

source/_patternlab-files/styleguide.mustache

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
<link rel="stylesheet" href="../../css/style.css" media="all" />
1010
</head>
1111
<body class="sg-pattern-list">
12-
12+
1313
<!-- Style Guide Main Content -->
1414
<div class="sg-main" role="main">
15-
15+
1616
<!-- Patterns -->
1717
<div id="sg-patterns">
1818
{{# partials }}
1919
<div class="sg-pattern">
20-
<h2 class="sg-pattern-head" ><a href="../../patterns/{{ patternLink }}" class="patternLink {{# patternState }}sg-pattern-state {{ . }}{{/ patternState }}" data-patternpartial="{{ patternPartialPath }}">{{ patternName }}</a></h2>
20+
<h2 class="sg-pattern-head" ><a href="../../patterns/{{ patternLink }}" class="patternLink {{# patternState }}sg-pattern-state {{ . }}{{/ patternState }}" data-patternpartial="{{ patternPartialPath }}">{{ patternDisplayName }}</a></h2>
2121
<div class="sg-pattern-body">
2222
{{{ patternPartial }}}
2323
<div class="sg-code" style="display: none">
2424
{{# patternLineageExists }}
2525
<div class="sg-code-contains">
26-
This pattern contains:
26+
This pattern contains:
2727
{{# patternLineages }}
2828
<a href="{{ lineagePath }}"><code>{{ lineagePattern }}</code><a>
2929
{{/ patternLineages }}
@@ -48,7 +48,7 @@
4848
</div>
4949
{{/ partials }}
5050
</div> <!--end #sg-patterns-->
51-
51+
5252
</div><!--End Style Guide Main Content-->
5353

5454
<!-- JS to hook everything together and do annotations -->
@@ -63,6 +63,6 @@
6363
<script src="../../styleguide/js/postmessage.js"></script>
6464
<script src="../../data/annotations.js"></script>
6565
<script src="../../styleguide/js/annotations-pattern.js"></script>
66-
<script src="../../styleguide/js/code-pattern.js"></script>
66+
<script src="../../styleguide/js/code-pattern.js"></script>
6767
</body>
68-
</html>
68+
</html>

source/_patternlab-files/viewall.mustache

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
<link rel="stylesheet" href="../../css/style.css" media="all" />
1010
</head>
1111
<body class="sg-pattern-list">
12-
12+
1313
<!-- View All Patterns in a Pattern Sub-Type -->
1414
<div class="sg-main" role="main">
15-
15+
1616
<!-- Patterns -->
1717
<div id="sg-patterns">
1818
{{# partials }}
1919
<div class="sg-pattern">
20-
<h2 class="sg-pattern-head" ><a href="../../patterns/{{ patternLink }}" class="patternLink" data-patternpartial="{{ patternPartialPath }}">{{ patternName }}</a></h2>
20+
<h2 class="sg-pattern-head" ><a href="../../patterns/{{ patternLink }}" class="patternLink" data-patternpartial="{{ patternPartialPath }}">{{ patternDisplayName }}</a></h2>
2121
<div class="sg-pattern-body">
2222
{{{ patternPartial }}}
2323
<div class="sg-code" style="display: none">
2424
{{# patternLineageExists }}
2525
<div class="sg-code-contains">
26-
This pattern contains:
26+
This pattern contains:
2727
{{# patternLineages }}
2828
<a href="{{ lineagePath }}"><code>{{ lineagePattern }}</code></a>
2929
{{/ patternLineages }}
@@ -48,9 +48,9 @@
4848
</div>
4949
{{/ partials }}
5050
</div> <!--end #sg-patterns-->
51-
51+
5252
</div><!--end .sg-main-->
53-
53+
5454
<!-- JS to hook everything together and do annotations -->
5555
<script>
5656
// handle injection of items from patternlab.js
@@ -63,6 +63,6 @@
6363
<script src="../../data/annotations.js"></script>
6464
<script src="../../styleguide/js/annotations-pattern.js"></script>
6565
<script src="../../styleguide/js/code-pattern.js"></script>
66-
66+
6767
</body>
68-
</html>
68+
</html>

test/object_factory_tests.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
test.equals(p.fileName, '00-colors');
1313
test.equals(p.jsonFileData.d, 123);
1414
test.equals(p.patternName, 'colors');
15+
test.equals(p.patternDisplayName, 'Colors');
1516
test.equals(p.patternLink, '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html');
1617
test.equals(p.patternGroup, 'atoms');
1718
test.equals(p.patternSubGroup, 'global');
@@ -24,6 +25,12 @@
2425
test.equals(p.lineageR.length, 0);
2526
test.equals(p.lineageRIndex.length, 0);
2627
test.done();
28+
},
29+
'test oPattern capitalizes patternDisplayName correctly' : function(test){
30+
var p = new of.oPattern('source/_patterns/00-atoms/00-global/00-colors-alt.mustache', '00-atoms/00-global', '00-colors-alt.mustache', { d: 123});
31+
test.equals(p.patternName, 'colors-alt');
32+
test.equals(p.patternDisplayName, 'Colors Alt');
33+
test.done();
2734
}
2835
};
2936

@@ -37,26 +44,44 @@
3744
test.equals(b.patternItems.length, 0);
3845
test.equals(b.patternItemsIndex.length, 0);
3946
test.done();
47+
},
48+
'test oBucket capitalizes bucketNameUC' : function(test){
49+
var b = new of.oBucket('page-templates');
50+
test.equals(b.bucketNameLC, 'page-templates');
51+
test.equals(b.bucketNameUC, 'Page Templates');
52+
test.done();
4053
}
4154
};
4255

4356
exports['oNavItem initialization'] = {
4457
'test oNavItem initializes correctly' : function(test){
4558
var ni = new of.oNavItem('test');
4659
test.equals(ni.sectionNameLC, 'test');
60+
test.equals(ni.sectionNameUC, 'Test');
4761
test.equals(ni.navSubItems.length, 0);
4862
test.equals(ni.navSubItemsIndex.length, 0);
4963
test.done();
64+
},
65+
'test oNavItem correctly capitalizes sectionNameUC' : function(test){
66+
var ni = new of.oNavItem('global-concepts');
67+
test.equals(ni.sectionNameLC, 'global-concepts');
68+
test.equals(ni.sectionNameUC, 'Global Concepts');
69+
test.done();
5070
}
5171
};
52-
72+
5373
exports['oSubNavItem initialization'] = {
5474
'test oSubNavItem initializes correctly' : function(test){
5575
var sni = new of.oNavSubItem('test');
5676
test.equals(sni.patternName, 'Test');
5777
test.equals(sni.patternPath, '');
5878
test.equals(sni.patternPartial, '');
5979
test.done();
80+
},
81+
'test oSubNavItem capitalizes patternName' : function(test){
82+
var sni = new of.oNavSubItem('nav button');
83+
test.equals(sni.patternName, 'Nav Button');
84+
test.done();
6085
}
6186
};
6287

0 commit comments

Comments
 (0)