Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 8f27e79

Browse files
author
New Geoff
committed
more reformatting and tweaks
1 parent 6db75a9 commit 8f27e79

File tree

5 files changed

+626
-633
lines changed

5 files changed

+626
-633
lines changed

builder/list_item_hunter.js

Lines changed: 110 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,115 @@
1-
/*
2-
* patternlab-node - v1.1.3 - 2016
3-
*
1+
/*
2+
* patternlab-node - v1.1.3 - 2016
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

11-
(function () {
12-
"use strict";
13-
14-
var list_item_hunter = function(){
15-
16-
var extend = require('util')._extend,
17-
pa = require('./pattern_assembler'),
18-
smh = require('./style_modifier_hunter'),
19-
mustache = require('mustache'),
20-
pattern_assembler = new pa(),
21-
style_modifier_hunter = new smh(),
22-
items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty'];
23-
24-
function processListItemPartials(pattern, patternlab){
25-
//find any listitem blocks
26-
var matches = pattern_assembler.find_list_items(pattern, patternlab);
27-
if(matches !== null){
28-
matches.forEach(function(liMatch, index, matches){
29-
30-
if(patternlab.config.debug){
31-
console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key);
32-
}
33-
34-
//find the boundaries of the block
35-
var loopNumberString = liMatch.split('.')[1].split('}')[0].trim();
36-
var end = liMatch.replace('#', '/');
37-
var patternBlock = pattern.template.substring(pattern.template.indexOf(liMatch) + liMatch.length, pattern.template.indexOf(end)).trim();
38-
//build arrays that repeat the block, however large we need to
39-
var repeatedBlockTemplate = [];
40-
var repeatedBlockHtml = '';
41-
for(var i = 0; i < items.indexOf(loopNumberString); i++){
42-
repeatedBlockTemplate.push(patternBlock);
43-
}
44-
45-
//check for a local listitems.json file
46-
var listData = JSON.parse(JSON.stringify(patternlab.listitems));
47-
listData = pattern_assembler.merge_data(listData, pattern.listitems);
48-
49-
//iterate over each copied block, rendering its contents along with pattenlab.listitems[i]
50-
for(var i = 0; i < repeatedBlockTemplate.length; i++){
51-
52-
var thisBlockTemplate = repeatedBlockTemplate[i];
53-
var thisBlockHTML = "";
54-
55-
//combine listItem data with pattern data with global data
56-
var itemData = listData['' + items.indexOf(loopNumberString)]; //this is a property like "2"
57-
var globalData = JSON.parse(JSON.stringify(patternlab.data));
58-
var localData = JSON.parse(JSON.stringify(pattern.jsonFileData));
59-
60-
var allData = pattern_assembler.merge_data(globalData, localData);
61-
allData = pattern_assembler.merge_data(allData, itemData != undefined ? itemData[i] : {}); //itemData could be undefined if the listblock contains no partial, just markup
62-
allData.link = extend({}, patternlab.data.link);
63-
64-
//check for partials within the repeated block
65-
var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate });
66-
67-
if(foundPartials && foundPartials.length > 0){
68-
69-
for(var j = 0; j < foundPartials.length; j++){
70-
71-
//get the partial
72-
var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0];
73-
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
74-
75-
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
76-
var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
77-
78-
//if partial has style modifier data, replace the styleModifier value
79-
if(foundPartials[j].indexOf(':') > -1){
80-
style_modifier_hunter.consume_style_modifier(cleanPartialPattern, foundPartials[j], patternlab);
81-
}
82-
83-
//replace its reference within the block with the extended template
84-
thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], cleanPartialPattern.extendedTemplate);
85-
}
86-
87-
//render with data
88-
thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials);
89-
90-
} else{
91-
//just render with mergedData
92-
thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials);
93-
}
94-
95-
//add the rendered HTML to our string
96-
repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML;
97-
}
98-
99-
//replace the block with our generated HTML
100-
var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length);
101-
pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml);
102-
103-
//update the extendedTemplate in the partials object in case this pattern is consumed later
104-
patternlab.partials[pattern.key] = pattern.extendedTemplate;
105-
106-
});
107-
}
108-
}
109-
110-
return {
111-
process_list_item_partials: function(pattern, patternlab){
112-
processListItemPartials(pattern, patternlab);
113-
}
114-
};
115-
116-
};
117-
118-
module.exports = list_item_hunter;
11911

120-
}());
12+
"use strict";
13+
14+
var list_item_hunter = function () {
15+
16+
var extend = require('util')._extend,
17+
pa = require('./pattern_assembler'),
18+
smh = require('./style_modifier_hunter'),
19+
pattern_assembler = new pa(),
20+
style_modifier_hunter = new smh(),
21+
items = [ 'zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen','twenty'];
22+
23+
function processListItemPartials(pattern, patternlab) {
24+
//find any listitem blocks
25+
var matches = pattern_assembler.find_list_items(pattern, patternlab);
26+
if (matches !== null) {
27+
matches.forEach(function (liMatch) {
28+
29+
if (patternlab.config.debug) {
30+
console.log('found listItem of size ' + liMatch + ' inside ' + pattern.key);
31+
}
32+
33+
//find the boundaries of the block
34+
var loopNumberString = liMatch.split('.')[1].split('}')[0].trim();
35+
var end = liMatch.replace('#', '/');
36+
var patternBlock = pattern.template.substring(pattern.template.indexOf(liMatch) + liMatch.length, pattern.template.indexOf(end)).trim();
37+
//build arrays that repeat the block, however large we need to
38+
var repeatedBlockTemplate = [];
39+
var repeatedBlockHtml = '';
40+
var i; // for loops
41+
42+
for (i = 0; i < items.indexOf(loopNumberString); i++) {
43+
repeatedBlockTemplate.push(patternBlock);
44+
}
45+
46+
//check for a local listitems.json file
47+
var listData = JSON.parse(JSON.stringify(patternlab.listitems));
48+
listData = pattern_assembler.merge_data(listData, pattern.listitems);
49+
50+
//iterate over each copied block, rendering its contents along with pattenlab.listitems[i]
51+
for (i = 0; i < repeatedBlockTemplate.length; i++) {
52+
var thisBlockTemplate = repeatedBlockTemplate[i];
53+
var thisBlockHTML = "";
54+
55+
//combine listItem data with pattern data with global data
56+
var itemData = listData['' + items.indexOf(loopNumberString)]; //this is a property like "2"
57+
var globalData = JSON.parse(JSON.stringify(patternlab.data));
58+
var localData = JSON.parse(JSON.stringify(pattern.jsonFileData));
59+
60+
var allData = pattern_assembler.merge_data(globalData, localData);
61+
allData = pattern_assembler.merge_data(allData, itemData !== undefined ? itemData[i] : {}); //itemData could be undefined if the listblock contains no partial, just markup
62+
allData.link = extend({}, patternlab.data.link);
63+
64+
//check for partials within the repeated block
65+
var foundPartials = pattern_assembler.find_pattern_partials({ 'template' : thisBlockTemplate });
66+
67+
if (foundPartials && foundPartials.length > 0) {
68+
for (var j = 0; j < foundPartials.length; j++) {
69+
//get the partial
70+
var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0];
71+
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
72+
73+
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
74+
var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
75+
76+
//if partial has style modifier data, replace the styleModifier value
77+
if (foundPartials[j].indexOf(':') > -1) {
78+
style_modifier_hunter.consume_style_modifier(cleanPartialPattern, foundPartials[j], patternlab);
79+
}
80+
81+
//replace its reference within the block with the extended template
82+
thisBlockTemplate = thisBlockTemplate.replace(foundPartials[j], cleanPartialPattern.extendedTemplate);
83+
}
84+
85+
//render with data
86+
thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials);
87+
} else {
88+
//just render with mergedData
89+
thisBlockHTML = pattern_assembler.renderPattern(thisBlockTemplate, allData, patternlab.partials);
90+
}
91+
92+
//add the rendered HTML to our string
93+
repeatedBlockHtml = repeatedBlockHtml + thisBlockHTML;
94+
}
95+
96+
//replace the block with our generated HTML
97+
var repeatingBlock = pattern.extendedTemplate.substring(pattern.extendedTemplate.indexOf(liMatch), pattern.extendedTemplate.indexOf(end) + end.length);
98+
pattern.extendedTemplate = pattern.extendedTemplate.replace(repeatingBlock, repeatedBlockHtml);
99+
100+
//update the extendedTemplate in the partials object in case this pattern is consumed later
101+
patternlab.partials[pattern.key] = pattern.extendedTemplate;
102+
103+
});
104+
}
105+
}
106+
107+
return {
108+
process_list_item_partials: function (pattern, patternlab) {
109+
processListItemPartials(pattern, patternlab);
110+
}
111+
};
112+
113+
};
114+
115+
module.exports = list_item_hunter;

builder/media_hunter.js

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,44 @@
88
*
99
*/
1010

