Permalink
Browse files

engine accepts autoEscape:false as a param now for users who want to …

…turn off escaping; fixed browser test case display
  • Loading branch information...
1 parent 8963ddd commit 22b39a0266e85b404148df8b8071989c1ee353d6 @malgorithms committed Oct 25, 2012
View
@@ -111,6 +111,12 @@ generateExpressTest = (cb) ->
else {
gbid("browser_#{rid}").style.backgroundColor="#fcc";
}
+ if (gbid("server_#{rid}").innerHTML == gbid("expected_#{rid}").innerHTML) {
+ gbid("server_#{rid}").style.backgroundColor="#dfe";
+ }
+ else {
+ gbid("server_#{rid}").style.backgroundColor="#fcc";
+ }
</script>
\n\n\n
"""
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,7 +1,7 @@
{
"name": "toffee",
"description": "A NodeJs, Express 3.x, Express 2.x, and browser-side templating language based on CoffeeScript with slicker tokens and syntax. Built with love at OkCupid.",
- "version": "0.0.50",
+ "version": "0.0.51",
"directories": {
"lib": "./lib"
},
View
@@ -108,7 +108,7 @@ maybeAttachHeaders = (pre_output) ->
if program.no_headers
return pre_output
else
- header_out = getCommonHeadersJs true, true
+ header_out = getCommonHeadersJs true, true, true
if program.coffee
return "`#{header_out}`\n\n#{pre_output}"
else
View
@@ -14,6 +14,7 @@ class engine
@prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true
@prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else true
+ @autoEscape = if options.autoEscape? then options.autoEscape else true
@additionalErrorHandler = options.additionalErrorHandler or null
@viewCache = {} # filename -> view
@@ -38,9 +39,10 @@ class engine
__toffee.autoEscape: if set as false, don't escape output of #{} vars by default
###
- if not options.prettyPrintErrors? then options.prettyPrintErrors = @prettyPrintErrors
- if not options.prettyLogErrors? then options.prettyLogErrors = @prettyLogErrors
- if not options.additionalErrorHandler? then options.additionalErrorHandler = @additionalErrorHandler
+ if not options.prettyPrintErrors? then options.prettyPrintErrors = @prettyPrintErrors
+ if not options.prettyLogErrors? then options.prettyLogErrors = @prettyLogErrors
+ if not options.additionalErrorHandler? then options.additionalErrorHandler = @additionalErrorHandler
+ if not options.autoEscape? then options.autoEscape = @autoEscape
if options?.layout
layout_options = {}
@@ -145,13 +147,7 @@ class engine
if (@fsErrorCache[filename] and previous_fs_err and @viewCache[filename])
return @viewCache[filename]
else
- view_options =
- fileName: filename
- verbose: @verbose
- prettyPrintErrors: @prettyPrintErrors
- prettyLogErrors: @prettyLogErrors
- additionalErrorHandler: @additionalErrorHandler
- minimize: @minimize
+ view_options = @_generateViewOptions filename
v = new view txt, view_options
@viewCache[filename] = v
@_monitorForChanges filename, options
@@ -165,18 +161,25 @@ class engine
txt = "Error: Could not read #{filename}"
if options.__toffee?.parent? then txt += " requested in #{options.__toffee.parent}"
if not (err and @viewCache[filename].fsError) # i.e., don't just create a new error view
- view_options =
- fileName: filename
- verbose: @verbose
- prettyPrintErrors: @prettyPrintErrors
- minimize: @minimize
- cb: (v) =>
- @_log "#{filename} updated and ready"
- @viewCache[filename] = v
+ view_options = @_generateViewOptions filename
+ view_options.cb = (v) =>
+ @_log "#{filename} updated and ready"
+ @viewCache[filename] = v
if err
view_options.fsError = true
v = new view txt, view_options
+ _generateViewOptions: (filename) ->
+ return {
+ fileName: filename
+ verbose: @verbose
+ prettyPrintErrors: @prettyPrintErrors
+ prettyLogErrors: @prettyLogErrors
+ autoEscape: @autoEscape
+ additionalErrorHandler: @additionalErrorHandler
+ minimize: @minimize
+ }
+
_monitorForChanges: (filename, options) ->
###
we must continuously unwatch/rewatch because some editors/systems invoke a "rename"
View
@@ -24,7 +24,7 @@ minimizeJs = (js) ->
process.exit 1
js
-getCommonHeaders = (include_bundle_headers) ->
+getCommonHeaders = (include_bundle_headers, auto_escape) ->
###
each view will use this, or if they're bundled together,
it'll only be used once.
@@ -47,15 +47,18 @@ toffee.__html = (locals, o) ->
(""+o).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
toffee.__escape = (locals, o) ->
- if (not locals.__toffee.autoEscape?) or locals.__toffee.autoEscape
+ if locals.__toffee.autoEscape? then ae = locals.__toffee.autoEscape
+ else if #{auto_escape?} then ae = #{auto_escape}
+ else ae = true
+ if ae
if o is undefined then return ''
if o? and (typeof o) is "object" then return locals.json o
return locals.html o
return o
toffee.__augmentLocals = (locals, bundle_path) ->
_l = locals
- _t = _l.__toffee = { out: []}
+ _t = _l.__toffee = {out: []}
if not _l.print? then _l.print = (o) -> toffee.__print _l, o
if not _l.json? then _l.json = (o) -> toffee.__json _l, o
if not _l.raw? then _l.raw = (o) -> toffee.__raw _l, o
@@ -138,8 +141,8 @@ toffee.__inlineInclude = (path, locals, parent_locals) ->
"""
-getCommonHeadersJs = (include_bundle_headers, minimize)->
- ch = getCommonHeaders include_bundle_headers
+getCommonHeadersJs = (include_bundle_headers, auto_escape, minimize)->
+ ch = getCommonHeaders include_bundle_headers, auto_escape
js = coffee.compile ch, {bare: true}
if minimize then js = minimizeJs js
js
@@ -152,21 +155,22 @@ class view
cb: if this is set, compilation will happen async and cb will be executed when it's ready
###
options = options or {}
- @fileName = options.fileName or options.filename or null
- @bundlePath = options.bundlePath or "/" # if to be included inside a bundle, this is the path inside it.
- @browserMode = options.browserMode or false
- @minimize = options.minimize or false # excludes line numbers from coffee ; uses uglify.JS
- @verbose = options.verbose or false
- @fsError = options.fsError or false # pass true if you could not load the view template and passed in error text
- @prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true
- @prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else false
+ @fileName = options.fileName or options.filename or null
+ @bundlePath = options.bundlePath or "/" # if to be included inside a bundle, this is the path inside it.
+ @browserMode = options.browserMode or false
+ @minimize = options.minimize or false # excludes line numbers from coffee ; uses uglify.JS
+ @verbose = options.verbose or false
+ @fsError = options.fsError or false # pass true if you could not load the view template and passed in error text
+ @prettyPrintErrors = if options.prettyPrintErrors? then options.prettyPrintErrors else true
+ @prettyLogErrors = if options.prettyLogErrors? then options.prettyLogErrors else false
+ @autoEscape = if options.autoEscape? then options.autoEscape else false
@additionalErrorHandler = options.additionalErrorHandler or null
- @txt = txt
- @tokenObj = null # constructed as needed
- @coffeeScript = null # constructed as needed
- @javaScript = null # constructed as needed
- @scriptObj = null # constructed as needed
- @error = null # if err, instance of toffeeError class
+ @txt = txt
+ @tokenObj = null # constructed as needed
+ @coffeeScript = null # constructed as needed
+ @javaScript = null # constructed as needed
+ @scriptObj = null # constructed as needed
+ @error = null # if err, instance of toffeeError class
if options.cb
@_prepAsync txt, =>
options.cb @
@@ -489,7 +493,7 @@ class view
___ = @_tabAsSpaces()
"""
-#{if @browserMode then '' else getCommonHeaders(false)}
+#{if @browserMode then '' else getCommonHeaders false, @autoEscape }
tmpl = toffee.templates["#{@bundlePath}"] =
bundlePath: "#{@bundlePath}"
tmpl.render = tmpl.pub = (__locals) ->
View
@@ -10,7 +10,8 @@ app = express()
app.configure ->
toffee.expressEngine.verbose = true
- #toffee.expressEngine.prettyPrintErrors = false
+ #toffee.expressEngine.autoEscape = false
+ toffee.expressEngine.prettyPrintErrors = false
app.set 'port', process.env.PORT or 3033
app.set 'views', __dirname + '/views'
Oops, something went wrong.

0 comments on commit 22b39a0

Please sign in to comment.