Skip to content

Commit

Permalink
CoffeeScript 0.5.5, with string interpolation and internal documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Mar 8, 2010
1 parent 90f2e0d commit bcf7b3f
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 109 deletions.
7 changes: 7 additions & 0 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ task 'build', 'build the CoffeeScript language from source', ->
run ['-c', '-o', 'lib'].concat(files)


task 'build:full', 'checkout /lib, rebuild the source twice, and run the tests', ->
exec 'git co lib && bin/cake build && bin/cake build && bin/cake test', (err, stdout, stderr) ->
print stdout if stdout
print stderr if stderr
throw err if err


task 'build:parser', 'rebuild the Jison parser (run build first)', ->
require.paths.unshift 'vendor/jison/lib'
parser: require('grammar').parser
Expand Down
2 changes: 2 additions & 0 deletions documentation/coffee/interpolation.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
author: "Wittgenstein"
quote: "A picture is a fact. -- $author"
4 changes: 4 additions & 0 deletions documentation/coffee/interpolation_expression.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sentence: "${ 22 / 7 } is a decent approximation of π"



10 changes: 5 additions & 5 deletions documentation/css/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ div.code {
#error {
position: absolute;
-webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px;
right: 15px; top: 15px; left: 565px;
right: 15px; top: 15px; left: 722px;
height: 15px;
padding: 2px 5px;
background: #fdcdcc;
Expand All @@ -142,14 +142,14 @@ div.code {
float: left;
padding: 0 20px;
border: 1px solid #bbb;
border-top: 0; border-bottom: 0;
border-top: 0; border-bottom: 0; border-left-width: 0;
cursor: pointer;
}
body.full_screen .navigation {
position: static;
}
.navigation.try {
border-left: 0;
.navigation.toc {
border-left-width: 1px;
}
.navigation:hover,
.navigation.active {
Expand Down Expand Up @@ -206,7 +206,7 @@ div.code {
}
.navigation .contents a {
display: block;
width: 300px;
width: 290px;
text-transform: none;
text-decoration: none;
font-weight: normal;
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/coffee-script.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<span class="k">else</span>
<span class="nv">lexer: </span><span class="k">new</span> <span class="nx">Lexer</span><span class="p">()</span>
<span class="nv">parser: </span><span class="nx">exports</span><span class="p">.</span><span class="nx">parser</span>
<span class="k">this</span><span class="p">.</span><span class="nv">exports: </span><span class="k">this</span><span class="p">.</span><span class="nv">CoffeeScript: </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</a> </div> <p>The current CoffeeScript version number.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.VERSION: </span><span class="s1">&#39;0.5.4&#39;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</a> </div> <p>Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison
<span class="k">this</span><span class="p">.</span><span class="nv">exports: </span><span class="k">this</span><span class="p">.</span><span class="nv">CoffeeScript: </span><span class="p">{}</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-3">#</a> </div> <p>The current CoffeeScript version number.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.VERSION: </span><span class="s1">&#39;0.5.5&#39;</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="octowrap"> <a class="octothorpe" href="#section-4">#</a> </div> <p>Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison
compiler.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nv">exports.compile: </span><span class="p">(</span><span class="nx">code</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="o">-&gt;</span>
<span class="k">try</span>
<span class="p">(</span><span class="nx">parser</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">lexer</span><span class="p">.</span><span class="nx">tokenize</span> <span class="nx">code</span><span class="p">).</span><span class="nx">compile</span> <span class="nx">options</span>
Expand Down
74 changes: 57 additions & 17 deletions documentation/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<div id="flybar">
<a id="logo" href="#top"> </a>
<div class="navigation">
<div class="navigation toc">
<div class="button">
Table of Contents
</div>
Expand Down Expand Up @@ -60,6 +60,7 @@
<a href="#try">Try/Catch/Finally</a>
<a href="#comparisons">Chained Comparisons</a>
<a href="#strings">Multiline Strings and Heredocs</a>
<a href="#interpolation">String Interpolation</a>
<a href="#cake">Cake, and Cakefiles</a>
<a href="#scripts">"text/coffeescript" Script Tags</a>
<a href="#resources">Resources</a>
Expand All @@ -84,6 +85,23 @@ alert reverse '!tpircseeffoC'</textarea></div>
</div>
</div>
</div>
<div class="navigation annotated">
<div class="button">
Annotated Source
</div>
<div class="contents">
<a href="documentation/docs/grammar.html">The Grammar &mdash; src/grammar</a>
<a href="documentation/docs/lexer.html">The Lexer &mdash; src/lexer</a>
<a href="documentation/docs/rewriter.html">The Rewriter &mdash; src/rewriter</a>
<a href="documentation/docs/nodes.html">The Syntax Tree &mdash; src/nodes</a>
<a href="documentation/docs/scope.html">Lexical Scope &mdash; src/scope</a>
<a href="documentation/docs/coffee-script.html">The CoffeeScript Module &mdash; src/coffee-script</a>
<a href="documentation/docs/cake.html">Cake &amp; Cakefiles &mdash; src/cake</a>
<a href="documentation/docs/command.html">"coffee" Command-Line Utility &mdash; src/command</a>
<a href="documentation/docs/optparse.html">Option Parsing &mdash; src/optparse</a>
<a href="documentation/docs/repl.html">Interactive REPL &mdash; src/repl</a>
</div>
</div>
<div id="error" style="display:none;"></div>
</div>

Expand Down Expand Up @@ -111,7 +129,7 @@ alert reverse '!tpircseeffoC'</textarea></div>

<p>
<b>Latest Version:</b>
<a href="http://github.com/jashkenas/coffee-script/tarball/0.5.4">0.5.4</a>
<a href="http://github.com/jashkenas/coffee-script/tarball/0.5.5">0.5.5</a>
</p>

<h2>
Expand Down Expand Up @@ -153,11 +171,11 @@ alert reverse '!tpircseeffoC'</textarea></div>

<p>
To install, first make sure you have a working version of
<a href="http://nodejs.org/">Node.js</a> version 0.1.31 or higher.
<a href="http://nodejs.org/">Node.js</a> version 0.1.31 or higher.
Then clone the CoffeeScript
<a href="http://github.com/jashkenas/coffee-script">source repository</a>
from GitHub, or download the latest
release: <a href="http://github.com/jashkenas/coffee-script/tarball/0.5.4">0.5.4</a>.
release: <a href="http://github.com/jashkenas/coffee-script/tarball/0.5.5">0.5.5</a>.
To install the CoffeeScript compiler system-wide
under <tt>/usr/local</tt>, open the directory and run:
</p>
Expand Down Expand Up @@ -185,8 +203,8 @@ sudo bin/cake install</pre>
<tr>
<td width="25%"><code>-i, --interactive</code></td>
<td>
Launch an interactive CoffeeScript session to try short snippets.
More pleasant if wrapped with
Launch an interactive CoffeeScript session to try short snippets.
More pleasant if wrapped with
<a href="http://utopia.knoware.nl/~hlub/uck/rlwrap/rlwrap.html">rlwrap</a>.
</td>
</tr>
Expand Down Expand Up @@ -654,7 +672,7 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
In JavaScript, the <tt>this</tt> keyword is dynamically scoped to mean the
object that the current function is attached to. If you pass a function as
as callback, or attach it to a different object, the original value of <tt>this</tt>
will be lost. If you're not familiar with this behavior,
will be lost. If you're not familiar with this behavior,
<a href="http://www.digital-web.com/articles/scope_in_javascript/">this Digital Web article</a>
gives a good overview of the quirks.
</p>
Expand All @@ -669,8 +687,8 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<%= code_for('fat_arrow') %>
<p>
If we had used <tt>-></tt> in the callback above, <tt>@customer</tt> would
have referred to the undefined "customer" property of the DOM element,
and trying to call <tt>purchase()</tt> on it would have raised an exception.
have referred to the undefined "customer" property of the DOM element,
and trying to call <tt>purchase()</tt> on it would have raised an exception.
</p>

<p>
Expand Down Expand Up @@ -732,6 +750,19 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
</p>
<%= code_for('heredocs') %>

<p>
<span id="interpolation" class="bookmark"></span>
<b class="header">String Interpolation</b>
A version of <a href="http://wiki.ecmascript.org/doku.php?id=strawman:string_interpolation">ECMAScript Harmony's proposed string interpolation</a>
is included in CoffeeScript. Simple variables can be included by marking
them with a dollar sign.
</p>
<%= code_for('interpolation', 'quote') %>
<p>
And arbitrary expressions can be interpolated by using brackets <tt>${ ... }</tt>
</p>
<%= code_for('interpolation_expression', 'sentence') %>

<h2>
<span id="cake" class="bookmark"></span>
Cake, and Cakefiles
Expand Down Expand Up @@ -794,9 +825,9 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<tt>bin/cake build</tt> to rebuild the CoffeeScript compiler, and <br />
<tt>bin/cake build:parser</tt> to regenerate the Jison parser if you're
working on the grammar. <br /><br />
<tt>git checkout lib &amp;&amp; bin/cake build &amp;&amp; bin/cake build &amp;&amp; bin/cake test</tt>
is a good command to run when you're working on the core language. It'll refresh the lib directory
(in case you broke something), build your altered compiler, use that to
<tt>bin/cake build:full</tt> is a good command to run when you're working
on the core language. It'll refresh the lib directory
(in case you broke something), build your altered compiler, use that to
rebuild itself (a good sanity test) and then run all of the tests. If
they pass, there's a good chance you've made a successful change.
</li>
Expand All @@ -812,12 +843,12 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<li>
<b>defunkt</b>'s <a href="http://github.com/defunkt/coffee-mode">CoffeeScript Major Mode</a>
&mdash; a Emacs major mode that provides syntax highlighting, indentation
support, and some bonus commands. (For Vim and TextMate highlighters,
support, and some bonus commands. (For Vim and TextMate highlighters,
see the <tt>extras</tt> directory of the main repository.)
</li>
<li>
<b>mattly</b>'s <a href="http://github.com/mattly/rack-coffee">rack-coffee</a>
&mdash; a small Rack middleware for serving CoffeeScript files as
&mdash; a small Rack middleware for serving CoffeeScript files as
compiled JavaScript on the fly.
</li>
</ul>
Expand All @@ -826,17 +857,26 @@ coffee --print app/scripts/*.coffee > concatenation.js</pre>
<span id="change_log" class="bookmark"></span>
Change Log
</h2>


<p>
<b class="header" style="margin-top: 20px;">0.5.5</b>
String interpolation, contributed by
<a href="http://github.com/StanAngeloff">Stan Angeloff</a>.
Since <tt>--run</tt> has been the default since <b>0.5.3</b>, updating
<tt>--stdio</tt> and <tt>--eval</tt> to run by default, pass <tt>--compile</tt>
as well if you'd like to print the result.
</p>

<p>
<b class="header" style="margin-top: 20px;">0.5.4</b>
Bugfix that corrects the Node.js global constants <tt>__filename</tt> and
<tt>__dirname</tt>. Tweaks for more flexible parsing of nested function
literals and improperly-indented comments. Updates for the latest Node.js API.
</p>

<p>
<b class="header" style="margin-top: 20px;">0.5.3</b>
CoffeeScript now has a syntax for defining classes. Many of the core
CoffeeScript now has a syntax for defining classes. Many of the core
components (Nodes, Lexer, Rewriter, Scope, Optparse) are using them.
Cakefiles can use <tt>optparse.coffee</tt> to define options for tasks.
<tt>--run</tt> is now the default flag for the <tt>coffee</tt> command,
Expand Down
5 changes: 5 additions & 0 deletions documentation/js/interpolation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(function(){
var author, quote;
author = "Wittgenstein";
quote = "A picture is a fact. -- " + author;
})();
4 changes: 4 additions & 0 deletions documentation/js/interpolation_expression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(function(){
var sentence;
sentence = (22 / 7) + " is a decent approximation of π";
})();
2 changes: 1 addition & 1 deletion extras/coffee-script.js

Large diffs are not rendered by default.

Loading

0 comments on commit bcf7b3f

Please sign in to comment.