Skip to content

Commit

Permalink
Merge pull request #21 from pattern-lab/nav-fixes
Browse files Browse the repository at this point in the history
Version 0.1.0
  • Loading branch information
Brian Muenzenmeyer committed Jan 21, 2014
2 parents 3700bd9 + 63029d9 commit 02834b6
Show file tree
Hide file tree
Showing 27 changed files with 2,024 additions and 1,456 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.

PL-node-v0.1.0
- FIX: Links to patterns did not work when visited from a server
- FIX: Patterns with hyphens in the name were breaking the iframe messaging
- FIX: Added stlyeguide/js files that were ignored at one point
- FIX: Watch _data/*.json files too
- FIX: Copy images, in an attempt to exclude files like Thumbs.db
- FIX: Typos in CHANGELOG
- ADD: A banner to patternlab.js

PL-node-v0.0.5
- FIX: type in organisms global header
- FIX: typo in organisms global header
- FIX: flat-structured pattern items rendered as if they had sub-menus #4
- ADD: Load all grunt tasks using matchdep
- THX: thanks to @colynb for the typo heads up
Expand All @@ -21,4 +30,4 @@ PL-node-v0.0.2
- FIX: Grunt watching styleguide scss

PL-node-v0.0.1
- Minimum Viable Product! At this point, I feel you could use Pattern Lab Node to build a atomic design-drive website.
- Minimum Viable Product! At this point, I feel you could use Pattern Lab Node to build an atomic design-driven website.
15 changes: 13 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: ['./public/patterns'],
concat: {
options: {
stripBanners: true,
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',
},
dist: {
src: './builder/patternlab.js',
dest: './builder/patternlab.js'
}
},
copy: {
main: {
files: [
{ expand: true, cwd: './source/js/', src: '*', dest: './public/js/'},
{ expand: true, cwd: './source/css/', src: 'style.css', dest: './public/css/' },
{ expand: true, cwd: './source/images/', src: ['*.png', '*.jpg', '*.gif', '*.jpeg'], dest: './public/images/' },
{ expand: true, cwd: './source/images/sample/', src: ['*.png', '*.jpg', '*.gif', '*.jpeg'], dest: './public/images/sample/'},
{ expand: true, cwd: './source/fonts/', src: '*', dest: './public/fonts/'}
{ expand: true, cwd: './source/fonts/', src: '*', dest: './public/fonts/'},
{ expand: true, cwd: './source/_data/', src: 'annotations.js', dest: './public/data/' }
]
}
},
Expand Down Expand Up @@ -63,5 +74,5 @@ module.exports = function(grunt) {
grunt.task.loadTasks('./builder/');

//if you choose to use scss, or any preprocessor, you can add it here
grunt.registerTask('default', ['clean', 'patternlab', /*'sass',*/ 'copy']);
grunt.registerTask('default', ['clean', 'concat', 'patternlab', /*'sass',*/ 'copy']);
};
56 changes: 39 additions & 17 deletions builder/patternlab.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* patternlab-node - v0.1.0 - 2014-01-21
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
*
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
*
*/

var path = require('path');

