New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for text/literate-coffeescript in the browser #2718
Conversation
Eh, +1. We might as well support it if we have it. Please commit the built |
Thanks, done as instructed. Force-pushed the squashed commit. |
@@ -38,16 +38,19 @@ CoffeeScript.load = (url, callback) -> | |||
# This happens on page load. | |||
runScripts = -> | |||
scripts = document.getElementsByTagName 'script' | |||
coffees = (s for s in scripts when s.type is 'text/coffeescript') | |||
coffeetypes = {'text/coffeescript': true, 'text/coffeescript+literate': true} | |||
coffees = (s for s in scripts when s.type of coffeetypes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something wrong with
coffeetypes = ['text/coffeescript', 'text/coffeescript+literate']
coffees = (s for s in scripts when s.type in coffeetypes)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, either way would be fine by me.
I avoid array indexing for lookups out of habit, thinking of hash lookups as more efficient.
: 1
instead of : true
would be fine too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler will optimize this for you:
$ coffee -bep 's.type in ["text/coffeescript", "text/coffeescript+literate"]'
var _ref;
(_ref = s.type) === "text/coffeescript" || _ref === "text/coffeescript+literate";
How about |
@jashkenas: The I'll submit a new squashed commit using |
Please do. |
Done. Tested the |
Add support for text/literate-coffeescript in the browser
This branch allows users of the browser-ready
extras/coffee-script.js
file to embed Literate CoffeeScript in web pages. For example:This results in "Success!" being displayed in the JavaScript console.
Contributors are urged by
CONTRIBUTING.md
to add their own tests. There are, however, no existing tests for the browser scripts functionality except for the test wrapper itself intests/test.html
For that reason, I have not added any new tests. I have of course tested that the code works on the web.EDIT: The original submission used
text/coffeescript+literate
. This was changed totext/literate-coffeescript
in a later squashed commit due to a suggestion from @jashkenas.