|
4 | 4 | var lih = require('../core/lib/list_item_hunter');
|
5 | 5 | var Pattern = require('../core/lib/object_factory').Pattern;
|
6 | 6 | var extend = require('util')._extend;
|
| 7 | + var pa = require('../core/lib/pattern_assembler'); |
| 8 | + var pattern_assembler = new pa(); |
7 | 9 |
|
8 | 10 | // fake pattern creators
|
9 | 11 | function createFakeListPattern(customProps) {
|
|
17 | 19 | }
|
18 | 20 |
|
19 | 21 | function createFakePatternLab(customProps) {
|
| 22 | + |
| 23 | + //NOTE: These listitems are faked so that pattern_assembler.combine_listitems has already clobbered them. |
| 24 | + |
20 | 25 | var pl = {
|
21 | 26 | "listitems": {
|
22 | 27 | "1": [
|
23 |
| - { "title": "Foo" } |
| 28 | + { |
| 29 | + "title": "Foo", |
| 30 | + "message": "FooM" |
| 31 | + } |
24 | 32 | ],
|
25 |
| - "2": [ |
26 |
| - { "title": "Foo" }, |
27 |
| - { "title": "Bar" } |
| 33 | + "2" : [ |
| 34 | + { |
| 35 | + "title": "Foo", |
| 36 | + "message": "FooM" |
| 37 | + }, |
| 38 | + { |
| 39 | + "title": "Bar", |
| 40 | + "message": "BarM" |
| 41 | + } |
| 42 | + ], |
| 43 | + "3": [ |
| 44 | + { |
| 45 | + "title": "Foo", |
| 46 | + "message": "FooM" |
| 47 | + }, |
| 48 | + { |
| 49 | + "title": "Bar", |
| 50 | + "message": "BarM" |
| 51 | + }, |
| 52 | + { |
| 53 | + "title": "Baz", |
| 54 | + "message": "BazM" |
| 55 | + }, |
28 | 56 | ]
|
29 | 57 | },
|
30 | 58 | "data": {
|
31 | 59 | "link": {},
|
32 | 60 | "partials": []
|
33 | 61 | },
|
34 |
| - "config": {"debug": false}, |
35 |
| - "partials" : {} |
| 62 | + "config": { |
| 63 | + "debug": false, |
| 64 | + "paths": { |
| 65 | + "source": { |
| 66 | + "patterns": "./test/files/_patterns" |
| 67 | + } |
| 68 | + } |
| 69 | + }, |
| 70 | + "partials" : {}, |
| 71 | + "patterns" : [] |
36 | 72 | };
|
37 | 73 |
|
38 | 74 | return extend(pl, customProps);
|
|
335 | 371 | var expectedValue = '<div class="test_group"> <span class="test_base "> Foo </span> <span class="test_base test_1"> Foo </span> <span class="test_base "> Foo </span> <span class="test_base "> Bar </span> <span class="test_base test_1"> Bar </span> <span class="test_base "> Bar </span> </div>';
|
336 | 372 | test.equals(bookendPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim());
|
337 | 373 | test.done();
|
338 |
| - } |
| 374 | + }, |
| 375 | + |
| 376 | + 'process_list_item_partials - correctly ignores already processed partial that had a style modifier when the same partial no longer has one' : function(test){ |
| 377 | + //arrange |
| 378 | + var fs = require('fs-extra'); |
| 379 | + var list_item_hunter = new lih(); |
| 380 | + |
| 381 | + var pl = createFakePatternLab(); |
| 382 | + |
| 383 | + var atomPattern = new Pattern('00-test/03-styled-atom.mustache'); |
| 384 | + atomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/03-styled-atom.mustache', 'utf8'); |
| 385 | + atomPattern.extendedTemplate = atomPattern.template; |
| 386 | + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); |
| 387 | + |
| 388 | + var anotherStyledAtomPattern = new Pattern('00-test/12-another-styled-atom.mustache'); |
| 389 | + anotherStyledAtomPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/12-another-styled-atom.mustache', 'utf8'); |
| 390 | + anotherStyledAtomPattern.extendedTemplate = anotherStyledAtomPattern.template; |
| 391 | + anotherStyledAtomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(anotherStyledAtomPattern); |
| 392 | + |
| 393 | + var listPattern = new Pattern('00-test/13-listitem.mustache'); |
| 394 | + listPattern.template = fs.readFileSync(pl.config.paths.source.patterns + '/00-test/13-listitem.mustache', 'utf8'); |
| 395 | + listPattern.extendedTemplate = listPattern.template; |
| 396 | + listPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(listPattern); |
| 397 | + |
| 398 | + pl.patterns.push(atomPattern); |
| 399 | + pl.patterns.push(anotherStyledAtomPattern); |
| 400 | + pl.patterns.push(listPattern); |
| 401 | + |
| 402 | + //act |
| 403 | + |
| 404 | + //might need to cal processPatternRecursive instead |
| 405 | + pattern_assembler.process_pattern_recursive(atomPattern.relPath, pl); |
| 406 | + pattern_assembler.process_pattern_recursive(anotherStyledAtomPattern.relPath, pl); |
| 407 | + pattern_assembler.process_pattern_recursive(listPattern.relPath, pl); |
| 408 | + |
| 409 | + //assert. |
| 410 | + var expectedValue = '<div class="test_group"> <span class="test_base "> FooM </span> </div>'; |
| 411 | + test.equals(listPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedValue.trim()); |
| 412 | + test.done(); |
| 413 | + }, |
339 | 414 |
|
340 | 415 | };
|
341 | 416 |
|
|
0 commit comments