minor doc updates -- let's try pulling in the underscore test suite

This commit is contained in:
Jeremy Ashkenas 2010-01-04 19:15:24 -05:00
parent 2c1033f5da
commit 3e24cef69f
7 changed files with 79 additions and 60 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
test.coffee
parser.output
test/fixtures/underscore
*.gem

View File

@ -63,6 +63,11 @@
output is quite readable — pretty-printed, with comments
preserved intact.
</p>
<p>
<b>Latest Version:</b>
<a href="http://gemcutter.org/gems/coffee-script">0.2.0</a>
</p>
<h2>Table of Contents</h2>

View File

@ -1,24 +1,24 @@
(function(){
var __a, __b, __c, __d, __e, __f, __g, food, i, lunch, row;
var __a, __b, __c, __d, __e, __f, food, i, lunch, row;
// Eat lunch.
__a = ['toast', 'cheese', 'wine'];
__c = [];
for (__b in __a) {
if (__a.hasOwnProperty(__b)) {
food = __a[__b];
__d = this.eat(food);
__c.push(__d);
lunch = (function() {
__a = ['toast', 'cheese', 'wine'];
__c = [];
for (__b in __a) {
if (__a.hasOwnProperty(__b)) {
food = __a[__b];
__d = this.eat(food);
__c.push(__d);
}
}
}
lunch = __c;
return __c;
})();
// Zebra-stripe a table.
__e = table;
__f = [];
for (i in __e) {
if (__e.hasOwnProperty(i)) {
row = __e[i];
i % 2 === 0 ? highlight(row) : null;
}
}
__f;
})();

View File

@ -22,14 +22,16 @@
}
};
// Array comprehensions:
__a = list;
__c = [];
for (__b in __a) {
if (__a.hasOwnProperty(__b)) {
num = __a[__b];
__d = math.cube(num);
__c.push(__d);
cubed_list = (function() {
__a = list;
__c = [];
for (__b in __a) {
if (__a.hasOwnProperty(__b)) {
num = __a[__b];
__d = math.cube(num);
__c.push(__d);
}
}
}
cubed_list = __c;
return __c;
})();
})();

View File

@ -4,7 +4,7 @@
change_numbers = function change_numbers() {
var new_num;
num = 2;
return (new_num = 3);
return new_num = 3;
};
new_num = change_numbers();
})();

View File

@ -6,7 +6,7 @@
return alert(this.name + " moved " + meters + "m.");
};
Snake = function Snake(name) {
return (this.name = name);
return this.name = name;
};
Snake.__superClass__ = Animal.prototype;
Snake.prototype = new Animal();
@ -16,7 +16,7 @@
return Snake.__superClass__.move.call(this, 5);
};
Horse = function Horse(name) {
return (this.name = name);
return this.name = name;
};
Horse.__superClass__ = Animal.prototype;
Horse.prototype = new Animal();

View File