var oPattern = function(name, subdir, filename, data){
Expand All @@ -6,7 +16,7 @@ var oPattern = function(name, subdir, filename, data){
this.filename = filename;
this.data = data;
this.template = '';
this.patternOutput = '';
this.patternPartial = '';
this.patternName = ''; //this is the display name for the ui
this.patternLink = '';
this.patternGroup = name.substring(name.indexOf('-') + 1, name.indexOf('-', 4) + 1 - name.indexOf('-') + 1);
Expand Down Expand Up @@ -91,11 +101,15 @@ module.exports = function(grunt) {
currentPattern.template = grunt.file.read(abspath);

//render the pattern. pass partials object just in case.
currentPattern.patternOutput = mustache.render(currentPattern.template, patternlab.data, patternlab.partials);
currentPattern.patternPartial = mustache.render(currentPattern.template, patternlab.data, patternlab.partials);

//write the compiled template to the public patterns directory
flatPatternPath = currentPattern.name + '/' + currentPattern.name + '.html';
grunt.file.write('./public/patterns/' + flatPatternPath, patternlab.header + currentPattern.patternOutput + patternlab.footer);

//add footer info before writing
var currentPatternFooter = mustache.render(patternlab.footer, currentPattern);

grunt.file.write('./public/patterns/' + flatPatternPath, patternlab.header + currentPattern.patternPartial + currentPatternFooter);
currentPattern.patternLink = flatPatternPath;

//add as a partial in case this is referenced later. convert to syntax needed by existing patterns
Expand Down Expand Up @@ -126,12 +140,17 @@ module.exports = function(grunt) {
currentPattern.template = grunt.file.read(abspath);

//render the pattern. pass partials object just in case.
currentPattern.patternOutput = mustache.render(currentPattern.template, currentPattern.data, patternlab.partials);
currentPattern.patternPartial = mustache.render(currentPattern.template, currentPattern.data, patternlab.partials);
grunt.log.writeln('template compiled with data!');

//write the compiled template to the public patterns directory
flatPatternPath = currentPattern.name + '/' + currentPattern.name + '.html';
grunt.file.write('./public/patterns/' + flatPatternPath, patternlab.header + currentPattern.patternOutput + patternlab.footer);

//add footer info before writing
var currentPatternFooter = mustache.render(patternlab.footer, currentPattern);

grunt.file.write('./public/patterns/' + flatPatternPath, patternlab.header + currentPattern.patternPartial + currentPatternFooter);

currentPattern.patternLink = flatPatternPath;

//done
Expand Down Expand Up @@ -184,31 +203,32 @@ module.exports = function(grunt) {
//assume the navSubItem does not exist.
var navSubItem = new oNavSubItem(navSubItemName);
navSubItem.patternPath = pattern.patternLink;
navSubItem.patternPartial = bucketName + "-" + navSubItemName;
navSubItem.patternPartial = bucketName + "-" + pattern.patternName; //add the hyphenated name

//if it is flat - we should not add the pattern to patternPaths
if(flatPatternItem){
//grunt.log.writeln('flat source structure found for ' + navItemName + " " + bucketName);

//add the navItem to patternItems
bucket.patternItems.push(navSubItem);

//add to patternPaths
patternlab.patternPaths[bucketName][pattern.patternName] = pattern.subdir + "/" + pattern.filename.substring(0, pattern.filename.indexOf('.'));

} else{
//add the more complex nav items

bucket.navItems.push(navItem);
bucket.navItemsIndex.push(navItemName);
navItem.navSubItems.push(navSubItem);
navItem.navSubItemsIndex.push(navSubItemName);

//add to patternPaths
patternlab.patternPaths[bucketName][navSubItemName] = pattern.subdir + "/" + pattern.filename.substring(0, pattern.filename.indexOf('.'));
}
patternlab.patternPaths[bucketName][pattern.patternName] = pattern.subdir + "/" + pattern.filename.substring(0, pattern.filename.indexOf('.'));

}

//add the bucket.
patternlab.buckets.push(bucket);
patternlab.bucketIndex.push(bucketName);


//done

} else{
Expand All @@ -224,7 +244,7 @@ module.exports = function(grunt) {
//assume the navSubItem does not exist.
var navSubItem = new oNavSubItem(navSubItemName);
navSubItem.patternPath = pattern.patternLink;
navSubItem.patternPartial = bucketName + "-" + navSubItemName;
navSubItem.patternPartial = bucketName + "-" + pattern.patternName; //add the hyphenated name

//test whether the pattern struture is flat or not - usually due to a template or page
var flatPatternItem = false;
Expand All @@ -234,10 +254,13 @@ module.exports = function(grunt) {

//if it is flat - we should not add the pattern to patternPaths
if(flatPatternItem){
//grunt.log.writeln('flat source structure found for ' + navItemName + " " + bucketName);

//add the navItem to patternItems
bucket.patternItems.push(navSubItem);

//add to patternPaths
patternlab.patternPaths[bucketName][pattern.patternName] = pattern.subdir + "/" + pattern.filename.substring(0, pattern.filename.indexOf('.'));

} else{
//check to see if navItem exists
var navItemIndex = bucket.navItemsIndex.indexOf(navItemName);
Expand All @@ -258,12 +281,11 @@ module.exports = function(grunt) {
navItem.navSubItemsIndex.push(navSubItemName);
}

//add to patternPaths
patternlab.patternPaths[bucketName][navSubItemName] = pattern.subdir + "/" + pattern.filename.substring(0, pattern.filename.indexOf('.'));
// just add to patternPaths
patternlab.patternPaths[bucketName][pattern.patternName] = pattern.subdir + "/" + pattern.filename.substring(0, pattern.filename.indexOf('.'));

}


//check to see if this bucket has a View All yet. If not, add it.
// var navItem = bucket.navItems[navItemIndex];
// if(navItem){
Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "patternlab-node",
"version": "0.0.5",
"description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.0",
"grunt-contrib-nodeunit": "~0.1.2",
Expand All @@ -9,6 +10,16 @@
"grunt-contrib-copy": "~0.4.0",
"grunt-contrib-jshint": "~0.4.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-concat": "~0.3.0",
"matchdep": "~0.3.0"
}
},
"keywords": [
"Pattern Lab",
"Atomic Web Design",
"Node",
"Grunt",
"Javascript"
],
"author": "Brian Muenzenmeyer",
"license": "MIT"
}
Loading

0 comments on commit 02834b6

Please sign in to comment.