1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

new live 'Try CoffeeScript'

This commit is contained in:
Jeremy Ashkenas 2010-02-25 20:39:34 -05:00
parent 406a18067d
commit dc7f4b4be0
5 changed files with 52 additions and 22 deletions

View file

@ -1,5 +1,5 @@
# Eat lunch.
lunch: eat(food) for food in ['toast', 'cheese', 'wine']
lunch: eat food for food in ['toast', 'cheese', 'wine']
# Naive collision detection.
for roid in asteroids

View file

@ -121,6 +121,19 @@ div.code {
position: absolute;
top: 0px; left: 10px;
}
#error {
position: absolute;
-webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px;
right: 15px; top: 15px; left: 565px;
height: 15px;
padding: 2px 5px;
background: #fdcdcc;
color: #864544;
border: 1px solid #864544;
font: 10px/15px Arial;
overflow: hidden;
text-transform: uppercase;
}
.navigation {
height: 50px;
font: bold 11px/50px Arial;
@ -169,9 +182,6 @@ div.code {
.navigation .code button {
bottom: 10px;
}
.navigation .compile {
left: 240px; right: auto;
}
.navigation .contents a {
display: block;
width: 300px;

View file

@ -76,12 +76,12 @@
alert reverse '!tpircseeffoC'</textarea>
<pre id="repl_results"></pre>
<button class="compile" onclick="javascript: repl_compile();">compile</button>
<button class="run" onclick="javascript: repl_run();">run</button>
<button class="run">run</button>
<br class="clear" />
</div>
</div>
</div>
<div id="error"></div>
</div>
<div class="container">
@ -965,27 +965,35 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<script type="text/coffeescript">
window.repl_compile: ->
# Set up the compilation function, to run when you stop typing.
compile_source: ->
source: $('#repl_source').val()
window.compiled_js: ''
try
window.compiled_js: CoffeeScript.compile source, {no_wrap: true}
catch error then alert error
$('#repl_results').text window.compiled_js
$('#repl_results').text window.compiled_js
$('#error').hide();
catch error
$('#error').text(error.message).show();
window.repl_run: ->
# Listen for keypresses and recompile.
$('#repl_source').keyup -> compile_source()
# Eval the compiled js.
$('button.run').click ->
try
eval window.compiled_js
catch error then alert error
nav: $('.navigation')
current_nav: null
# Helper to hide the menus.
close_menus: ->
current_nav.removeClass 'active' if current_nav
current_nav: null
nav.click (e) ->
# Bind navigation buttons to open the menus.
$('.navigation').click (e) ->
return if e.target.tagName.toLowerCase() is 'a'
if this isnt (current_nav and current_nav[0])
close_menus();
@ -995,6 +1003,8 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
$(document.body).click -> close_menus()
compile_source()
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

File diff suppressed because one or more lines are too long

View file

@ -62,12 +62,12 @@
alert reverse '!tpircseeffoC'</textarea>
<pre id="repl_results"></pre>
<button class="compile" onclick="javascript: repl_compile();">compile</button>
<button class="run" onclick="javascript: repl_run();">run</button>
<button class="run">run</button>
<br class="clear" />
</div>
</div>
</div>
<div id="error"></div>
</div>
<div class="container">
@ -817,7 +817,7 @@ One fell out and bumped his head.");
would use a loop, <b>each</b>/<b>forEach</b>, <b>map</b>, or <b>select</b>/<b>filter</b>.
</p>
<div class='code'><pre class="idle"><span class="Comment"><span class="Comment">#</span> Eat lunch.</span>
<span class="FunctionName">lunch</span><span class="Keyword">:</span> eat(food) <span class="Keyword">for</span> food <span class="Keyword">in</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>]
<span class="FunctionName">lunch</span><span class="Keyword">:</span> eat food <span class="Keyword">for</span> food <span class="Keyword">in</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>]
<span class="Comment"><span class="Comment">#</span> Naive collision detection.</span>
<span class="Keyword">for</span> roid <span class="Keyword">in</span> asteroids
@ -1845,27 +1845,35 @@ task(<span class="String"><span class="String">'</span>test<span class="String">
<script type="text/coffeescript">
window.repl_compile: ->
# Set up the compilation function, to run when you stop typing.
compile_source: ->
source: $('#repl_source').val()
window.compiled_js: ''
try
window.compiled_js: CoffeeScript.compile source, {no_wrap: true}
catch error then alert error
$('#repl_results').text window.compiled_js
$('#repl_results').text window.compiled_js
$('#error').hide();
catch error
$('#error').text(error.message).show();
window.repl_run: ->
# Listen for keypresses and recompile.
$('#repl_source').keyup -> compile_source()
# Eval the compiled js.
$('button.run').click ->
try
eval window.compiled_js
catch error then alert error
nav: $('.navigation')
current_nav: null
# Helper to hide the menus.
close_menus: ->
current_nav.removeClass 'active' if current_nav
current_nav: null
nav.click (e) ->
# Bind navigation buttons to open the menus.
$('.navigation').click (e) ->
return if e.target.tagName.toLowerCase() is 'a'
if this isnt (current_nav and current_nav[0])
close_menus();
@ -1875,6 +1883,8 @@ task(<span class="String"><span class="String">'</span>test<span class="String">
$(document.body).click -> close_menus()
compile_source()
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>