@ -1,6 +1,8 @@
<!DOCTYPE html>
<html>
<head>
@ -34,6 +36,11 @@
output is quite readable &mdash; pretty-printed, with comments
preserved intact.
</p>
<p>
<b>Latest Version:</b>
<a href="http://gemcutter.org/gems/coffee-script">0.2.0</a>
</p>
<h2>Table of Contents</h2>
@ -110,16 +117,18 @@ math <span class="Keyword">=</span> {
}
};
<span class="Comment"><span class="Comment">//</span> Array comprehensions:</span>
__a <span class="Keyword">=</span> list;
__c <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (__b <span class="Keyword">in</span> __a) {
<span class="Keyword">if</span> (__a.hasOwnProperty(__b)) {
num <span class="Keyword">=</span> __a[__b];
__d <span class="Keyword">=</span> math.cube(num);
__c.<span class="LibraryFunction">push</span>(__d);
cubed_list <span class="Keyword">=</span> (<span class="Storage">function</span>() {
__a <span class="Keyword">=</span> list;
__c <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (__b <span class="Keyword">in</span> __a) {
<span class="Keyword">if</span> (__a.hasOwnProperty(__b)) {
num <span class="Keyword">=</span> __a[__b];
__d <span class="Keyword">=</span> math.cube(num);
__c.<span class="LibraryFunction">push</span>(__d);
}
}
}
cubed_list <span class="Keyword">=</span> __c;
<span class="Keyword">return</span> __c;
})();
</pre><button onclick='javascript: var __a, __b, __c, __d, cubed_list, list, math, num, number, opposite_day, square;
// Assignment:
number = 42;
@ -143,16 +152,18 @@ math = {
}
};
// Array comprehensions:
__a = list;
__c = [];
for (__b in __a) {
if (__a.hasOwnProperty(__b)) {
num = __a[__b];
__d = math.cube(num);
__c.push(__d);
cubed_list = (function() {
__a = list;
__c = [];
for (__b in __a) {
if (__a.hasOwnProperty(__b)) {
num = __a[__b];
__d = math.cube(num);
__c.push(__d);
}
}
}
cubed_list = __c;
return __c;
})();
;alert(cubed_list);'>run: cubed_list</button><br class='clear' /></div>
<h2 id="installation">Installation and Usage</h2>
@ -379,7 +390,7 @@ num <span class="Keyword">=</span> <span class="Number">1</span>;
change_numbers <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">change_numbers</span>() {
<span class="Storage">var</span> new_num;
num <span class="Keyword">=</span> <span class="Number">2</span>;
<span class="Keyword">return</span> (new_num <span class="Keyword">=</span> <span class="Number">3</span>);
<span class="Keyword">return</span> new_num <span class="Keyword">=</span> <span class="Number">3</span>;
};
new_num <span class="Keyword">=</span> change_numbers();
</pre><button onclick='javascript: var change_numbers, new_num, num;
@ -387,7 +398,7 @@ num = 1;
change_numbers = function change_numbers() {
var new_num;
num = 2;
return (new_num = 3);
return new_num = 3;
};
new_num = change_numbers();
;alert(new_num);'>run: new_num</button><br class='clear' /></div>
@ -585,28 +596,28 @@ lunch<span class="Keyword">:</span> <span class="Variable">this</span>.eat(food)
<span class="Comment"><span class="Comment">#</span> Zebra-stripe a table.</span>
highlight(row) <span class="Keyword">for</span> row, i <span class="Keyword">in</span> table <span class="Keyword">when</span> i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">is</span> <span class="Number">0</span>
</pre><pre class="idle"><span class="Storage">var</span> __a, __b, __c, __d, __e, __f, __g, food, i, lunch, row;
</pre><pre class="idle"><span class="Storage">var</span> __a, __b, __c, __d, __e, __f, food, i, lunch, row;
<span class="Comment"><span class="Comment">//</span> Eat lunch.</span>
__a <span class="Keyword">=</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>];
__c <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (__b <span class="Keyword">in</span> __a) {
<span class="Keyword">if</span> (__a.hasOwnProperty(__b)) {
food <span class="Keyword">=</span> __a[__b];
__d <span class="Keyword">=</span> <span class="Variable">this</span>.eat(food);
__c.<span class="LibraryFunction">push</span>(__d);
lunch <span class="Keyword">=</span> (<span class="Storage">function</span>() {
__a <span class="Keyword">=</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>];
__c <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (__b <span class="Keyword">in</span> __a) {
<span class="Keyword">if</span> (__a.hasOwnProperty(__b)) {
food <span class="Keyword">=</span> __a[__b];
__d <span class="Keyword">=</span> <span class="Variable">this</span>.eat(food);
__c.<span class="LibraryFunction">push</span>(__d);
}
}
}
lunch <span class="Keyword">=</span> __c;
<span class="Keyword">return</span> __c;
})();
<span class="Comment"><span class="Comment">//</span> Zebra-stripe a table.</span>
__e <span class="Keyword">=</span> table;
__f <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (i <span class="Keyword">in</span> __e) {
<span class="Keyword">if</span> (__e.hasOwnProperty(i)) {
row <span class="Keyword">=</span> __e[i];
i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">===</span> <span class="Number">0</span> ? highlight(row) : <span class="BuiltInConstant">null</span>;
}
}
__f;
</pre><br class='clear' /></div>
<p>
If you're not iterating over an actual array, you can use a range to
@ -688,7 +699,7 @@ Animal <span class="Keyword">=</span> <span class="Storage">function</span> <spa
<span class="Keyword">return</span> <span class="LibraryFunction">alert</span>(<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span> moved <span class="String">&quot;</span></span> <span class="Keyword">+</span> meters <span class="Keyword">+</span> <span class="String"><span class="String">&quot;</span>m.<span class="String">&quot;</span></span>);
};
Snake <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">Snake</span>(<span class="FunctionArgument">name</span>) {
<span class="Keyword">return</span> (<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name);
<span class="Keyword">return</span> <span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name;
};
Snake.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryConstant">prototype</span>;
<span class="LibraryClassType">Snake</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">Animal</span>();
@ -698,7 +709,7 @@ Snake.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryC
<span class="Keyword">return</span> Snake.__superClass__.move.<span class="LibraryFunction">call</span>(<span class="Variable">this</span>, <span class="Number">5</span>);
};
Horse <span class="Keyword">=</span> <span class="Storage">function</span> <span class="FunctionName">Horse</span>(<span class="FunctionArgument">name</span>) {
<span class="Keyword">return</span> (<span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name);
<span class="Keyword">return</span> <span class="Variable">this</span>.<span class="LibraryConstant">name</span> <span class="Keyword">=</span> name;
};
Horse.__superClass__ <span class="Keyword">=</span> Animal.<span class="LibraryConstant">prototype</span>;
<span class="LibraryClassType">Horse</span>.<span class="LibraryConstant">prototype</span> = <span class="Keyword">new</span> <span class="TypeName">Animal</span>();
@ -718,7 +729,7 @@ Animal.prototype.move = function move(meters) {
return alert(this.name + " moved " + meters + "m.");
};
Snake = function Snake(name) {
return (this.name = name);
return this.name = name;
};
Snake.__superClass__ = Animal.prototype;
Snake.prototype = new Animal();
@ -728,7 +739,7 @@ Snake.prototype.move = function move() {
return Snake.__superClass__.move.call(this, 5);
};
Horse = function Horse(name) {
return (this.name = name);
return this.name = name;
};
Horse.__superClass__ = Animal.prototype;
Horse.prototype = new Animal();