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

Use Node instead of Ruby for documentation

This commit is contained in:
xixixao 2014-01-28 01:56:29 +00:00
parent 570529f526
commit f42329ca0a
11 changed files with 881 additions and 791 deletions

View file

@ -84,13 +84,6 @@ task 'build:parser', 'rebuild the Jison parser (run build first)', ->
parser = require('./lib/coffee-script/grammar').parser parser = require('./lib/coffee-script/grammar').parser
fs.writeFile 'lib/coffee-script/parser.js', parser.generate() fs.writeFile 'lib/coffee-script/parser.js', parser.generate()
task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', ->
exec 'plist2syntax ../coffee-script-tmbundle/Syntaxes/CoffeeScript.tmLanguage', (err) ->
throw err if err
exec 'sudo mv coffeescript.yaml /usr/local/lib/ruby/gems/1.8/gems/ultraviolet-0.10.2/syntax/coffeescript.syntax'
task 'build:browser', 'rebuild the merged script for inclusion in the browser', -> task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
code = '' code = ''
for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'sourcemap', 'coffee-script', 'browser'] for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'sourcemap', 'coffee-script', 'browser']
@ -123,9 +116,49 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser',
invoke 'test:browser' invoke 'test:browser'
task 'doc:site', 'watch and continually rebuild the documentation for the website', -> task 'doc:site', 'build the documentation for the website', ->
exec 'rake doc', (err) -> source = 'documentation/index.html.coffee'
throw err if err exec 'bin/coffee -bc -o documentation/js documentation/coffee/*.coffee'
# _.template for CoffeeScript
template = (text, compile) ->
escapes =
"'": "'"
'\\': '\\'
'\r': 'r'
'\n': 'n'
'\t': 't'
'\u2028': 'u2028'
'\u2029': 'u2029'
escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g
matcher = /<%=([\s\S]+?)%>|<%([\s\S]+?)%>|$/g
# Compile the template source, escaping string literals appropriately.
index = 0
source = ""
text.replace matcher, (match, interpolate, evaluate, offset) ->
source += text[index...offset].replace escaper, (match) ->
"\\#{escapes[match]}"
# strip newline and semi-colon from interpolated expression
source += "'+\n#{(compile interpolate)[0...-2]}+\n'" if interpolate
source += "';\n#{compile evaluate}\n__p+='" if evaluate
index = offset + match.length
match
source = "with(obj){\n__p+='#{source}';\n}\n"
source = "var __p='',__j=Array.prototype.join,
print=function(){__p+=__j.call(arguments,'');};\n
#{source}return __p;\n"
try
render = new Function 'obj', source
catch e
e.source = source
throw e
render require: require
rendered = template fs.readFileSync(source, 'utf-8'), (code) ->
CoffeeScript.compile code, bare: true
fs.writeFileSync 'index.html', rendered
task 'doc:source', 'rebuild the internal documentation', -> task 'doc:source', 'rebuild the internal documentation', ->

View file

@ -1,79 +0,0 @@
require 'rubygems'
require 'erb'
require 'fileutils'
require 'rake/testtask'
require 'json'
desc "Build the documentation page"
task :doc do
source = 'documentation/index.html.erb'
child = fork { exec "bin/coffee -bcw -o documentation/js documentation/coffee/*.coffee" }
at_exit { Process.kill("INT", child) }
Signal.trap("INT") { exit }
loop do
mtime = File.stat(source).mtime
if !@mtime || mtime > @mtime
rendered = ERB.new(File.read(source)).result(binding)
File.open('index.html', 'w+') {|f| f.write(rendered) }
end
@mtime = mtime
sleep 1
end
end
desc "Build coffee-script-source gem"
task :gem do
require 'rubygems'
require 'rubygems/package'
gemspec = Gem::Specification.new do |s|
s.name = 'coffee-script-source'
s.version = JSON.parse(File.read('package.json'))["version"]
s.date = Time.now.strftime("%Y-%m-%d")
s.homepage = "http://jashkenas.github.com/coffee-script/"
s.summary = "The CoffeeScript Compiler"
s.description = <<-EOS
CoffeeScript is a little language that compiles into JavaScript.
Underneath all of those embarrassing braces and semicolons,
JavaScript has always had a gorgeous object model at its heart.
CoffeeScript is an attempt to expose the good parts of JavaScript
in a simple way.
EOS
s.files = [
'lib/coffee_script/coffee-script.js',
'lib/coffee_script/source.rb'
]
s.authors = ['Jeremy Ashkenas']
s.email = 'jashkenas@gmail.com'
s.rubyforge_project = 'coffee-script-source'
s.license = "MIT"
end
file = File.open("coffee-script-source.gem", "w")
Gem::Package.open(file, 'w') do |pkg|
pkg.metadata = gemspec.to_yaml
path = "lib/coffee_script/source.rb"
contents = <<-ERUBY
module CoffeeScript
module Source
def self.bundled_path
File.expand_path("../coffee-script.js", __FILE__)
end
end
end
ERUBY
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
tar_io.write(contents)
end
contents = File.read("extras/coffee-script.js")
path = "lib/coffee_script/coffee-script.js"
pkg.add_file_simple(path, 0644, contents.size) do |tar_io|
tar_io.write(contents)
end
end
end

