@@ -6,7 +6,7 @@ var extend = require('util')._extend;
66
77// Pattern properties
88
9- var Pattern = function ( relPath , data ) {
9+ var Pattern = function ( relPath , data , patternlab ) {
1010 // We expect relPath to be the path of the pattern template, relative to the
1111 // root of the pattern tree. Parse out the path parts and save the useful ones.
1212 var pathObj = path . parse ( path . normalize ( relPath ) ) ;
@@ -29,10 +29,6 @@ var Pattern = function (relPath, data) {
2929 return val . charAt ( 0 ) . toUpperCase ( ) + val . slice ( 1 ) + ' ' + working . charAt ( 0 ) . toUpperCase ( ) + working . slice ( 1 ) ;
3030 } , '' ) . trim ( ) ; //this is the display name for the ui. strip numeric + hyphen prefixes
3131
32- // calculated path from the root of the public directory to the generated html
33- // file for this pattern
34- this . patternLink = this . name + path . sep + this . name + '.html' ; // '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
35-
3632 // the top-level pattern group this pattern belongs to. 'atoms'
3733 this . patternGroup = this . subdir . split ( path . sep ) [ 0 ] . replace ( / ^ \d * - / , '' ) ;
3834
@@ -48,6 +44,10 @@ var Pattern = function (relPath, data) {
4844 // the joined pattern group and subgroup directory
4945 this . flatPatternPath = this . subdir . replace ( / [ \/ \\ ] / g, '-' ) ; // '00-atoms-00-global'
5046
47+ // calculated path from the root of the public directory to the generated
48+ // (rendered!) html file for this pattern, to be shown in the iframe
49+ this . patternLink = patternlab ? this . getPatternLink ( patternlab , 'rendered' ) : null ;
50+
5151 // The canonical "key" by which this pattern is known. This is the callable
5252 // name of the pattern. UPDATE: this.key is now known as this.patternPartial
5353 this . patternPartial = this . patternGroup + '-' + this . patternBaseName ;
@@ -84,6 +84,20 @@ Pattern.prototype = {
8484 }
8585 } ,
8686
87+ // calculated path from the root of the public directory to the generated html
88+ // file for this pattern.
89+ // Should look something like '00-atoms-00-global-00-colors/00-atoms-00-global-00-colors.html'
90+ getPatternLink : function ( patternlab , suffixType ) {
91+ // if no suffixType is provided, we default to rendered
92+ var suffixConfig = patternlab . config . outputFileSuffixes ;
93+ var suffix = suffixType ? suffixConfig [ suffixType ] : suffixConfig . rendered ;
94+
95+ if ( suffixType === 'rawTemplate' ) {
96+ return this . name + path . sep + this . name + suffix + this . fileExtension ;
97+ }
98+ return this . name + path . sep + this . name + suffix + '.html' ;
99+ } ,
100+
87101 // the finders all delegate to the PatternEngine, which also encapsulates all
88102 // appropriate regexes
89103 findPartials : function ( ) {
@@ -111,16 +125,16 @@ Pattern.prototype = {
111125
112126// factory: creates an empty Pattern for miscellaneous internal use, such as
113127// by list_item_hunter
114- Pattern . createEmpty = function ( customProps ) {
115- var pattern = new Pattern ( '' , null ) ;
128+ Pattern . createEmpty = function ( customProps , patternlab ) {
129+ var pattern = new Pattern ( '' , null , patternlab ) ;
116130 return extend ( pattern , customProps ) ;
117131} ;
118132
119133// factory: creates an Pattern object on-demand from a hash; the hash accepts
120134// parameters that replace the positional parameters that the Pattern
121135// constructor takes.
122- Pattern . create = function ( relPath , data , customProps ) {
123- var newPattern = new Pattern ( relPath || '' , data || null ) ;
136+ Pattern . create = function ( relPath , data , customProps , patternlab ) {
137+ var newPattern = new Pattern ( relPath || '' , data || null , patternlab ) ;
124138 return extend ( newPattern , customProps ) ;
125139} ;
126140
0 commit comments