Skip to content

Commit

Permalink
Fixes #2209 -- document heredocs as 'block strings'
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Apr 25, 2012
1 parent 6bcc798 commit c1309e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 33 deletions.
20 changes: 10 additions & 10 deletions documentation/index.html.erb
Expand Up @@ -62,8 +62,8 @@
<a href="#embedded">Embedded JavaScript</a> <a href="#embedded">Embedded JavaScript</a>
<a href="#switch">Switch and Try/Catch</a> <a href="#switch">Switch and Try/Catch</a>
<a href="#comparisons">Chained Comparisons</a> <a href="#comparisons">Chained Comparisons</a>
<a href="#strings">String Interpolation, Heredocs, and Block Comments</a> <a href="#strings">String Interpolation, Block Strings, and Block Comments</a>
<a href="#regexes">Extended Regular Expressions</a> <a href="#regexes">Block Regular Expressions</a>
<a href="#cake">Cake, and Cakefiles</a> <a href="#cake">Cake, and Cakefiles</a>
<a href="#scripts">"text/coffeescript" Script Tags</a> <a href="#scripts">"text/coffeescript" Script Tags</a>
<a href="#resources">Books, Screencasts, Examples and Resources</a> <a href="#resources">Books, Screencasts, Examples and Resources</a>
Expand Down Expand Up @@ -837,7 +837,7 @@ Expressions


<p> <p>
<span id="strings" class="bookmark"></span> <span id="strings" class="bookmark"></span>
<b class="header">String Interpolation, Heredocs, and Block Comments</b> <b class="header">String Interpolation, Block Strings, and Block Comments</b>
Ruby-style string interpolation is included in CoffeeScript. Double-quoted Ruby-style string interpolation is included in CoffeeScript. Double-quoted
strings allow for interpolated values, using <tt>#{ ... }</tt>, strings allow for interpolated values, using <tt>#{ ... }</tt>,
and single-quoted strings are literal. and single-quoted strings are literal.
Expand All @@ -848,30 +848,30 @@ Expressions
</p> </p>
<%= code_for('strings', 'mobyDick') %> <%= code_for('strings', 'mobyDick') %>
<p> <p>
Heredocs can be used to hold formatted or indentation-sensitive text Block strings can be used to hold formatted or indentation-sensitive text
(or, if you just don't feel like escaping quotes and apostrophes). The (or, if you just don't feel like escaping quotes and apostrophes). The
indentation level that begins the heredoc is maintained throughout, so indentation level that begins the block is maintained throughout, so
you can keep it all aligned with the body of your code. you can keep it all aligned with the body of your code.
</p> </p>
<%= code_for('heredocs', 'html') %> <%= code_for('heredocs', 'html') %>
<p> <p>
Double-quoted heredocs, like double-quoted strings, allow interpolation. Double-quoted block strings, like other double-quoted strings, allow interpolation.
</p> </p>
<p> <p>
Sometimes you'd like to pass a block comment through to the generated Sometimes you'd like to pass a block comment through to the generated
JavaScript. For example, when you need to embed a licensing header at JavaScript. For example, when you need to embed a licensing header at
the top of a file. Block comments, which mirror the syntax for heredocs, the top of a file. Block comments, which mirror the syntax for block strings,
are preserved in the generated code. are preserved in the generated code.
</p> </p>
<%= code_for('block_comment') %> <%= code_for('block_comment') %>


