|
1 | | -/* |
2 | | - * patternlab-node - v0.14.0 - 2015 |
3 | | - * |
| 1 | +/* |
| 2 | + * patternlab-node - v0.14.0 - 2015 |
| 3 | + * |
4 | 4 | * 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. |
8 | 8 | * |
9 | 9 | */ |
10 | 10 |
|
11 | 11 | (function () { |
12 | 12 | "use strict"; |
13 | 13 |
|
| 14 | + var patternEngines = require('./pattern_engines/pattern_engines'); |
| 15 | + var path = require('path'); |
| 16 | + var fs = require('fs-extra'); |
| 17 | + var config = fs.readJSONSync('./config.json'); |
| 18 | + var extend = require('util')._extend; |
| 19 | + |
| 20 | + // oPattern properties |
| 21 | + |
14 | 22 | var oPattern = function(abspath, subdir, filename, data){ |
| 23 | + if (config.debug) { |
| 24 | + console.log('=== NEW OPATTERN.', '\nabsPath:', abspath, '\nsubdir:', subdir, '\nfilename:', filename, '\ndata:\n', data); |
| 25 | + } |
15 | 26 | this.fileName = filename.substring(0, filename.indexOf('.')); |
| 27 | + this.fileExtension = path.extname(abspath); |
16 | 28 | this.abspath = abspath; |
17 | 29 | this.subdir = subdir; |
18 | 30 | this.name = subdir.replace(/[\/\\]/g, '-') + '-' + this.fileName; //this is the unique name with the subDir |
|
32 | 44 | this.lineageIndex = []; |
33 | 45 | this.lineageR = []; |
34 | 46 | this.lineageRIndex = []; |
| 47 | + this.isPseudoPattern = false; |
| 48 | + this.engine = patternEngines.getEngineForPattern(this); |
| 49 | + }; |
| 50 | + |
| 51 | + // oPattern methods |
| 52 | + |
| 53 | + // render method on oPatterns; this acts as a proxy for the PatternEngine's |
| 54 | + // render function |
| 55 | + oPattern.prototype.render = function (data, partials) { |
| 56 | + if (config.debug && this.isPseudoPattern) { |
| 57 | + console.log('===', this.name + ' IS A PSEUDO-PATTERN ==='); |
| 58 | + } |
| 59 | + return this.engine.renderPattern(this.extendedTemplate, data, partials); |
| 60 | + }; |
| 61 | + // the finders all delegate to the PatternEngine, which also encapsulates all |
| 62 | + // appropriate regexes |
| 63 | + oPattern.prototype.findPartials = function () { |
| 64 | + return this.engine.findPartials(this); |
| 65 | + }; |
| 66 | + oPattern.prototype.findPartialsWithStyleModifiers = function () { |
| 67 | + return this.engine.findPartialsWithStyleModifiers(this); |
| 68 | + }; |
| 69 | + oPattern.prototype.findPartialsWithPatternParameters = function () { |
| 70 | + return this.engine.findPartialsWithPatternParameters(this); |
35 | 71 | }; |
| 72 | + oPattern.prototype.findListItems = function () { |
| 73 | + return this.engine.findListItems(this); |
| 74 | + }; |
| 75 | + |
| 76 | + // oPattern static methods |
| 77 | + |
| 78 | + // factory: creates an empty oPattern for miscellaneous internal use, such as |
| 79 | + // by list_item_hunter |
| 80 | + oPattern.createEmpty = function (customProps) { |
| 81 | + var pattern = new oPattern('', '', '', null); |
| 82 | + return extend(pattern, customProps); |
| 83 | + }; |
| 84 | + |
| 85 | + // factory: creates an oPattern object on-demand from a hash; the hash accepts |
| 86 | + // parameters that replace the positional parameters that the oPattern |
| 87 | + // constructor takes. |
| 88 | + oPattern.create = function (abspath, subdir, filename, data, customProps) { |
| 89 | + var newPattern = new oPattern(abspath || '', subdir || '', filename || '', data || null); |
| 90 | + return extend(newPattern, customProps); |
| 91 | + }; |
| 92 | + |
36 | 93 |
|
37 | 94 | var oBucket = function(name){ |
38 | 95 | this.bucketNameLC = name; |
|
45 | 102 | this.patternItemsIndex = []; |
46 | 103 | }; |
47 | 104 |
|
| 105 | + |
48 | 106 | var oNavItem = function(name){ |
49 | 107 | this.sectionNameLC = name; |
50 | 108 | this.sectionNameUC = name.split('-').reduce(function(val, working){ |
|
54 | 112 | this.navSubItemsIndex = []; |
55 | 113 | }; |
56 | 114 |
|
| 115 | + |
57 | 116 | var oNavSubItem = function(name){ |
58 | 117 | this.patternPath = ''; |
59 | 118 | this.patternPartial = ''; |
|
62 | 121 | }, '').trim(); |
63 | 122 | }; |
64 | 123 |
|
| 124 | + |
65 | 125 | module.exports = { |
66 | 126 | oPattern: oPattern, |
67 | 127 | oBucket: oBucket, |
68 | 128 | oNavItem: oNavItem, |
69 | 129 | oNavSubItem: oNavSubItem |
70 | 130 | }; |
71 | 131 |
|
72 | | -}()); |
| 132 | +})(); |
0 commit comments