CoffeeScript = require './coffee-script'
-CoffeeScript.require = requirediff --git a/LICENSE b/LICENSE index dbe6b4e3..a396eaed 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2009-2012 Jeremy Ashkenas +Copyright (c) 2009-2013 Jeremy Ashkenas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +OTHER DEALINGS IN THE SOFTWARE. diff --git a/documentation/coffee/block_comment.coffee b/documentation/coffee/block_comment.coffee index 431dfd95..452ca3b0 100644 --- a/documentation/coffee/block_comment.coffee +++ b/documentation/coffee/block_comment.coffee @@ -1,5 +1,5 @@ ### -CoffeeScript Compiler v1.6.1 +SkinnyMochaHalfCaffScript Compiler v1.0 Released under the MIT License ### diff --git a/documentation/docs/browser.html b/documentation/docs/browser.html index 05ef70c8..dc451de2 100644 --- a/documentation/docs/browser.html +++ b/documentation/docs/browser.html @@ -92,174 +92,197 @@ -
Override exported methods for non-Node.js engines. - +
This Browser compatibility layer extends core CoffeeScript functions
+to make things work smoothly when compiling code directly in the browser.
+We add support for loading remote Coffee scripts via XHR, and
+text/coffeescript script tags, source maps via data-URLs, and so on.
CoffeeScript = require './coffee-script'
-CoffeeScript.require = requireCoffeeScript = require './coffee-script'
+CoffeeScript.require = require
+compile = CoffeeScript.compileUse standard JavaScript eval to eval code.
-
+
Use standard JavaScript eval to eval code.
CoffeeScript.eval = (code, options = {}) ->
- options.bare ?= on
- eval CoffeeScript.compile code, optionsCoffeeScript.eval = (code, options = {}) ->
+ options.bare ?= on
+ eval compile code, optionsRunning code does not provide access to this scope. - +
Running code does not provide access to this scope.
CoffeeScript.run = (code, options = {}) ->
- options.bare = on
- Function(CoffeeScript.compile code, options)()CoffeeScript.run = (code, options = {}) ->
+ options.bare = on
+ Function(compile code, options)()If we're not in a browser environment, we're finished with the public API. - +
If we're not in a browser environment, we're finished with the public API.
return unless window?return unless window?Load a remote script from the current domain via XHR. - +
Include source maps where possible. If we've got a base64 encoder, and a +JSON serializer, we're good to go.
CoffeeScript.load = (url, callback, options = {}) ->
- xhr = if window.ActiveXObject
- new window.ActiveXObject('Microsoft.XMLHTTP')
- else
- new XMLHttpRequest()
- xhr.open 'GET', url, true
- xhr.overrideMimeType 'text/plain' if 'overrideMimeType' of xhr
- xhr.onreadystatechange = ->
- if xhr.readyState is 4
- if xhr.status in [0, 200]
- CoffeeScript.run xhr.responseText, options
- else
- throw new Error "Could not load #{url}"
- callback() if callback
- xhr.send nullif btoa? and JSON?
+ compile = (code, options = {}) ->
+ options.sourceMap = true
+ options.inline = true
+ {js, v3SourceMap} = CoffeeScript.compile code, options
+ "#{js}\n//@ sourceMappingURL=data:application/json;base64,#{btoa v3SourceMap}\n//@ sourceURL=coffeescript"Activate CoffeeScript in the browser by having it compile and evaluate
-all script tags with a content-type of text/coffeescript.
-This happens on page load.
-
+
Load a remote script from the current domain via XHR.
runScripts = ->
- scripts = document.getElementsByTagName 'script'
- coffeetypes = ['text/coffeescript', 'text/literate-coffeescript']
- coffees = (s for s in scripts when s.type in coffeetypes)
- index = 0
- length = coffees.length
- do execute = ->
- script = coffees[index++]
- mediatype = script?.type
- if mediatype in coffeetypes
- options = {literate: mediatype is 'text/literate-coffeescript'}
- if script.src
- CoffeeScript.load script.src, execute, options
- else
- CoffeeScript.run script.innerHTML, options
- execute()
- nullCoffeeScript.load = (url, callback, options = {}) ->
+ options.sourceFiles = [url]
+ xhr = if window.ActiveXObject
+ new window.ActiveXObject('Microsoft.XMLHTTP')
+ else
+ new XMLHttpRequest()
+ xhr.open 'GET', url, true
+ xhr.overrideMimeType 'text/plain' if 'overrideMimeType' of xhr
+ xhr.onreadystatechange = ->
+ if xhr.readyState is 4
+ if xhr.status in [0, 200]
+ CoffeeScript.run xhr.responseText, options
+ else
+ throw new Error "Could not load #{url}"
+ callback() if callback
+ xhr.send nullListen for window load, both in browsers and in IE. +
Activate CoffeeScript in the browser by having it compile and evaluate
+all script tags with a content-type of text/coffeescript.
+This happens on page load.
if window.addEventListener
- addEventListener 'DOMContentLoaded', runScripts, no
-else
- attachEvent 'onload', runScripts
-
-runScripts = ->
+ scripts = document.getElementsByTagName 'script'
+ coffeetypes = ['text/coffeescript', 'text/literate-coffeescript']
+ coffees = (s for s in scripts when s.type in coffeetypes)
+ index = 0
+ length = coffees.length
+ do execute = ->
+ script = coffees[index++]
+ mediatype = script?.type
+ if mediatype in coffeetypes
+ options = {literate: mediatype is 'text/literate-coffeescript'}
+ if script.src
+ CoffeeScript.load script.src, execute, options
+ else
+ options.sourceFiles = ['embedded']
+ CoffeeScript.run script.innerHTML, options
+ execute()
+ nullListen for window load, both in decent browsers and in IE. +
+ +if window.addEventListener
+ addEventListener 'DOMContentLoaded', runScripts, no
+else
+ attachEvent 'onload', runScripts