21
21
var utils = require ( './utils' )
22
22
, templateCache = { }
23
23
, jsCache = { }
24
- , includeFile
25
- , includeSource
26
- , resolveInclude
27
- , compile
28
- , rethrow
29
24
, _DEFAULT_DELIMITER = '%'
30
25
, _REGEX_STRING = '(<%%)|(<%=)|(<%-)|(<%#)|(<%)|(%>)|(-%>)'
31
26
, _OPTS_MAP = {
@@ -39,7 +34,7 @@ var utils = require('./utils')
39
34
, client : 'client'
40
35
} ;
41
36
42
- resolveInclude = function ( name , filename ) {
37
+ function resolveInclude ( name , filename ) {
43
38
var path = require ( 'path' )
44
39
, dirname = path . dirname
45
40
, extname = path . extname
@@ -50,9 +45,9 @@ resolveInclude = function (name, filename) {
50
45
includePath += '.ejs' ;
51
46
}
52
47
return includePath ;
53
- } ;
48
+ }
54
49
55
- includeFile = function ( path , options ) {
50
+ function includeFile ( path , options ) {
56
51
var fn
57
52
, opts = utils . shallowCopy ( { } , options || /* istanbul ignore next */ { } )
58
53
, fs = require ( 'fs' )
@@ -76,9 +71,9 @@ includeFile = function (path, options) {
76
71
opts . filename = includePath ;
77
72
fn = exports . compile ( template , opts ) ;
78
73
return fn ;
79
- } ;
74
+ }
80
75
81
- includeSource = function ( path , options ) {
76
+ function includeSource ( path , options ) {
82
77
var opts = utils . shallowCopy ( { } , options || { } )
83
78
, fs = require ( 'fs' )
84
79
, includePath
@@ -102,15 +97,15 @@ includeSource = function (path, options) {
102
97
var templ = new Template ( template , opts ) ;
103
98
templ . generateSource ( ) ;
104
99
return templ . source ;
105
- } ;
100
+ }
106
101
107
- rethrow = function ( err , str , filename , lineno ) {
102
+ function rethrow ( err , str , filename , lineno ) {
108
103
var lines = str . split ( '\n' )
109
104
, start = Math . max ( lineno - 3 , 0 )
110
105
, end = Math . min ( lines . length , lineno + 3 ) ;
111
106
112
107
// Error context
113
- var context = lines . slice ( start , end ) . map ( function ( line , i ) {
108
+ var context = lines . slice ( start , end ) . map ( function ( line , i ) {
114
109
var curr = i + start + 1 ;
115
110
return ( curr === lineno ? ' >> ' : ' ' )
116
111
+ curr
@@ -126,12 +121,13 @@ rethrow = function (err, str, filename, lineno){
126
121
+ err . message ;
127
122
128
123
throw err ;
129
- } ;
124
+ }
130
125
131
- compile = exports . compile = function ( template , opts ) {
126
+ function compile ( template , opts ) {
132
127
var templ = new Template ( template , opts ) ;
133
128
return templ . compile ( ) ;
134
- } ;
129
+ }
130
+ exports . compile = compile ;
135
131
136
132
// template, [data], [opts]
137
133
// Have to include an empty data object if you want opts and no data
@@ -188,13 +184,12 @@ exports.renderFile = function () {
188
184
, cb = args . pop ( )
189
185
, data = args . shift ( ) || { }
190
186
, opts = args . pop ( ) || { }
191
- , template
192
- , handleTemplate ;
187
+ , template ;
193
188
194
189
// Set the filename for includes
195
190
opts . filename = path ;
196
191
197
- handleTemplate = function ( template ) {
192
+ function handleTemplate ( template ) {
198
193
var result
199
194
, failed = false ;
200
195
try {
@@ -207,7 +202,7 @@ exports.renderFile = function () {
207
202
if ( ! failed ) {
208
203
cb ( null , result ) ;
209
204
}
210
- } ;
205
+ }
211
206
212
207
template = templateCache [ path ] ;
213
208
if ( opts . cache && template ) {
@@ -233,7 +228,7 @@ exports.clearCache = function () {
233
228
jsCache = { } ;
234
229
} ;
235
230
236
- var Template = function ( text , opts ) {
231
+ function Template ( text , opts ) {
237
232
opts = opts || { } ;
238
233
var options = { } ;
239
234
this . templateText = text ;
@@ -251,10 +246,9 @@ var Template = function (text, opts) {
251
246
this . opts = options ;
252
247
253
248
this . regex = this . createRegex ( ) ;
254
- } ;
249
+ }
255
250
256
251
Template . prototype = new function ( ) {
257
-
258
252
this . modes = {
259
253
EVAL : 'eval'
260
254
, ESCAPED : 'escaped'
@@ -411,10 +405,9 @@ Template.prototype = new function () {
411
405
this . scanLine = function ( line ) {
412
406
var self = this
413
407
, d = this . opts . delimiter
414
- , newLineCount = 0
415
- , _addOutput ;
408
+ , newLineCount = 0 ;
416
409
417
- _addOutput = function ( ) {
410
+ function _addOutput ( ) {
418
411
if ( self . truncate ) {
419
412
line = line . replace ( '\n' , '' ) ;
420
413
}
@@ -430,7 +423,7 @@ Template.prototype = new function () {
430
423
// - this will be the delimiter during execution
431
424
line = line . replace ( / " / g, '\\"' ) ;
432
425
self . source += ';__output += "' + line + '";' ;
433
- } ;
426
+ }
434
427
435
428
newLineCount = ( line . split ( '\n' ) . length - 1 ) ;
436
429
0 commit comments