Skip to content

Commit a818d28

Browse files
committed
support for multiple classes on stylemodifier
closes #186
1 parent 3c3270a commit a818d28

File tree

5 files changed

+47
-19
lines changed

5 files changed

+47
-19
lines changed

CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.
22

33
PL-node-v0.15.1
44
- FIX: Resolve issue with styleModifiers not being replaced when the partial has spaces in it.
5-
- THX: Thanks @theorise for the issue report!
5+
- ADD: Support multiple styleModifier classes using the | pipe syntax
6+
- THX: Thanks @theorise for the issue reports!
67

78
PL-node-v0.15.0
89
- CHG: Updated package.json devDependencies for Node 4.X and 5.X support.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ Once rendered, it looks like this:
212212
</div>
213213
```
214214

215+
You may also specify multiple classes using a pipe character (|).
216+
217+
```
218+
{{> atoms-message:error|is-on }}
219+
```
215220

216221

217222

builder/pattern_assembler.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.15.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.15.1 - 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

@@ -24,19 +24,19 @@
2424

2525
// returns any patterns that match {{> value:mod }} or {{> value:mod(foo:"bar") }} within the pattern
2626
function findPartialsWithStyleModifiers(pattern){
27-
var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-_]+)+(?:(| )\(.*)?([ ])?}}/g);
27+
var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?!\()(\:[A-Za-z0-9-_|]+)+(?:(| )\(.*)?([ ])?}}/g);
2828
return matches;
2929
}
3030

3131
// returns any patterns that match {{> value(foo:"bar") }} or {{> value:mod(foo:"bar") }} within the pattern
3232
function findPartialsWithPatternParameters(pattern){
33-
var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)+([ ])?}}/g);
33+
var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)+([ ])?}}/g);
3434
return matches;
3535
}
3636

3737
//find and return any {{> template-name* }} within pattern
3838
function findPartials(pattern){
39-
var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_]+)?(?:(| )\(.*)?([ ])?}}/g);
39+
var matches = pattern.template.match(/{{>([ ])?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(| )\(.*)?([ ])?}}/g);
4040
return matches;
4141
}
4242

@@ -207,7 +207,7 @@
207207

208208
//do something with the regular old partials
209209
for(i = 0; i < foundPatternPartials.length; i++){
210-
var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z-_]+)?(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g, '$2');
210+
var partialKey = foundPatternPartials[i].replace(/{{>([ ])?([\w\-\.\/~]+)(:[A-z-_|]+)?(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g, '$2');
211211

212212
var partialPath;
213213

@@ -262,7 +262,7 @@
262262
throw 'Could not find pattern with key ' + key;
263263
}
264264

265-
265+
266266
function mergeData(obj1, obj2){
267267
if(typeof obj2 === 'undefined'){
268268
obj2 = {};

builder/style_modifier_hunter.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.15.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.15.1 - 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

@@ -16,9 +16,12 @@
1616
function consumestylemodifier(pattern, partial, patternlab){
1717

1818
//extract the classname from the stylemodifier which comes in the format of :className
19-
var styleModifier = partial.match(/:([\w\-_])+/g) ? partial.match(/:([\w\-_])+/g)[0].slice(1) : null;
19+
var styleModifier = partial.match(/:([\w\-_|])+/g) ? partial.match(/:([\w\-_|])+/g)[0].slice(1) : null;
2020
if(styleModifier){
2121

22+
//replace the special character pipe | used to separate multiple classes with a space
23+
styleModifier = styleModifier.replace(/\|/g, ' ');
24+
2225
if(patternlab.config.debug){
2326
console.log('found partial styleModifier within pattern ' + pattern.key);
2427
}

test/style_modifier_hunter_tests.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@
4242
test.equals(pattern.extendedTemplate, '<div class="foo bar"></div>');
4343
test.done();
4444
},
45+
'replaces multiple style modifiers' : function(test){
46+
//arrange
47+
var pl = {};
48+
pl.config = {};
49+
pl.config.debug = false;
50+
51+
var pattern = {
52+
extendedTemplate: '<div class="foo {{ styleModifier }}"></div>'
53+
};
54+
55+
var style_modifier_hunter = new smh();
56+
57+
//act
58+
style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl);
59+
60+
//assert
61+
test.equals(pattern.extendedTemplate, '<div class="foo bar baz dum"></div>');
62+
test.done();
63+
},
4564
'does not alter pattern extendedTemplate if styleModifier not found in partial' : function(test){
4665
//arrange
4766
var pl = {};

0 commit comments

Comments
 (0)