View file

@ -0,0 +1,66 @@
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original code:; http://softwaremaniacs.org/media/soft/highlight/styles/tomorrow.css */
/* But forked for CoffeeScript */
.tomorrow-comment, pre .comment, pre .title {
color: #8e908c;
}
.tomorrow-red, pre .variable, pre .tag, pre .regexp, pre .ruby .constant, pre .xml .tag .title, pre .xml .pi, pre .xml .doctype, pre .html .doctype, pre .css .id, pre .css .class, pre .css .pseudo {
color: #c82829;
}
.tomorrow-orange, pre .number, pre .preprocessor, pre .built_in, pre .params, pre .constant {
color: #000000;
}
.tomorrow-yellow, pre .class, pre .ruby .class .title, pre .css .rules .attribute {
color: #eab700;
}
.tomorrow-green, pre .string, pre .value, pre .inheritance, pre .header, pre .ruby .symbol, pre .xml .cdata {
color: #718c00;
}
.tomorrow-aqua, pre .css .hexcolor {
color: #3e999f;
}
.tomorrow-blue, pre .function, pre .function .title, pre .python .decorator, pre .python .title, pre .ruby .function .title, pre .ruby .title .keyword, pre .perl .sub, pre .javascript .title, pre .coffeescript .title {
color: #21439C;
}
.tomorrow-purple, pre .keyword, pre .reserved, pre .javascript .function {
color: #FF5600;
}
pre .subst {
color: #A535AE;
}
pre .literal {
color: #A535AE;
}
pre .property {
color: #A535AE;
}
pre .class .title {
color: #21439C;
}
pre code {
display: block;
background: white;
color: #000000;
}
pre .coffeescript .javascript,
pre .javascript .xml,
pre .tex .formula,
pre .xml .javascript,
pre .xml .vbscript,
pre .xml .css,
pre .xml .cdata {
opacity: 0.5;
}

View file

