Skip to content

Commit c98ee1c

Browse files
committed
fixed an assumption in media hunter that was causing a media query with no spaces to break the MQ Nav. closes #98
1 parent fc3cf72 commit c98ee1c

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ latest-change.txt
1313
patternlab.json
1414
.sass-cache/*
1515
/sass-cache
16-
source/images/Thumbs.db
16+
source/images/Thumbs.db
17+
public/styleguide/css/static.css.map
18+
public/styleguide/css/styleguide-specific.css.map
19+
public/styleguide/css/styleguide.css.map
20+
source/css/style.css.map

builder/media_hunter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
var safeContents = contents.replace("\r", " ").replace("\n", " ");
2727
var matches = safeContents.match(/\((min|max)-width:([ ]+)?(([0-9]{1,5})(\.[0-9]{1,20}|)(px|em))/g);
2828
for(var i = 0; i < matches.length; i++){
29-
var breakpoint = matches[i].substring(matches[i].indexOf(' ') + 1);
29+
var breakpoint = matches[i].substring(matches[i].indexOf(':') + 1).trimLeft();
3030
if(patternlab.mediaQueries.indexOf(breakpoint) === -1){
3131
patternlab.mediaQueries.push(breakpoint);
3232
}

source/css/scss/base/_global-classes.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
}
8181
}
8282

83+
.hide-large-2 {
84+
@media all and (min-width:$bp-large-2) {
85+
display: none;
86+
}
87+
}
88+
8389
//
8490
.valid {
8591
color: $valid;

test/media_hunter_tests.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
var MediaHunter = require('../builder/media_hunter');
55

6-
exports['media_query hunter '] = {
6+
//all tests here run against the shipped code, and as such altering any of that can break these tests
7+
//these tests are intended to catch development regressions. one should not have a need to run tests during patternlab use.
8+
9+
exports['media_query hunter basic support '] = {
710
'test media hunter finds query' : function(test){
811

912
//setup pl object
@@ -12,7 +15,47 @@
1215

1316
mh.find_media_queries(pl);
1417

15-
test.equals(pl.mediaQueries.length, 6);
18+
test.equals(pl.mediaQueries.length, 7);
19+
20+
test.done();
21+
}
22+
};
23+
24+
exports['media_query hunter spaces '] = {
25+
'test media hunter supports spaces in media query' : function(test){
26+
27+
//setup pl object
28+
var pl = {};
29+
var mh = new MediaHunter();
30+
31+
mh.find_media_queries(pl);
32+
33+
test.equals(pl.mediaQueries[0], '24em');
34+
35+
test.done();
36+
}
37+
};
38+
39+
exports['media_query hunter no spaces '] = {
40+
'test media hunter supports nospaces in media query' : function(test){
41+
42+
//setup pl object
43+
var pl = {};
44+
var mh = new MediaHunter();
45+
46+
mh.find_media_queries(pl);
47+
48+
//the last media query found in the shipped suite does not have a space
49+
//you can see this here:
50+
51+
//./source/css/scss/base/_global-classes.scss
52+
// .hide-large-2 {
53+
// @media all and (min-width:$bp-large-2) {
54+
// display: none;
55+
// }
56+
// }
57+
58+
test.equals(pl.mediaQueries[6], '66em');
1659

1760
test.done();
1861
}

0 commit comments

Comments
 (0)