|
364 | 364 | //assert
|
365 | 365 | var expectedCleanValue = '<span class="test_base {{styleModifier}}"> {{message}} </span>';
|
366 | 366 | var expectedSetValue = '<span class="test_base test_1"> {{message}} </span>';
|
367 |
| - test.equals(anotherPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedSetValue.trim()); |
| 367 | + |
| 368 | + //this is the "atom" - it should remain unchanged |
368 | 369 | test.equals(atomPattern.template.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedCleanValue.trim());
|
369 | 370 | test.equals(atomPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedCleanValue.trim());
|
| 371 | + |
| 372 | + // this is the style modifier pattern, which should resolve correctly |
| 373 | + test.equals(anotherPattern.template.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), '{{> test-styled-atom:test_1 }}'); |
| 374 | + test.equals(anotherPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedSetValue.trim()); |
| 375 | + |
| 376 | + test.done(); |
| 377 | + }, |
| 378 | + 'processPatternRecursive - ensure deep-nesting works' : function(test){ |
| 379 | + //arrange |
| 380 | + var fs = require('fs-extra'); |
| 381 | + var pattern_assembler = new pa(); |
| 382 | + var patterns_dir = './test/files/_patterns'; |
| 383 | + |
| 384 | + var pl = {}; |
| 385 | + pl.config = { |
| 386 | + paths: { |
| 387 | + source: { |
| 388 | + patterns: patterns_dir |
| 389 | + } |
| 390 | + }, |
| 391 | + outputFileSuffixes: { |
| 392 | + rendered : '' |
| 393 | + } |
| 394 | + }; |
| 395 | + pl.data = {}; |
| 396 | + pl.data.link = {}; |
| 397 | + pl.config.debug = false; |
| 398 | + pl.patterns = []; |
| 399 | + pl.partials = {}; |
| 400 | + |
| 401 | + var atomPattern = new Pattern('00-test/01-bar.mustache'); |
| 402 | + atomPattern.template = fs.readFileSync(patterns_dir + '/00-test/01-bar.mustache', 'utf8'); |
| 403 | + atomPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(atomPattern); |
| 404 | + atomPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(atomPattern); |
| 405 | + |
| 406 | + var templatePattern = new Pattern('00-test/00-foo.mustache'); |
| 407 | + templatePattern.template = fs.readFileSync(patterns_dir + '/00-test/00-foo.mustache', 'utf8'); |
| 408 | + templatePattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(templatePattern); |
| 409 | + templatePattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(templatePattern); |
| 410 | + |
| 411 | + var pagesPattern = new Pattern('00-test/14-inception.mustache'); |
| 412 | + pagesPattern.template = fs.readFileSync(patterns_dir + '/00-test/14-inception.mustache', 'utf8'); |
| 413 | + pagesPattern.stylePartials = pattern_assembler.find_pattern_partials_with_style_modifiers(pagesPattern); |
| 414 | + pagesPattern.parameteredPartials = pattern_assembler.find_pattern_partials_with_parameters(pagesPattern); |
| 415 | + |
| 416 | + pattern_assembler.addPattern(atomPattern, pl); |
| 417 | + pattern_assembler.addPattern(templatePattern, pl); |
| 418 | + pattern_assembler.addPattern(pagesPattern, pl); |
| 419 | + |
| 420 | + //act |
| 421 | + pattern_assembler.process_pattern_recursive('00-test' + path.sep + '14-inception.mustache', pl, {}); |
| 422 | + |
| 423 | + //assert |
| 424 | + var expectedCleanValue = 'bar'; |
| 425 | + var expectedSetValue = 'bar'; |
| 426 | + |
| 427 | + //this is the "atom" - it should remain unchanged |
| 428 | + test.equals(atomPattern.template.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedCleanValue); |
| 429 | + test.equals(atomPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedCleanValue); |
| 430 | + |
| 431 | + //this is the "template pattern" - it should have an updated extendedTemplate but an unchanged template |
| 432 | + test.equals(templatePattern.template.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), '{{> test-bar }}'); |
| 433 | + test.equals(templatePattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedSetValue.trim()); |
| 434 | + |
| 435 | + //this is the "pages pattern" - it should have an updated extendedTemplate equal to the template pattern but an unchanged template |
| 436 | + test.equals(pagesPattern.template.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), '{{> test-foo }}'); |
| 437 | + test.equals(pagesPattern.extendedTemplate.replace(/\s\s+/g, ' ').replace(/\n/g, ' ').trim(), expectedSetValue.trim()); |
370 | 438 | test.done();
|
371 | 439 | },
|
372 | 440 | 'setState - applies any patternState matching the pattern' : function(test){
|
|
0 commit comments