@ -1,29 +1,29 @@
<% <%
require 'uv' path = require 'path'
require 'json' fs = require 'fs'
@counter = 0 hljs = require 'highlight.js'
def code_for(file, executable=false, show_load=true) hljs.configure classPrefix: ''
@counter += 1
return '' unless File.exists?("documentation/js/#{file}.js") counter = 0
cs = File.read("documentation/coffee/#{file}.coffee") code_for = (file, executable = false, showLoad = true) ->
js = File.read("documentation/js/#{file}.js") counter++
js = js.sub(/^\/\/ generated.*?\n/i, '') return unless fs.existsSync "documentation/js/#{file}.js"
cshtml = Uv.parse(cs, 'xhtml', 'coffeescript', false, 'idle', false) cs = fs.readFileSync "documentation/coffee/#{file}.coffee", 'utf-8'
jshtml = Uv.parse(js, 'xhtml', 'javascript', false, 'idle', false) js = fs.readFileSync "documentation/js/#{file}.js", 'utf-8'
append = executable == true ? '' : "alert(#{executable});" js = js.replace /^\/\/ generated.*?\n/i, ''
if executable and executable != true
cs.sub!(/(\S)\s*\Z/m, "\\1\n\nalert #{executable}") cshtml = "<pre><code>#{hljs.highlight('coffeescript', cs).value}</code></pre>"
end jshtml = "<pre><code>#{hljs.highlight('javascript', js).value}</code></pre>"
run = executable == true ? 'run' : "run: #{executable}" append = if executable is yes then '' else "alert(#{executable});"
name = "example#{@counter}" if executable and executable != yes
script = "<script>window.#{name} = #{cs.to_json}</script>" cs.replace /(\S)\s*\Z/m, "$1\n\nalert #{executable}"
import = show_load ? "<div class='minibutton load' onclick='javascript: loadConsole(#{name});'>load</div>" : '' run = if executable is true then 'run' else "run: #{executable}"
button = executable ? "<div class='minibutton ok' onclick='javascript: #{js};#{append}'>#{run}</div>" : '' name = "example#{counter}"
"<div class='code'>#{cshtml}#{jshtml}#{script}#{import}#{button}<br class='clear' /></div>" script = "<script>window.#{name} = #{JSON.stringify cs}</script>"
end load = if showLoad then "<div class='minibutton load' onclick='javascript: loadConsole(#{name});'>load</div>" else ''
button = if executable then "<div class='minibutton ok' onclick='javascript: #{js};#{append}'>#{run}</div>" else ''
"<div class='code'>#{cshtml}#{jshtml}#{script}#{load}#{button}<br class='clear' /></div>"
%> %>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -32,6 +32,7 @@
<link rel="canonical" href="http://coffeescript.org" /> <link rel="canonical" href="http://coffeescript.org" />
<link rel="stylesheet" type="text/css" href="documentation/css/docs.css" /> <link rel="stylesheet" type="text/css" href="documentation/css/docs.css" />
<link rel="stylesheet" type="text/css" href="documentation/css/idle.css" /> <link rel="stylesheet" type="text/css" href="documentation/css/idle.css" />
<link rel="stylesheet" type="text/css" href="documentation/css/tomorrow.css" />
<link rel="shortcut icon" href="documentation/images/favicon.ico" /> <link rel="shortcut icon" href="documentation/images/favicon.ico" />
</head> </head>
<body> <body>
@ -150,7 +151,7 @@ sudo npm install -g coffee-script</pre>
<p><i>CoffeeScript on the left, compiled JavaScript output on the right.</i></p> <p><i>CoffeeScript on the left, compiled JavaScript output on the right.</i></p>
<%= code_for('overview', 'cubes', false) %> <%= code_for 'overview', 'cubes', false %>
<h2> <h2>
<span id="installation" class="bookmark"></span> <span id="installation" class="bookmark"></span>
@ -435,12 +436,12 @@ Expressions
an arrow, and the function body. The empty function looks like this: an arrow, and the function body. The empty function looks like this:
<tt>-></tt> <tt>-></tt>
</p> </p>
<%= code_for('functions', 'cube(5)') %> <%= code_for 'functions', 'cube(5)' %>
<p> <p>
Functions may also have default values for arguments, which will be used Functions may also have default values for arguments, which will be used
if the incoming argument is missing (<tt>null</tt> or <tt>undefined</tt>). if the incoming argument is missing (<tt>null</tt> or <tt>undefined</tt>).
</p> </p>
<%= code_for('default_args', 'fill("cup")') %> <%= code_for 'default_args', 'fill("cup")' %>
<p> <p>
<span id="objects_and_arrays" class="bookmark"></span> <span id="objects_and_arrays" class="bookmark"></span>
@ -450,14 +451,14 @@ Expressions
the commas are optional. Objects may be created using indentation instead the commas are optional. Objects may be created using indentation instead
of explicit braces, similar to <a href="http://yaml.org">YAML</a>. of explicit braces, similar to <a href="http://yaml.org">YAML</a>.
</p> </p>
<%= code_for('objects_and_arrays', 'song.join(" ... ")') %> <%= code_for 'objects_and_arrays', 'song.join(" ... ")' %>
<p> <p>
In JavaScript, you can't use reserved words, like <tt>class</tt>, as properties In JavaScript, you can't use reserved words, like <tt>class</tt>, as properties
of an object, without quoting them as strings. CoffeeScript notices reserved words of an object, without quoting them as strings. CoffeeScript notices reserved words
used as keys in objects and quotes them for you, so you don't have to worry used as keys in objects and quotes them for you, so you don't have to worry
about it (say, when using jQuery). about it (say, when using jQuery).
</p> </p>
<%= code_for('objects_reserved') %> <%= code_for 'objects_reserved' %>
<p> <p>
<span id="lexical-scope" class="bookmark"></span> <span id="lexical-scope" class="bookmark"></span>
@ -466,7 +467,7 @@ Expressions
are properly declared within lexical scope &mdash; you never need to write are properly declared within lexical scope &mdash; you never need to write
<tt>var</tt> yourself. <tt>var</tt> yourself.
</p> </p>
<%= code_for('scope', 'inner') %> <%= code_for 'scope', 'inner' %>
<p> <p>
Notice how all of the variable declarations have been pushed up to Notice how all of the variable declarations have been pushed up to
the top of the closest scope, the first time they appear. the top of the closest scope, the first time they appear.
@ -511,7 +512,7 @@ Expressions
is no explicit ternary statement in CoffeeScript &mdash; you simply use is no explicit ternary statement in CoffeeScript &mdash; you simply use
a regular <b>if</b> statement on a single line. a regular <b>if</b> statement on a single line.
</p> </p>
<%= code_for('conditionals') %> <%= code_for 'conditionals' %>
<p> <p>
<span id="splats" class="bookmark"></span> <span id="splats" class="bookmark"></span>
@ -521,7 +522,7 @@ Expressions
splats <tt>...</tt>, both for function definition as well as invocation, splats <tt>...</tt>, both for function definition as well as invocation,
making variable numbers of arguments a little bit more palatable. making variable numbers of arguments a little bit more palatable.
</p> </p>
<%= code_for('splats', true) %> <%= code_for 'splats', true %>
<p> <p>
<span id="loops" class="bookmark"></span> <span id="loops" class="bookmark"></span>
@ -532,7 +533,7 @@ Expressions
Unlike for loops, array comprehensions are expressions, and can be returned Unlike for loops, array comprehensions are expressions, and can be returned
and assigned. and assigned.
</p> </p>
<%= code_for('array_comprehensions') %> <%= code_for 'array_comprehensions' %>
<p> <p>
Comprehensions should be able to handle most places where you otherwise Comprehensions should be able to handle most places where you otherwise
would use a loop, <b>each</b>/<b>forEach</b>, <b>map</b>, or <b>select</b>/<b>filter</b>, for example: would use a loop, <b>each</b>/<b>forEach</b>, <b>map</b>, or <b>select</b>/<b>filter</b>, for example:
@ -541,7 +542,7 @@ Expressions
in fixed-size increments, you can use a range to specify the start and in fixed-size increments, you can use a range to specify the start and
end of your comprehension. end of your comprehension.
</p> </p>
<%= code_for('range_comprehensions', 'countdown') %> <%= code_for 'range_comprehensions', 'countdown' %>
<p> <p>
Note how because we are assigning the value of the comprehensions to a Note how because we are assigning the value of the comprehensions to a
variable in the example above, CoffeeScript is collecting the result of variable in the example above, CoffeeScript is collecting the result of
@ -561,7 +562,7 @@ Expressions
an object. Use <tt>of</tt> to signal comprehension over the properties of an object. Use <tt>of</tt> to signal comprehension over the properties of
an object instead of the values in an array. an object instead of the values in an array.
</p> </p>
<%= code_for('object_comprehensions', 'ages.join(", ")') %> <%= code_for 'object_comprehensions', 'ages.join(", ")' %>
<p> <p>
If you would like to iterate over just the keys that are defined on the If you would like to iterate over just the keys that are defined on the
object itself, by adding a <tt>hasOwnProperty</tt> object itself, by adding a <tt>hasOwnProperty</tt>
@ -574,7 +575,7 @@ Expressions
as an expression, returning an array containing the result of each iteration as an expression, returning an array containing the result of each iteration
through the loop. through the loop.
</p> </p>
<%= code_for('while', 'lyrics.join("\n")') %> <%= code_for 'while', 'lyrics.join("\n")' %>
<p> <p>
For readability, the <b>until</b> keyword is equivalent to <tt>while not</tt>, For readability, the <b>until</b> keyword is equivalent to <tt>while not</tt>,
and the <b>loop</b> keyword is equivalent to <tt>while true</tt>. and the <b>loop</b> keyword is equivalent to <tt>while true</tt>.
@ -586,7 +587,7 @@ Expressions
provides the <tt>do</tt> keyword, which immediately invokes a passed function, provides the <tt>do</tt> keyword, which immediately invokes a passed function,
forwarding any arguments. forwarding any arguments.
</p> </p>
<%= code_for('do') %> <%= code_for 'do' %>
<p> <p>
<span id="slices" class="bookmark"></span> <span id="slices" class="bookmark"></span>
@ -597,12 +598,12 @@ Expressions
Slices indices have useful defaults. An omitted first index defaults to Slices indices have useful defaults. An omitted first index defaults to
zero and an omitted second index defaults to the size of the array. zero and an omitted second index defaults to the size of the array.
</p> </p>
<%= code_for('slices', 'middle') %> <%= code_for 'slices', 'middle' %>
<p> <p>
The same syntax can be used with assignment to replace a segment of an array The same syntax can be used with assignment to replace a segment of an array
with new values, splicing it. with new values, splicing it.
</p> </p>
<%= code_for('splices', 'numbers') %> <%= code_for 'splices', 'numbers' %>
<p> <p>
Note that JavaScript strings are immutable, and can't be spliced. Note that JavaScript strings are immutable, and can't be spliced.
</p> </p>
@ -616,7 +617,7 @@ Expressions
pushed down into each possible branch of execution in the function pushed down into each possible branch of execution in the function
below. below.
</p> </p>
<%= code_for('expressions', 'eldest') %> <%= code_for 'expressions', 'eldest' %>
<p> <p>
Even though functions will always return their final value, it's both possible Even though functions will always return their final value, it's both possible
and encouraged to return early from a function body writing out the explicit and encouraged to return early from a function body writing out the explicit
@ -626,19 +627,19 @@ Expressions
Because variable declarations occur at the top of scope, assignment can Because variable declarations occur at the top of scope, assignment can
be used within expressions, even for variables that haven't been seen before: be used within expressions, even for variables that haven't been seen before:
</p> </p>
<%= code_for('expressions_assignment', 'six') %> <%= code_for 'expressions_assignment', 'six' %>
<p> <p>
Things that would otherwise be statements in JavaScript, when used Things that would otherwise be statements in JavaScript, when used
as part of an expression in CoffeeScript, are converted into expressions as part of an expression in CoffeeScript, are converted into expressions
by wrapping them in a closure. This lets you do useful things, like assign by wrapping them in a closure. This lets you do useful things, like assign
the result of a comprehension to a variable: the result of a comprehension to a variable:
</p> </p>
<%= code_for('expressions_comprehension', 'globals') %> <%= code_for 'expressions_comprehension', 'globals' %>
<p> <p>
As well as silly things, like passing a <b>try/catch</b> statement directly As well as silly things, like passing a <b>try/catch</b> statement directly
into a function call: into a function call:
</p> </p>
<%= code_for('expressions_try', true) %> <%= code_for 'expressions_try', true %>
<p> <p>
There are a handful of statements in JavaScript that can't be meaningfully There are a handful of statements in JavaScript that can't be meaningfully
converted into expressions, namely <tt>break</tt>, <tt>continue</tt>, converted into expressions, namely <tt>break</tt>, <tt>continue</tt>,
@ -706,7 +707,7 @@ Expressions
<tr><td><tt>a %% b</tt></td><td><tt>(a % b + b) % b</tt></td></tr> <tr><td><tt>a %% b</tt></td><td><tt>(a % b + b) % b</tt></td></tr>
</table> </table>
<%= code_for('aliases') %> <%= code_for 'aliases' %>
<p> <p>
<b class="header">The Existential Operator</b> <b class="header">The Existential Operator</b>
@ -720,7 +721,7 @@ Expressions
It can also be used for safer conditional assignment than <tt>||=</tt> It can also be used for safer conditional assignment than <tt>||=</tt>
provides, for cases where you may be handling numbers or strings. provides, for cases where you may be handling numbers or strings.
</p> </p>
<%= code_for('existence', 'footprints') %> <%= code_for 'existence', 'footprints' %>
<p> <p>
The accessor variant of the existential operator <tt>?.</tt> can be used to soak The accessor variant of the existential operator <tt>?.</tt> can be used to soak
up null references in a chain of properties. Use it instead up null references in a chain of properties. Use it instead
@ -729,7 +730,7 @@ Expressions
result, if the chain is broken, <b>undefined</b> is returned instead of result, if the chain is broken, <b>undefined</b> is returned instead of
the <b>TypeError</b> that would be raised otherwise. the <b>TypeError</b> that would be raised otherwise.
</p> </p>
<%= code_for('soaks') %> <%= code_for 'soaks' %>
<p> <p>
Soaking up nulls is similar to Ruby's Soaking up nulls is similar to Ruby's
<a href="http://andand.rubyforge.org/">andand gem</a>, and to the <a href="http://andand.rubyforge.org/">andand gem</a>, and to the
@ -762,7 +763,7 @@ Expressions
Constructor functions are named, to better support helpful stack traces. Constructor functions are named, to better support helpful stack traces.
In the first class in the example below, <tt>this.constructor.name is "Animal"</tt>. In the first class in the example below, <tt>this.constructor.name is "Animal"</tt>.
</p> </p>
<%= code_for('classes', true) %> <%= code_for 'classes', true %>
<p> <p>
If structuring your prototypes classically isn't your cup of tea, CoffeeScript If structuring your prototypes classically isn't your cup of tea, CoffeeScript
provides a couple of lower-level conveniences. The <tt>extends</tt> operator provides a couple of lower-level conveniences. The <tt>extends</tt> operator
@ -771,7 +772,7 @@ Expressions
quick access to an object's prototype; and <tt>super()</tt> quick access to an object's prototype; and <tt>super()</tt>
is converted into a call against the immediate ancestor's method of the same name. is converted into a call against the immediate ancestor's method of the same name.
</p> </p>
<%= code_for('prototypes', '"one_two".dasherize()') %> <%= code_for 'prototypes', '"one_two".dasherize()' %>
<p> <p>
Finally, class definitions are blocks of executable code, which make for interesting Finally, class definitions are blocks of executable code, which make for interesting
metaprogramming possibilities. Because in the context of a class definition, metaprogramming possibilities. Because in the context of a class definition,
@ -791,30 +792,30 @@ Expressions
on the right to the variables on the left. In the simplest case, it can be on the right to the variables on the left. In the simplest case, it can be
used for parallel assignment: used for parallel assignment:
</p> </p>
<%= code_for('parallel_assignment', 'theBait') %> <%= code_for 'parallel_assignment', 'theBait' %>
<p> <p>
But it's also helpful for dealing with functions that return multiple But it's also helpful for dealing with functions that return multiple
values. values.
</p> </p>
<%= code_for('multiple_return_values', 'forecast') %> <%= code_for 'multiple_return_values', 'forecast' %>
<p> <p>
Destructuring assignment can be used with any depth of array and object nesting, Destructuring assignment can be used with any depth of array and object nesting,
to help pull out deeply nested properties. to help pull out deeply nested properties.
</p> </p>
<%= code_for('object_extraction', '"#{name} - #{street}"') %> <%= code_for 'object_extraction', '"name + "-" + street"' %>
<p> <p>
Destructuring assignment can even be combined with splats. Destructuring assignment can even be combined with splats.
</p> </p>
<%= code_for('patterns_and_splats', 'contents.join("")') %> <%= code_for 'patterns_and_splats', 'contents.join("")' %>
<p> <p>
Expansion can be used to retrieve elements from the end of an array without having to assign the rest of its values. It works in the function argument list as well. Expansion can be used to retrieve elements from the end of an array without having to assign the rest of its values. It works in the function argument list as well.
</p> </p>
<%= code_for('expansions', '"#{first} #{last}"') %> <%= code_for 'expansions', '"first + " " + last"' %>
<p> <p>
Destructuring assignment is also useful when combined with class constructors Destructuring assignment is also useful when combined with class constructors
to assign properties to your instance from an options object passed to the constructor. to assign properties to your instance from an options object passed to the constructor.
</p> </p>
<%= code_for('constructor_destructuring', 'tim.age') %> <%= code_for 'constructor_destructuring', 'tim.age' %>
<p> <p>
<span id="fat-arrow" class="bookmark"></span> <span id="fat-arrow" class="bookmark"></span>
@ -834,7 +835,7 @@ Expressions
to use with <tt>bind</tt>. Functions created with the fat arrow are able to access to use with <tt>bind</tt>. Functions created with the fat arrow are able to access
properties of the <tt>this</tt> where they're defined. properties of the <tt>this</tt> where they're defined.
</p> </p>
<%= code_for('fat_arrow') %> <%= code_for 'fat_arrow' %>
<p> <p>
If we had used <tt>-&gt;</tt> in the callback above, <tt>@customer</tt> would If we had used <tt>-&gt;</tt> in the callback above, <tt>@customer</tt> would
have referred to the undefined "customer" property of the DOM element, have referred to the undefined "customer" property of the DOM element,
@ -853,7 +854,7 @@ Expressions
snippets of JavaScript within your CoffeeScript, you can snippets of JavaScript within your CoffeeScript, you can
use backticks to pass it straight through. use backticks to pass it straight through.
</p> </p>
<%= code_for('embedded', 'hi()') %> <%= code_for 'embedded', 'hi()' %>
<p> <p>
<span id="switch" class="bookmark"></span> <span id="switch" class="bookmark"></span>
@ -870,12 +871,12 @@ Expressions
values for each <b>when</b> clause. If any of the values match, the clause values for each <b>when</b> clause. If any of the values match, the clause
runs. runs.
</p> </p>
<%= code_for('switch') %> <%= code_for 'switch' %>
<p> <p>
Switch statements can also be used without a control expression, turning them in to a cleaner alternative to if/else chains. Switch statements can also be used without a control expression, turning them in to a cleaner alternative to if/else chains.
</p> </p>
<%= code_for('switch_with_no_expression') %> <%= code_for 'switch_with_no_expression' %>
<p> <p>
<span id="try" class="bookmark"></span> <span id="try" class="bookmark"></span>
@ -883,7 +884,7 @@ Expressions
Try/catch statements are just about the same as JavaScript (although Try/catch statements are just about the same as JavaScript (although
they work as expressions). they work as expressions).
</p> </p>
<%= code_for('try') %> <%= code_for 'try' %>
<p> <p>
<span id="comparisons" class="bookmark"></span> <span id="comparisons" class="bookmark"></span>
@ -893,7 +894,7 @@ Expressions
from Python &mdash; making it easy to test if a value falls within a from Python &mdash; making it easy to test if a value falls within a
certain range. certain range.
</p> </p>
<%= code_for('comparisons', 'healthy') %> <%= code_for 'comparisons', 'healthy' %>
<p> <p>
<span id="strings" class="bookmark"></span> <span id="strings" class="bookmark"></span>
@ -902,18 +903,18 @@ Expressions
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.
</p> </p>
<%= code_for('interpolation', 'sentence') %> <%= code_for 'interpolation', 'sentence' %>
<p> <p>
Multiline strings are allowed in CoffeeScript. Lines are joined by a single space unless they end with a backslash. Indentation is ignored. Multiline strings are allowed in CoffeeScript. Lines are joined by a single space unless they end with a backslash. Indentation is ignored.
</p> </p>
<%= code_for('strings', 'mobyDick') %> <%= code_for 'strings', 'mobyDick' %>
<p> <p>
Block strings 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 block 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 block strings, like other double-quoted strings, allow interpolation. Double-quoted block strings, like other double-quoted strings, allow interpolation.
</p> </p>
@ -923,7 +924,7 @@ Expressions
the top of a file. Block comments, which mirror the syntax for block strings, 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>
@ -934,7 +935,7 @@ Expressions
block regexes 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' %>
<h2> <h2>
@ -960,7 +961,7 @@ Expressions
be made available in the <tt>options</tt> object. Here's a task that uses be made available in the <tt>options</tt> object. Here's a task that uses
the Node.js API to rebuild CoffeeScript's parser: the Node.js API to rebuild CoffeeScript's parser:
</p> </p>
<%= code_for('cake_tasks') %> <%= code_for 'cake_tasks' %>
<p> <p>
If you need to invoke one task before another &mdash; for example, running If you need to invoke one task before another &mdash; for example, running
<tt>build</tt> before <tt>test</tt>, you can use the <tt>invoke</tt> function: <tt>build</tt> before <tt>test</tt>, you can use the <tt>invoke</tt> function:
@ -1255,7 +1256,7 @@ Expressions
</li> </li>
</ul> </ul>
</p> </p>
<%= code_for('chaining') %> <%= code_for 'chaining' %>
<p> <p>
<b class="header" style="margin-top: 20px;"> <b class="header" style="margin-top: 20px;">
<a href="https://github.com/jashkenas/coffee-script/compare/1.6.2...1.6.3">1.6.3</a> <a href="https://github.com/jashkenas/coffee-script/compare/1.6.2...1.6.3">1.6.3</a>

