From ff1725b367d919d905082285b94fcfbaa7c8149e Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Sun, 11 Dec 2016 20:29:08 -0800 Subject: [PATCH] =?UTF-8?q?Handle=20ids=20within=20the=20template,=20not?= =?UTF-8?q?=20in=20the=20Cakefile;=20remove=20marked=E2=80=99s=20auto-gene?= =?UTF-8?q?rated=20and=20conflicting=20ids?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cakefile | 3 +- docs/v1/index.html | 193 ++++++++++++------------------------- documentation/v1/body.html | 109 ++++++++++++++------- 3 files changed, 134 insertions(+), 171 deletions(-) diff --git a/Cakefile b/Cakefile index 5bcf6230..88fc6748 100644 --- a/Cakefile +++ b/Cakefile @@ -180,6 +180,8 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit htmlFor = -> marked = require 'marked' markdownRenderer = new marked.Renderer() + markdownRenderer.heading = (text, level) -> + "#{text}" # Don’t let marked add an id markdownRenderer.code = (code) -> if code.indexOf('codeFor(') is 0 or code.indexOf('releaseHeader(') is 0 "<%= #{code} %>" @@ -195,7 +197,6 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit html = _.template(html) codeFor: codeFor() releaseHeader: releaseHeader - "\n\n#{html}" include = -> (file) -> diff --git a/docs/v1/index.html b/docs/v1/index.html index fc2ae5d2..61c5e485 100644 --- a/docs/v1/index.html +++ b/docs/v1/index.html @@ -599,20 +599,16 @@ pre .xml .cdata { -
- - -

CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

+
+ +

CoffeeScript is a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.

The golden rule of CoffeeScript is: “It’s just JavaScript”. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable, pretty-printed, and tends to run as fast or faster than the equivalent handwritten JavaScript.

The CoffeeScript compiler goes to great lengths to generate output JavaScript that runs in every JavaScript runtime, but there are exceptions. Use generator functions, for…from, or tagged template literals only if you know that your target runtimes can support them. If you use modules, you will need to use an additional tool to resolve them.

Latest Version: 1.12.1

npm install -g coffee-script
- - -

Overview

-

CoffeeScript on the left, compiled JavaScript output on the right.

+

Overview

CoffeeScript on the left, compiled JavaScript output on the right.

# Assignment:
 number   = 42
 opposite = true
@@ -731,9 +727,7 @@ cubes = (function() {
 })();
 ;alert(cubes);">run: cubes

- -

Installation

-

The CoffeeScript compiler is itself written in CoffeeScript, using the Jison parser generator. The command-line version of coffee is available as a Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (see “Try CoffeeScript”, above).

+

Installation

The CoffeeScript compiler is itself written in CoffeeScript, using the Jison parser generator. The command-line version of coffee is available as a Node.js utility. The core compiler however, does not depend on Node, and can be run in any JavaScript environment, or in the browser (see “Try CoffeeScript”, above).

To install, first make sure you have a working copy of the latest stable version of Node.js. You can then install CoffeeScript globally with npm:

