1
1
/*
2
- * mustache pattern engine for patternlab-node - v2.X.X - 2016
2
+ * react pattern engine for patternlab-node - v0.1.0 - 2016
3
3
*
4
4
* Geoffrey Pursell, Brian Muenzenmeyer, and the web community.
5
5
* Licensed under the MIT license.
13
13
*
14
14
* Full + extensions. Partial calls and lineage hunting are supported. Style
15
15
* modifiers and pattern parameters are used to extend the core feature set of
16
- * Mustache templates.
16
+ * React templates.
17
17
*
18
18
*/
19
19
20
20
"use strict" ;
21
21
22
- var Mustache = require ( 'mustache' ) ;
23
- var utilMustache = require ( './util_mustache' ) ;
22
+ var React = { } ;
24
23
25
- var engine_mustache = {
26
- engine : Mustache ,
27
- engineName : 'mustache ' ,
28
- engineFileExtension : '.mustache ' ,
24
+ var engine_react = {
25
+ engine : React ,
26
+ engineName : 'react ' ,
27
+ engineFileExtension : '.jsx ' ,
29
28
30
- // partial expansion is only necessary for Mustache templates that have
29
+ // partial expansion is only necessary for React templates that have
31
30
// style modifiers or pattern parameters (I think)
32
- expandPartials : true ,
31
+ expandPartials : false ,
33
32
34
33
// regexes, stored here so they're only compiled once
35
- findPartialsRE : utilMustache . partialsRE ,
36
- findPartialsWithStyleModifiersRE : utilMustache . partialsWithStyleModifiersRE ,
37
- findPartialsWithPatternParametersRE : utilMustache . partialsWithPatternParametersRE ,
38
- findListItemsRE : utilMustache . listItemsRE ,
39
- findPartialRE : utilMustache . partialRE ,
34
+ findPartialsRE : null ,
35
+ findPartialsWithStyleModifiersRE : null ,
36
+ findPartialsWithPatternParametersRE : null ,
37
+ findListItemsRE : null ,
38
+ findPartialRE : null ,
40
39
41
40
// render it
42
41
renderPattern : function renderPattern ( pattern , data , partials ) {
43
42
try {
44
- if ( partials ) {
45
- return Mustache . render ( pattern . extendedTemplate , data , partials ) ;
46
- }
47
- return Mustache . render ( pattern . extendedTemplate , data ) ;
43
+ return "hey! this should be react, yeah" ;
48
44
} catch ( e ) {
49
- debugger ;
50
- console . log ( "e = " , e ) ;
45
+ console . log ( "e = " , e ) ;
46
+ return "" ;
51
47
}
52
48
} ,
53
49
@@ -70,48 +66,32 @@ var engine_mustache = {
70
66
71
67
// find and return any {{> template-name }} within pattern
72
68
findPartials : function findPartials ( pattern ) {
73
- var matches = this . patternMatcher ( pattern , this . findPartialsRE ) ;
74
- return matches ;
69
+ return [ ] ;
75
70
} ,
76
71
findPartialsWithStyleModifiers : function ( pattern ) {
77
- var matches = this . patternMatcher ( pattern , this . findPartialsWithStyleModifiersRE ) ;
78
- return matches ;
72
+ return [ ] ;
79
73
} ,
80
74
81
75
// returns any patterns that match {{> value(foo:"bar") }} or {{>
82
76
// value:mod(foo:"bar") }} within the pattern
83
77
findPartialsWithPatternParameters : function ( pattern ) {
84
- var matches = this . patternMatcher ( pattern , this . findPartialsWithPatternParametersRE ) ;
85
- return matches ;
78
+ return [ ] ;
86
79
} ,
87
80
findListItems : function ( pattern ) {
88
- var matches = this . patternMatcher ( pattern , this . findListItemsRE ) ;
89
- return matches ;
81
+ return [ ] ;
90
82
} ,
91
83
92
84
// given a pattern, and a partial string, tease out the "pattern key" and
93
85
// return it.
94
86
findPartial_new : function ( partialString ) {
95
- var partial = partialString . replace ( this . findPartialRE , '$1' ) ;
96
- return partial ;
87
+ return [ ] ;
97
88
} ,
98
89
99
90
// GTP: the old implementation works better. We might not need
100
91
// this.findPartialRE anymore if it works in all cases!
101
92
findPartial : function ( partialString ) {
102
- //strip out the template cruft
103
- var foundPatternPartial = partialString . replace ( "{{> " , "" ) . replace ( " }}" , "" ) . replace ( "{{>" , "" ) . replace ( "}}" , "" ) ;
104
-
105
- // remove any potential pattern parameters. this and the above are rather brutish but I didn't want to do a regex at the time
106
- if ( foundPatternPartial . indexOf ( '(' ) > 0 ) {
107
- foundPatternPartial = foundPatternPartial . substring ( 0 , foundPatternPartial . indexOf ( '(' ) ) ;
108
- }
109
-
110
- //remove any potential stylemodifiers.
111
- foundPatternPartial = foundPatternPartial . split ( ':' ) [ 0 ] ;
112
93
113
- return foundPatternPartial ;
114
94
}
115
95
} ;
116
96
117
- module . exports = engine_mustache ;
97
+ module . exports = engine_react ;
0 commit comments