Skip to content

Commit c7d0399

Browse files
committed
first half of list item support - constructing the list
1 parent d977b18 commit c7d0399

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

builder/pattern_assembler.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,34 @@
156156
return obj1;
157157
}
158158

159+
function buildListItems(patternlab){
160+
//combine all list items into one structure
161+
var list = [];
162+
for (var item in patternlab.listitems) {
163+
if( patternlab.listitems.hasOwnProperty(item)) {
164+
list.push(patternlab.listitems[item]);
165+
}
166+
}
167+
patternlab.listItemArray = shuffle(list);
168+
169+
for(var i = 1; i <= 12; i++){
170+
var top = i;
171+
var c = 1;
172+
var tempItems = [];
173+
while(c <= top){
174+
tempItems.push(patternlab.listItemArray[c]);
175+
c++;
176+
}
177+
patternlab.listitems['' + i ] = tempItems;
178+
}
179+
}
180+
181+
//http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript
182+
function shuffle(o){
183+
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
184+
return o;
185+
}
186+
159187
return {
160188
find_pattern_partials: function(pattern){
161189
return findPartials(pattern);
@@ -180,6 +208,9 @@
180208
},
181209
merge_data: function(existingData, newData){
182210
return mergeData(existingData, newData);
211+
},
212+
combine_listItems: function(patternlab){
213+
buildListItems(patternlab);
183214
}
184215
};
185216

builder/patternlab.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ var patternlab_engine = function () {
6868
pattern_exporter = new pe(),
6969
patterns_dir = './source/_patterns';
7070

71+
pattern_assembler.combine_listItems(patternlab);
72+
7173
diveSync(patterns_dir, {
7274
filter: function(path, dir) {
7375
if(dir){

0 commit comments

Comments
 (0)