npm install -g coffee-script
@@ -748,9 +742,7 @@ cubes = (function() {
sudo bin/cake install
- -

Usage

-

Once installed, you should have access to the coffee command, which can execute scripts, compile .coffee files into .js, and provide an interactive REPL. The coffee command takes the following options:

+

Usage

Once installed, you should have access to the coffee command, which can execute scripts, compile .coffee files into .js, and provide an interactive REPL. The coffee command takes the following options:

@@ -910,8 +902,7 @@ cubes = (function() {
-

Examples:

-
    +

    Examples:

    • Compile a directory tree of .coffee files in src into a parallel tree of .js files in lib:
      coffee --compile --output lib/ src/
    • Watch a file for changes, and recompile it every time the file is saved:
      @@ -927,25 +918,19 @@ cubes = (function() {
    - -

    Literate CoffeeScript

    -

    Besides being used as an ordinary programming language, CoffeeScript may also be written in “literate” mode. If you name your file with a .litcoffee extension, you can write it as a Markdown document — a document that also happens to be executable CoffeeScript code. The compiler will treat any indented blocks (Markdown’s way of indicating source code) as code, and ignore the rest as comments.

    +

    Literate CoffeeScript

    Besides being used as an ordinary programming language, CoffeeScript may also be written in “literate” mode. If you name your file with a .litcoffee extension, you can write it as a Markdown document — a document that also happens to be executable CoffeeScript code. The compiler will treat any indented blocks (Markdown’s way of indicating source code) as code, and ignore the rest as comments.

    Just for kicks, a little bit of the compiler is currently implemented in this fashion: See it as a document, raw, and properly highlighted in a text editor.

    I’m fairly excited about this direction for the language, and am looking forward to writing (and more importantly, reading) more programs in this style. More information about Literate CoffeeScript, including an example program, are available in this blog post.

    - -

    Language Reference

    -

    This reference is structured so that it can be read from top to bottom, if you like. Later sections use ideas and syntax previously introduced. Familiarity with JavaScript is assumed. In all of the following examples, the source CoffeeScript is provided on the left, and the direct compilation into JavaScript is on the right.

    +

    Language Reference

    This reference is structured so that it can be read from top to bottom, if you like. Later sections use ideas and syntax previously introduced. Familiarity with JavaScript is assumed. In all of the following examples, the source CoffeeScript is provided on the left, and the direct compilation into JavaScript is on the right.

    Many of the examples can be run (where it makes sense) by pressing the run button on the right, and can be loaded into the “Try CoffeeScript” console by pressing the load button on the left.

    First, the basics: CoffeeScript uses significant whitespace to delimit blocks of code. You don’t need to use semicolons ; to terminate expressions, ending the line will do just as well (although semicolons can still be used to fit multiple expressions onto a single line). Instead of using curly braces { } to surround blocks of code in functions, if-statements, switch, and try/catch, use indentation.

    You don’t need to use parentheses to invoke a function if you’re passing arguments. The implicit call wraps forward to the end of the line or block expression.
    console.log sys.inspect objectconsole.log(sys.inspect(object));

    - - -

    Functions

    -

    Functions are defined by an optional list of parameters in parentheses, an arrow, and the function body. The empty function looks like this: ->

    + +

    Functions

    Functions are defined by an optional list of parameters in parentheses, an arrow, and the function body. The empty function looks like this: ->

    square = (x) -> x * x
     cube   = (x) -> square(x) * x
     
    var cube, square;
    @@ -986,10 +971,8 @@ fill = function(container, liquid) {
       return "Filling the " + container + " with " + liquid + "...";
     };
     ;alert(fill("cup"));">run: fill("cup")

- - -

Objects and Arrays

-

The CoffeeScript literals for objects and arrays look very similar to their JavaScript cousins. When each property is listed on its own line, the commas are optional. Objects may be created using indentation instead of explicit braces, similar to YAML.

+ +

Objects and Arrays

The CoffeeScript literals for objects and arrays look very similar to their JavaScript cousins. When each property is listed on its own line, the commas are optional. Objects may be created using indentation instead of explicit braces, similar to YAML.

song = ["do", "re", "mi", "fa", "so"]
 
 singers = {Jagger: "Rock", Elvis: "Roll"}
@@ -1080,10 +1063,8 @@ turtle = {
 
 output = turtle.name + " wears an " + turtle.mask + " mask. Watch out for his " + turtle.weapon + "!";
 
load

- - -

Lexical Scoping and Variable Safety

-

The CoffeeScript compiler takes care to make sure that all of your variables are properly declared within lexical scope — you never need to write var yourself.

+ +

Lexical Scoping and Variable Safety

The CoffeeScript compiler takes care to make sure that all of your variables are properly declared within lexical scope — you never need to write var yourself.

outer = 1
 changeNumbers = ->
   inner = -1
@@ -1116,10 +1097,8 @@ inner = changeNumbers();
 

Although suppressed within this documentation for clarity, all CoffeeScript output is wrapped in an anonymous function: (function(){ … })(); This safety wrapper, combined with the automatic generation of the var keyword, make it exceedingly difficult to pollute the global namespace by accident.

If you’d like to create top-level variables for other scripts to use, attach them as properties on window; attach them as properties on the exports object in CommonJS; or use an export statement. If you’re targeting both CommonJS and the browser, the existential operator (covered below), gives you a reliable way to figure out where to add them: exports ? this

- - -

If, Else, Unless, and Conditional Assignment

-

If/else statements can be written without the use of parentheses and curly brackets. As with functions and other block expressions, multi-line conditionals are delimited by indentation. There’s also a handy postfix form, with the if or unless at the end.

+ +

If, Else, Unless, and Conditional Assignment

If/else statements can be written without the use of parentheses and curly brackets. As with functions and other block expressions, multi-line conditionals are delimited by indentation. There’s also a handy postfix form, with the if or unless at the end.

CoffeeScript can compile if statements into JavaScript expressions, using the ternary operator when possible, and closure wrapping otherwise. There is no explicit ternary statement in CoffeeScript — you simply use a regular if statement on a single line.

mood = greatlyImproved if singing
 
@@ -1145,10 +1124,8 @@ date = if friday then
 
 date = friday ? sue : jill;
 
load

- - -

Splats…

-

The JavaScript arguments object is a useful way to work with functions that accept variable numbers of arguments. CoffeeScript provides splats ..., both for function definition as well as invocation, making variable numbers of arguments a little bit more palatable.

+ +

Splats…

The JavaScript arguments object is a useful way to work with functions that accept variable numbers of arguments. CoffeeScript provides splats ..., both for function definition as well as invocation, making variable numbers of arguments a little bit more palatable.

gold = silver = rest = "unknown"
 
 awardMedals = (first, second, others...) ->
@@ -1219,10 +1196,8 @@ alert("Silver: " + silver);
 
 alert("The Field: " + rest);
 ;">run

- - -

Loops and Comprehensions

-

Most of the loops you’ll write in CoffeeScript will be comprehensions over arrays, objects, and ranges. Comprehensions replace (and compile into) for loops, with optional guard clauses and the value of the current array index. Unlike for loops, array comprehensions are expressions, and can be returned and assigned.

+ +

Loops and Comprehensions

Most of the loops you’ll write in CoffeeScript will be comprehensions over arrays, objects, and ranges. Comprehensions replace (and compile into) for loops, with optional guard clauses and the value of the current array index. Unlike for loops, array comprehensions are expressions, and can be returned and assigned.

# Eat lunch.
 eat food for food in ['toast', 'cheese', 'wine']
 
@@ -1397,10 +1372,8 @@ fn = function(\n    fs.readFile filename, (err, contents) ->\n      compile filename, contents.toString()\n"
load

- - -

Array Slicing and Splicing with Ranges

-

Ranges can also be used to extract slices of arrays. With two dots (3..6), the range is inclusive (3, 4, 5, 6); with three dots (3...6), the range excludes the end (3, 4, 5). Slices indices have useful defaults. An omitted first index defaults to zero and an omitted second index defaults to the size of the array.

+ +

Array Slicing and Splicing with Ranges

Ranges can also be used to extract slices of arrays. With two dots (3..6), the range is inclusive (3, 4, 5, 6); with three dots (3...6), the range excludes the end (3, 4, 5). Slices indices have useful defaults. An omitted first index defaults to zero and an omitted second index defaults to the size of the array.

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
 
 start   = numbers[0..2]
@@ -1448,10 +1421,8 @@ numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
 [].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;
 ;alert(numbers);">run: numbers

Note that JavaScript strings are immutable, and can’t be spliced.

- - -

Everything is an Expression (at least, as much as possible)

-

You might have noticed how even though we don’t add return statements to CoffeeScript functions, they nonetheless return their final value. The CoffeeScript compiler tries to make sure that all statements in the language can be used as expressions. Watch how the return gets pushed down into each possible branch of execution in the function below.

+ +

Everything is an Expression (at least, as much as possible)

You might have noticed how even though we don’t add return statements to CoffeeScript functions, they nonetheless return their final value. The CoffeeScript compiler tries to make sure that all statements in the language can be used as expressions. Watch how the return gets pushed down into each possible branch of execution in the function below.

grade = (student) ->
   if student.excellentWork
     "A+"
@@ -1557,10 +1528,8 @@ alert((function() {
 })());
 ;">run

There are a handful of statements in JavaScript that can’t be meaningfully converted into expressions, namely break, continue, and return. If you make use of them within a block of code, CoffeeScript won’t try to perform the conversion.

- - -

Operators and Aliases

-

Because the == operator frequently causes undesirable coercion, is intransitive, and has a different meaning than in other languages, CoffeeScript compiles == into ===, and != into !==. In addition, is compiles into ===, and isnt into !==.

+ +

Operators and Aliases

Because the == operator frequently causes undesirable coercion, is intransitive, and has a different meaning than in other languages, CoffeeScript compiles == into ===, and != into !==. In addition, is compiles into ===, and isnt into !==.

You can use not as an alias for !.

For logic, and compiles to &&, and or into ||.

Instead of a newline or semicolon, then can be used to separate conditions from expressions, in while, if/else, and switch/when statements.

@@ -1736,10 +1705,8 @@ winner = yes if pick < print(inspect("My name is " + this.name));
load

- - -

The Existential Operator

-

It’s a little difficult to check for the existence of a variable in JavaScript. if (variable) … comes close, but fails for zero, the empty string, and false. CoffeeScript’s existential operator ? returns true unless a variable is null or undefined, which makes it analogous to Ruby’s nil?

+ +

The Existential Operator

It’s a little difficult to check for the existence of a variable in JavaScript. if (variable) … comes close, but fails for zero, the empty string, and false. CoffeeScript’s existential operator ? returns true unless a variable is null or undefined, which makes it analogous to Ruby’s nil?

It can also be used for safer conditional assignment than ||= provides, for cases where you may be handling numbers or strings.

solipsism = true if mind? and not world?
 
@@ -1780,10 +1747,8 @@ footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : &qu
 zip = typeof lottery.drawWinner === "function" ? (ref = lottery.drawWinner().address) != null ? ref.zipcode : void 0 : void 0;
 
load

Soaking up nulls is similar to Ruby’s andand gem, and to the safe navigation operator in Groovy.

- - -

Classes, Inheritance, and Super

-

JavaScript’s prototypal inheritance has always been a bit of a brain-bender, with a whole family tree of libraries that provide a cleaner syntax for classical inheritance on top of JavaScript’s prototypes: Base2, Prototype.js, JS.Class, etc. The libraries provide syntactic sugar, but the built-in inheritance would be completely usable if it weren’t for a couple of small exceptions: it’s awkward to call super (the prototype object’s implementation of the current function), and it’s awkward to correctly set the prototype chain.

+ +

Classes, Inheritance, and Super

JavaScript’s prototypal inheritance has always been a bit of a brain-bender, with a whole family tree of libraries that provide a cleaner syntax for classical inheritance on top of JavaScript’s prototypes: Base2, Prototype.js, JS.Class, etc. The libraries provide syntactic sugar, but the built-in inheritance would be completely usable if it weren’t for a couple of small exceptions: it’s awkward to call super (the prototype object’s implementation of the current function), and it’s awkward to correctly set the prototype chain.

Instead of repetitively attaching functions to a prototype, CoffeeScript provides a basic class structure that allows you to name your class, set the superclass, assign prototypal properties, and define the constructor, in a single assignable expression.

Constructor functions are named, to better support helpful stack traces. In the first class in the example below, this.constructor.name is "Animal".

class Animal
@@ -1931,10 +1896,8 @@ tom.move();
 ;alert("one_two".dasherize());">run: "one_two".dasherize()

Finally, class definitions are blocks of executable code, which make for interesting metaprogramming possibilities. Because in the context of a class definition, this is the class object itself (the constructor function), you can assign static properties by using @property: value, and call functions defined in parent classes: @attr 'title', type: 'text'

- - -

Destructuring Assignment

-

Just like JavaScript (since ES2015), CoffeeScript has destructuring assignment syntax. When you assign an array or object literal to a value, CoffeeScript breaks up and matches both sides against each other, assigning the values on the right to the variables on the left. In the simplest case, it can be used for parallel assignment:

+ +

Destructuring Assignment

Just like JavaScript (since ES2015), CoffeeScript has destructuring assignment syntax. When you assign an array or object literal to a value, CoffeeScript breaks up and matches both sides against each other, assigning the values on the right to the variables on the left. In the simplest case, it can be used for parallel assignment:

theBait   = 1000
 theSwitch = 0
 
@@ -2080,10 +2043,8 @@ tim = new Person({
 });
 ;alert(tim.age + " " + tim.height);">run: tim.age + " " + tim.height

The above example also demonstrates that if properties are missing in the destructured object or array, you can, just like in JavaScript, provide defaults. The difference with JavaScript is that CoffeeScript, as always, treats both null and undefined the same.

- - -

Bound Functions, Generator Functions

-

In JavaScript, the this keyword is dynamically scoped to mean the object that the current function is attached to. If you pass a function as a callback or attach it to a different object, the original value of this will be lost. If you’re not familiar with this behavior, this Digital Web article gives a good overview of the quirks.

+ +

Bound Functions, Generator Functions

In JavaScript, the this keyword is dynamically scoped to mean the object that the current function is attached to. If you pass a function as a callback or attach it to a different object, the original value of this will be lost. If you’re not familiar with this behavior, this Digital Web article gives a good overview of the quirks.

The fat arrow => can be used to both define a function, and to bind it to the current value of this, right on the spot. This is helpful when using callback-based libraries like Prototype or jQuery, for creating iterator functions to pass to each, or event-handler functions to use with on. Functions created with the fat arrow are able to access properties of the this where they’re defined.

Account = (customer, cart) ->
   @customer = customer
@@ -2199,10 +2160,8 @@ getFibonacciNumbers = function(length) {
   return results;
 };
 ;alert(getFibonacciNumbers(10));">run: getFibonacciNumbers(10)

- - -

Embedded JavaScript

-

Hopefully, you’ll never need to use it, but if you ever need to intersperse snippets of JavaScript within your CoffeeScript, you can use backticks to pass it straight through.

+ +

Embedded JavaScript

Hopefully, you’ll never need to use it, but if you ever need to intersperse snippets of JavaScript within your CoffeeScript, you can use backticks to pass it straight through.

hi = `function() {
   return [document.title, "Hello JavaScript"].join(": ");
 }`
@@ -2250,10 +2209,8 @@ function time() {
 ;
 
 ;alert(time());">run: time()

- - -

Switch/When/Else

-

Switch statements in JavaScript are a bit awkward. You need to remember to break at the end of every case statement to avoid accidentally falling through to the default case. CoffeeScript prevents accidental fall-through, and can convert the switch into a returnable, assignable expression. The format is: switch condition, when clauses, else the default case.

+ +

Switch/When/Else

Switch statements in JavaScript are a bit awkward. You need to remember to break at the end of every case statement to avoid accidentally falling through to the default case. CoffeeScript prevents accidental fall-through, and can convert the switch into a returnable, assignable expression. The format is: switch condition, when clauses, else the default case.

As in Ruby, switch statements in CoffeeScript can take multiple values for each when clause. If any of the values match, the clause runs.

switch day
   when "Mon" then go work
@@ -2316,10 +2273,8 @@ grade = (function(
load

- - -

Try/Catch/Finally

-

Try-expressions have the same semantics as try-statements in JavaScript, though in CoffeeScript, you may omit both the catch and finally parts. The catch part may also omit the error parameter if it is not needed.

+ +

Try/Catch/Finally

Try-expressions have the same semantics as try-statements in JavaScript, though in CoffeeScript, you may omit both the catch and finally parts. The catch part may also omit the error parameter if it is not needed.

try
   allHellBreaksLoose()
   catsAndDogsLivingTogether()
@@ -2339,10 +2294,8 @@ grade = (function(
load

- - -

Chained Comparisons

-

CoffeeScript borrows chained comparisons from Python — making it easy to test if a value falls within a certain range.

+ +

Chained Comparisons

CoffeeScript borrows chained comparisons from Python — making it easy to test if a value falls within a certain range.

cholesterol = 127
 
 healthy = 200 > cholesterol > 60
@@ -2357,10 +2310,8 @@ cholesterol = 127;
 
 healthy = (200 > cholesterol && cholesterol > 60);
 ;alert(healthy);">run: healthy

- - -

String Interpolation, Block Strings, and Block Comments

-

Ruby-style string interpolation is included in CoffeeScript. Double-quoted strings allow for interpolated values, using #{ … }, and single-quoted strings are literal. You may even use interpolation in object keys.

+ +

String Interpolation, Block Strings, and Block Comments

Ruby-style string interpolation is included in CoffeeScript. Double-quoted strings allow for interpolated values, using #{ … }, and single-quoted strings are literal. You may even use interpolation in object keys.

author = "Wittgenstein"
 quote  = "A picture is a fact. -- #{ author }"
 
@@ -2417,10 +2368,8 @@ Released under the MIT License
  */
 
 
load

- - -

Tagged Template Literals

-

CoffeeScript supports ES2015 tagged template literals, which enable customized string interpolation. If you immediately prefix a string with a function name (no space between the two), CoffeeScript will output this “function plus string” combination as an ES2015 tagged template literal, which will behave accordingly: the function is called, with the parameters being the input text and expression parts that make up the interpolated string. The function can then assemble these parts into an output string, providing custom string interpolation.

+ +

Tagged Template Literals

CoffeeScript supports ES2015 tagged template literals, which enable customized string interpolation. If you immediately prefix a string with a function name (no space between the two), CoffeeScript will output this “function plus string” combination as an ES2015 tagged template literal, which will behave accordingly: the function is called, with the parameters being the input text and expression parts that make up the interpolated string. The function can then assemble these parts into an output string, providing custom string interpolation.

Be aware that the CoffeeScript compiler is outputting ES2015 syntax for this feature, so your target JavaScript runtime(s) must support this syntax for your code to work; or you could use tools like Babel or Traceur Compiler to convert this ES2015 syntax into compatible JavaScript.

upperCaseExpr = (textParts, expressions...) ->
   textParts.reduce (text, textPart, i) ->
@@ -2459,10 +2408,8 @@ greet = function(name, adjective) {
   return upperCaseExpr`Hi ${name}. You look ${adjective}!`;
 };
 ;alert(greet("greg", "awesome"));">run: greet("greg", "awesome")

- - -

Block Regular Expressions

-

Similar to block strings and comments, CoffeeScript supports block regexes — extended regular expressions that ignore internal whitespace and can contain comments and interpolation. Modeled after Perl’s /x modifier, CoffeeScript’s block regexes are delimited by /// and go a long way towards making complex regular expressions readable. To quote from the CoffeeScript source:

+ +

Block Regular Expressions

Similar to block strings and comments, CoffeeScript supports block regexes — extended regular expressions that ignore internal whitespace and can contain comments and interpolation. Modeled after Perl’s /x modifier, CoffeeScript’s block regexes are delimited by /// and go a long way towards making complex regular expressions readable. To quote from the CoffeeScript source:

OPERATOR = /// ^ (
   ?: [-=]>             # function
    | [-+*/%<>&|^!?=]=  # compound assign / compare
@@ -2476,10 +2423,8 @@ greet = function(name, adjective) {
 
 OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
 
load

- - -

Modules

-

ES2015 modules are supported in CoffeeScript, with very similar import and export syntax:

+ +

Modules

ES2015 modules are supported in CoffeeScript, with very similar import and export syntax:

import 'local-file.coffee'
 import 'coffee-script'
 
@@ -2571,9 +2516,7 @@ OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>&g
 

Also note that any file with an import or export statement will be output without a top-level function safety wrapper; in other words, importing or exporting modules will automatically trigger bare mode for that file. This is because per the ES2015 spec, import or export statements must occur at the topmost scope.

- -

Cake, and Cakefiles

-

CoffeeScript includes a (very) simple build system similar to Make and Rake. Naturally, it’s called Cake, and is used for the tasks that build and test the CoffeeScript language itself. Tasks are defined in a file named Cakefile, and can be invoked by running cake [task] from within the directory. To print a list of all the tasks and options, just type cake.

+

Cake, and Cakefiles

CoffeeScript includes a (very) simple build system similar to Make and Rake. Naturally, it’s called Cake, and is used for the tasks that build and test the CoffeeScript language itself. Tasks are defined in a file named Cakefile, and can be invoked by running cake [task] from within the directory. To print a list of all the tasks and options, just type cake.

Task definitions are written in CoffeeScript, so you can put arbitrary code in your Cakefile. Define a task with a name, a long description, and the function to invoke when the task is run. If your task takes a command-line option, you can define the option with short and long flags, and it will be made available in the options object. Here’s a task that uses the Node.js API to rebuild CoffeeScript’s parser:

fs = require 'fs'
 
@@ -2600,22 +2543,16 @@ task('build:parser', 'rebuild t
 
load

If you need to invoke one task before another — for example, running build before test, you can use the invoke function: invoke 'build'. Cake tasks are a minimal way to expose your CoffeeScript functions to the command line, so don’t expect any fanciness built-in. If you need dependencies, or async callbacks, it’s best to put them in your code itself — not the cake task.

- -

Source Maps

-

CoffeeScript 1.6.1 and above include support for generating source maps, a way to tell your JavaScript engine what part of your CoffeeScript program matches up with the code being evaluated. Browsers that support it can automatically use source maps to show your original source code in the debugger. To generate source maps alongside your JavaScript files, pass the --map or -m flag to the compiler.

+

Source Maps

CoffeeScript 1.6.1 and above include support for generating source maps, a way to tell your JavaScript engine what part of your CoffeeScript program matches up with the code being evaluated. Browsers that support it can automatically use source maps to show your original source code in the debugger. To generate source maps alongside your JavaScript files, pass the --map or -m flag to the compiler.

For a full introduction to source maps, how they work, and how to hook them up in your browser, read the HTML5 Tutorial.

- -

"text/coffeescript" Script Tags

-

While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using <script type="text/coffeescript"> tags. The source includes a compressed and minified version of the compiler (Download current version here, 51k when gzipped) as v1/browser-compiler/coffee-script.js. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order.

+

"text/coffeescript" Script Tags

While it’s not recommended for serious use, CoffeeScripts may be included directly within the browser using <script type="text/coffeescript"> tags. The source includes a compressed and minified version of the compiler (Download current version here, 51k when gzipped) as v1/browser-compiler/coffee-script.js. Include this file on a page with inline CoffeeScript tags, and it will compile and evaluate them in order.

In fact, the little bit of glue script that runs “Try CoffeeScript” above, as well as the jQuery for the menu, is implemented in just this way. View source and look at the bottom of the page to see the example. Including the script also gives you access to CoffeeScript.compile() so you can pop open Firebug and try compiling some strings.

The usual caveats about CoffeeScript apply — your inline scripts will run within a closure wrapper, so if you want to expose global variables or functions, attach them to the window object.

- -

Books

-

There are a number of excellent resources to help you get started with CoffeeScript, some of which are freely available online.

+

Books

There are a number of excellent resources to help you get started with CoffeeScript, some of which are freely available online.

- -

Screencasts

-
    +

    Screencasts

    • A Sip of CoffeeScript is a Code School Course which combines 6 screencasts with in-browser coding to make learning fun. The first level is free to try out.
    • Meet CoffeeScript is a 75-minute long screencast by PeepCode. Highly memorable for its animations which demonstrate transforming CoffeeScript into the equivalent JS.
    • If you’re looking for less of a time commitment, RailsCasts’ CoffeeScript Basics should have you covered, hitting all of the important notes about CoffeeScript in 11 minutes.
    - -

    Examples

    -

    The best list of open-source CoffeeScript examples can be found on GitHub. But just to throw out a few more:

    +

    Examples

    The best list of open-source CoffeeScript examples can be found on GitHub. But just to throw out a few more:

    • GitHub’s Hubot, a friendly IRC robot that can perform any number of useful and useless tasks.
    • sstephenson’s Pow, a zero-configuration Rack server, with comprehensive annotated source.
    • @@ -2652,9 +2585,7 @@ task('build:parser', 'rebuild t
    - -

    Resources

    -
      +

      Resources

      • Source Code
        Use bin/coffee to test your changes,
        bin/cake test to run the test suite,
        @@ -2679,15 +2610,11 @@ The CoffeeScript logo is available in SVG for use in presentations.

      - -

      Web Chat (IRC)

      -

      Quick help and advice can usually be found in the CoffeeScript IRC room. Join #coffeescript on irc.freenode.net, or click the button below to open a webchat session on this page.

      +

      Web Chat (IRC)

      Quick help and advice can usually be found in the CoffeeScript IRC room. Join #coffeescript on irc.freenode.net, or click the button below to open a webchat session on this page.

      - -

      Change Log

      -
      +

      Change Log

      1.12.1 diff --git a/documentation/v1/body.html b/documentation/v1/body.html index f9a711b6..bbe8d827 100644 --- a/documentation/v1/body.html +++ b/documentation/v1/body.html @@ -80,41 +80,76 @@

-
- <%= htmlFor('introduction', 'top') %> - <%= htmlFor('overview') %> - <%= htmlFor('installation') %> - <%= htmlFor('usage') %> - <%= htmlFor('literate') %> - <%= htmlFor('language') %> - <%= htmlFor('functions', 'literals') %> - <%= htmlFor('objects_and_arrays') %> - <%= htmlFor('lexical_scope') %> - <%= htmlFor('conditionals') %> - <%= htmlFor('splats') %> - <%= htmlFor('loops') %> - <%= htmlFor('slices') %> - <%= htmlFor('expressions') %> - <%= htmlFor('operators') %> - <%= htmlFor('existential_operator') %> - <%= htmlFor('classes') %> - <%= htmlFor('destructuring') %> - <%= htmlFor('fat_arrow') %> - <%= htmlFor('embedded') %> - <%= htmlFor('switch') %> - <%= htmlFor('try') %> - <%= htmlFor('comparisons') %> - <%= htmlFor('strings') %> - <%= htmlFor('tagged_template_literals') %> - <%= htmlFor('heregexes', 'regexes') %> - <%= htmlFor('modules') %> - <%= htmlFor('cake') %> - <%= htmlFor('source_maps') %> - <%= htmlFor('scripts') %> - <%= htmlFor('books', 'resources') %> - <%= htmlFor('screencasts') %> - <%= htmlFor('examples') %> - <%= htmlFor('resources', 'additional-resources') %> - <%= htmlFor('chat') %> - <%= htmlFor('changelog') %> +
+ + <%= htmlFor('introduction') %> + <%= htmlFor('overview') %> + + <%= htmlFor('installation') %> + + <%= htmlFor('usage') %> + + <%= htmlFor('literate') %> + + <%= htmlFor('language') %> + + <%= htmlFor('functions') %> + + <%= htmlFor('objects_and_arrays') %> + + <%= htmlFor('lexical_scope') %> + + <%= htmlFor('conditionals') %> + + <%= htmlFor('splats') %> + + <%= htmlFor('loops') %> + + <%= htmlFor('slices') %> + + <%= htmlFor('expressions') %> + + <%= htmlFor('operators') %> + + <%= htmlFor('existential_operator') %> + + <%= htmlFor('classes') %> + + <%= htmlFor('destructuring') %> + + <%= htmlFor('fat_arrow') %> + + <%= htmlFor('embedded') %> + + <%= htmlFor('switch') %> + + <%= htmlFor('try') %> + + <%= htmlFor('comparisons') %> + + <%= htmlFor('strings') %> + + <%= htmlFor('tagged_template_literals') %> + + <%= htmlFor('heregexes') %> + + <%= htmlFor('modules') %> + + <%= htmlFor('cake') %> + + <%= htmlFor('source_maps') %> + + <%= htmlFor('scripts') %> + + <%= htmlFor('books') %> + + <%= htmlFor('screencasts') %> + + <%= htmlFor('examples') %> + + <%= htmlFor('resources') %> + + <%= htmlFor('chat') %> + + <%= htmlFor('changelog') %>