View file

@ -1,7 +1,7 @@
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
/* /*
SkinnyMochaHalfCaffScript Compiler v1.0 SkinnyMochaHalfCaffScript Compiler v1.0
Released under the MIT License Released under the MIT License
*/ */

View file

@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
var Animal, Horse, Snake, sam, tom, _ref, _ref1, var Animal, Horse, Snake, sam, tom,
__hasProp = {}.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
@ -20,8 +20,7 @@ Snake = (function(_super) {
__extends(Snake, _super); __extends(Snake, _super);
function Snake() { function Snake() {
_ref = Snake.__super__.constructor.apply(this, arguments); return Snake.__super__.constructor.apply(this, arguments);
return _ref;
} }
Snake.prototype.move = function() { Snake.prototype.move = function() {
@ -37,8 +36,7 @@ Horse = (function(_super) {
__extends(Horse, _super); __extends(Horse, _super);
function Horse() { function Horse() {
_ref1 = Horse.__super__.constructor.apply(this, arguments); return Horse.__super__.constructor.apply(this, arguments);
return _ref1;
} }
Horse.prototype.move = function() { Horse.prototype.move = function() {

View file

@ -0,0 +1,6 @@
// Generated by CoffeeScript 1.6.3
var first, last, text, _ref;
text = "Every literary critic believes he will outwit history and have the last word";
_ref = text.split(" "), first = _ref[0], last = _ref[_ref.length - 1];

View file

@ -2,10 +2,11 @@
var Account; var Account;
Account = function(customer, cart) { Account = function(customer, cart) {
var _this = this;
this.customer = customer; this.customer = customer;
this.cart = cart; this.cart = cart;
return $('.shopping_cart').bind('click', function(event) { return $('.shopping_cart').bind('click', (function(_this) {
return _this.customer.purchase(_this.cart); return function(event) {
}); return _this.customer.purchase(_this.cart);
};
})(this));
}; };

View file

@ -16,7 +16,7 @@ lyrics = (function() {
var _results; var _results;
_results = []; _results = [];
while (num -= 1) { while (num -= 1) {
_results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head."); _results.push("" + num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
} }
return _results; return _results;
})(); })();

1266
index.html

File diff suppressed because it is too large Load diff

View file

@ -1,33 +1,39 @@
{ {
"name": "coffee-script", "name": "coffee-script",
"description": "Unfancy JavaScript", "description": "Unfancy JavaScript",
"keywords": ["javascript", "language", "coffeescript", "compiler"], "keywords": [
"author": "Jeremy Ashkenas", "javascript",
"version": "1.6.3", "language",
"license": "MIT", "coffeescript",
"engines": { "compiler"
"node": ">=0.8.0" ],
"author": "Jeremy Ashkenas",
"version": "1.6.3",
"license": "MIT",
"engines": {
"node": ">=0.8.0"
}, },
"directories" : { "directories": {
"lib" : "./lib/coffee-script" "lib": "./lib/coffee-script"
}, },
"main" : "./lib/coffee-script/coffee-script", "main": "./lib/coffee-script/coffee-script",
"bin": { "bin": {
"coffee": "./bin/coffee", "coffee": "./bin/coffee",
"cake": "./bin/cake" "cake": "./bin/cake"
}, },
"scripts": { "scripts": {
"test": "node ./bin/cake test" "test": "node ./bin/cake test"
}, },
"homepage": "http://coffeescript.org", "homepage": "http://coffeescript.org",
"bugs": "https://github.com/jashkenas/coffee-script/issues", "bugs": "https://github.com/jashkenas/coffee-script/issues",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/jashkenas/coffee-script.git" "url": "git://github.com/jashkenas/coffee-script.git"
}, },
"devDependencies": { "devDependencies": {
"uglify-js": "~2.2", "uglify-js": "~2.2",
"jison": ">=0.2.0" "jison": ">=0.2.0",
"highlight.js": "~8.0.0"
}, },
"dependencies": { "dependencies": {
"mkdirp": "~0.3.5" "mkdirp": "~0.3.5"