<p> <p>
<span id="regexes" class="bookmark"></span> <span id="regexes" class="bookmark"></span>
<b class="header">Extended Regular Expressions</b> <b class="header">Block Regular Expressions</b>
Similar to "heredocs" and "herecomments", CoffeeScript supports "heregexes" &mdash; Similar to block strings and comments, CoffeeScript supports block regexes &mdash;
extended regular expressions that ignore internal whitespace and can contain extended regular expressions that ignore internal whitespace and can contain
comments and interpolation. Modeled after Perl's <tt>/x</tt> modifier, CoffeeSctipt's comments and interpolation. Modeled after Perl's <tt>/x</tt> modifier, CoffeeSctipt's
heregexes are delimited by <tt>///</tt> and go a long way towards making complex block regexes are delimited by <tt>///</tt> and go a long way towards making complex
regular expressions readable. To quote from the CoffeeScript source: regular expressions readable. To quote from the CoffeeScript source:
</p> </p>
<%= code_for('heregexes') %> <%= code_for('heregexes') %>
Expand Down
34 changes: 11 additions & 23 deletions index.html
Expand Up @@ -39,8 +39,8 @@
<a href="#embedded">Embedded JavaScript</a> <a href="#embedded">Embedded JavaScript</a>
<a href="#switch">Switch and Try/Catch</a> <a href="#switch">Switch and Try/Catch</a>
<a href="#comparisons">Chained Comparisons</a> <a href="#comparisons">Chained Comparisons</a>
<a href="#strings">String Interpolation, Heredocs, and Block Comments</a> <a href="#strings">String Interpolation, Block Strings, and Block Comments</a>
<a href="#regexes">Extended Regular Expressions</a> <a href="#regexes">Block Regular Expressions</a>
<a href="#cake">Cake, and Cakefiles</a> <a href="#cake">Cake, and Cakefiles</a>
<a href="#scripts">"text/coffeescript" Script Tags</a> <a href="#scripts">"text/coffeescript" Script Tags</a>
<a href="#resources">Books, Screencasts, Examples and Resources</a> <a href="#resources">Books, Screencasts, Examples and Resources</a>
Expand Down Expand Up @@ -1463,8 +1463,6 @@ <h2>