11-
(function () {
12-
"use strict";
13-
14-
var diveSync = require('diveSync'),
15-
path = require('path'),
16-
fs = require('fs-extra');
17-
18-
var media_hunter = function(){
19-
20-
function findMediaQueries(dir, patternlab){
21-
patternlab.mediaQueries = [];
22-
23-
diveSync(dir, function(err, file){
24-
if(path.extname(file) === '.css'){
25-
var contents = fs.readFileSync(file, 'utf8');
26-
var safeContents = contents.replace("\r", " ").replace("\n", " ");
27-
var matches = safeContents.match(/\((min|max)-width:([ ]+)?(([0-9]{1,5})(\.[0-9]{1,20}|)(px|em))/g);
28-
for(var i = 0; i < matches.length; i++){
29-
var breakpoint = matches[i].substring(matches[i].indexOf(':') + 1).trimLeft();
30-
if(patternlab.mediaQueries.indexOf(breakpoint) === -1){
31-
patternlab.mediaQueries.push(breakpoint);
32-
}
33-
}
34-
}
35-
});
36-
patternlab.mediaQueries.sort(function(a,b){
37-
var integerPartA = a.match(/(?:\d*\.)?\d+/g);
38-
var integerPartB = b.match(/(?:\d*\.)?\d+/g);
39-
return parseInt(a,10) > parseInt(b,10);
40-
});
41-
}
42-
43-
return {
44-
find_media_queries: function(dir, patternlab){
45-
findMediaQueries(dir, patternlab);
46-
}
47-
};
48-
49-
};
50-
51-
module.exports = media_hunter;
52-
53-
}());
11+
"use strict";
12+
13+
var diveSync = require('diveSync'),
14+
path = require('path'),
15+
fs = require('fs-extra');
16+
17+
var media_hunter = function () {
18+
19+
function findMediaQueries(dir, patternlab) {
20+
patternlab.mediaQueries = [];
21+
22+
diveSync(dir, function (err, file) {
23+
if (path.extname(file) === '.css') {
24+
var contents = fs.readFileSync(file, 'utf8');
25+
var safeContents = contents.replace("\r", " ").replace("\n", " ");
26+
var matches = safeContents.match(/\((min|max)-width:([ ]+)?(([0-9]{1,5})(\.[0-9]{1,20}|)(px|em))/g);
27+
for (var i = 0; i < matches.length; i++) {
28+
var breakpoint = matches[i].substring(matches[i].indexOf(':') + 1).trimLeft();
29+
if (patternlab.mediaQueries.indexOf(breakpoint) === -1) {
30+
patternlab.mediaQueries.push(breakpoint);
31+
}
32+
}
33+
}
34+
});
35+
patternlab.mediaQueries.sort(function (a, b) {
36+
var integerPartA = a.match(/(?:\d*\.)?\d+/g);
37+
var integerPartB = b.match(/(?:\d*\.)?\d+/g);
38+
return parseInt(a, 10) > parseInt(b, 10);
39+
});
40+
}
41+
42+
return {
43+
find_media_queries: function (dir, patternlab) {
44+
findMediaQueries(dir, patternlab);
45+
}
46+
};
47+
48+
};
49+
50+
module.exports = media_hunter;
51+

0 commit comments

Comments
 (0)