Animal <span class="Keyword">=</span> (<span class="Storage">function</span>() { Animal <span class="Keyword">=</span> (<span class="Storage">function</span>() {


Animal.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> <span class="String"><span class="String">'</span>Animal<span class="String">'</span></span>;

<span class="Storage">function</span> <span class="FunctionName">Animal</span>(<span class="FunctionArgument">name</span>) { <span class="Storage">function</span> <span class="FunctionName">Animal</span>(<span class="FunctionArgument">name</span>) {
<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name; <span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name;
} }
Expand All @@ -1481,8 +1479,6 @@ <h2>


__extends(Snake, _super); __extends(Snake, _super);


Snake.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> <span class="String"><span class="String">'</span>Snake<span class="String">'</span></span>;

<span class="Storage">function</span> <span class="FunctionName">Snake</span>() { <span class="Storage">function</span> <span class="FunctionName">Snake</span>() {
<span class="Keyword">return</span> Snake.__super__.<span class="LibraryConstant">constructor</span>.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments); <span class="Keyword">return</span> Snake.__super__.<span class="LibraryConstant">constructor</span>.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
} }
Expand All @@ -1500,8 +1496,6 @@ <h2>


__extends(Horse, _super); __extends(Horse, _super);


Horse.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> <span class="String"><span class="String">'</span>Horse<span class="String">'</span></span>;

<span class="Storage">function</span> <span class="FunctionName">Horse</span>() { <span class="Storage">function</span> <span class="FunctionName">Horse</span>() {
<span class="Keyword">return</span> Horse.__super__.<span class="LibraryConstant">constructor</span>.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments); <span class="Keyword">return</span> Horse.__super__.<span class="LibraryConstant">constructor</span>.<span class="LibraryFunction">apply</span>(<span class="Variable">this</span>, arguments);
} }
Expand All @@ -1528,8 +1522,6 @@ <h2>
Animal = (function() { Animal = (function() {
Animal.name = 'Animal';

function Animal(name) { function Animal(name) {
this.name = name; this.name = name;
} }
Expand All @@ -1546,8 +1538,6 @@ <h2>
__extends(Snake, _super); __extends(Snake, _super);
Snake.name = 'Snake';

function Snake() { function Snake() {
return Snake.__super__.constructor.apply(this, arguments); return Snake.__super__.constructor.apply(this, arguments);
} }
Expand All @@ -1565,8 +1555,6 @@ <h2>
__extends(Horse, _super); __extends(Horse, _super);
Horse.name = 'Horse';

function Horse() { function Horse() {
return Horse.__super__.constructor.apply(this, arguments); return Horse.__super__.constructor.apply(this, arguments);
} }
Expand Down Expand Up @@ -1922,7 +1910,7 @@ <h2>


<p> <p>
<span id="strings" class="bookmark"></span> <span id="strings" class="bookmark"></span>
<b class="header">String Interpolation, Heredocs, and Block Comments</b> <b class="header">String Interpolation, Block Strings, and Block Comments</b>
Ruby-style string interpolation is included in CoffeeScript. Double-quoted Ruby-style string interpolation is included in CoffeeScript. Double-quoted
strings allow for interpolated values, using <tt>#{ ... }</tt>, strings allow for interpolated values, using <tt>#{ ... }</tt>,
and single-quoted strings are literal. and single-quoted strings are literal.
Expand Down Expand Up @@ -1970,9 +1958,9 @@ <h2>
mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world..."; mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...";
;alert(mobyDick);'>run: mobyDick</div><br class='clear' /></div> ;alert(mobyDick);'>run: mobyDick</div><br class='clear' /></div>
<p> <p>
Heredocs can be used to hold formatted or indentation-sensitive text Block strings can be used to hold formatted or indentation-sensitive text
(or, if you just don't feel like escaping quotes and apostrophes). The (or, if you just don't feel like escaping quotes and apostrophes). The
indentation level that begins the heredoc is maintained throughout, so indentation level that begins the block is maintained throughout, so
you can keep it all aligned with the body of your code. you can keep it all aligned with the body of your code.
</p> </p>
<div class='code'><pre class="idle">html <span class="Keyword">=</span> <span class="String"><span class="String">&quot;&quot;&quot;</span></span> <div class='code'><pre class="idle">html <span class="Keyword">=</span> <span class="String"><span class="String">&quot;&quot;&quot;</span></span>
Expand All @@ -1989,12 +1977,12 @@ <h2>
html = "<strong>\n cup of coffeescript\n</strong>"; html = "<strong>\n cup of coffeescript\n</strong>";
;alert(html);'>run: html</div><br class='clear' /></div> ;alert(html);'>run: html</div><br class='clear' /></div>
<p> <p>
Double-quoted heredocs, like double-quoted strings, allow interpolation. Double-quoted block strings, like other double-quoted strings, allow interpolation.
</p> </p>
<p> <p>
Sometimes you'd like to pass a block comment through to the generated Sometimes you'd like to pass a block comment through to the generated
JavaScript. For example, when you need to embed a licensing header at JavaScript. For example, when you need to embed a licensing header at
the top of a file. Block comments, which mirror the syntax for heredocs, the top of a file. Block comments, which mirror the syntax for block strings,
are preserved in the generated code. are preserved in the generated code.
</p> </p>
<div class='code'><pre class="idle"><span class="Comment"><span class="Comment">###</span></span> <div class='code'><pre class="idle"><span class="Comment"><span class="Comment">###</span></span>
Expand All @@ -2013,11 +2001,11 @@ <h2>


<p> <p>
<span id="regexes" class="bookmark"></span> <span id="regexes" class="bookmark"></span>
<b class="header">Extended Regular Expressions</b> <b class="header">Block Regular Expressions</b>
Similar to "heredocs" and "herecomments", CoffeeScript supports "heregexes" &mdash; Similar to block strings and comments, CoffeeScript supports block regexes &mdash;
extended regular expressions that ignore internal whitespace and can contain extended regular expressions that ignore internal whitespace and can contain
comments and interpolation. Modeled after Perl's <tt>/x</tt> modifier, CoffeeSctipt's comments and interpolation. Modeled after Perl's <tt>/x</tt> modifier, CoffeeSctipt's
heregexes are delimited by <tt>///</tt> and go a long way towards making complex block regexes are delimited by <tt>///</tt> and go a long way towards making complex
regular expressions readable. To quote from the CoffeeScript source: regular expressions readable. To quote from the CoffeeScript source:
</p> </p>
<div class='code'><pre class="idle">OPERATOR <span class="Keyword">=</span> <span class="String">/// ^ (</span> <div class='code'><pre class="idle">OPERATOR <span class="Keyword">=</span> <span class="String">/// ^ (</span>
Expand Down Expand Up @@ -2956,7 +2944,7 @@ <h2>
closeMenus = -> closeMenus = ->
$('.navigation.active').removeClass 'active' $('.navigation.active').removeClass 'active'


$('.minibutton.run').click evalJS $('.minibutton.run').click -> evalJS()


# Bind navigation buttons to open the menus. # Bind navigation buttons to open the menus.
$('.navigation').click (e) -> $('.navigation').click (e) ->
Expand Down

0 comments on commit c1309e1

Please sign in to comment.