coffee-script 0.3.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +2 -2
- data/README.md +15 -0
- data/lib/coffee-script.rb +1 -21
- data/lib/coffee_script.rb +31 -0
- metadata +30 -46
- data/README +0 -41
- data/bin/coffee +0 -5
- data/coffee-script.gemspec +0 -27
- data/examples/blocks.coffee +0 -57
- data/examples/code.coffee +0 -173
- data/examples/poignant.coffee +0 -186
- data/examples/potion.coffee +0 -205
- data/examples/underscore.coffee +0 -603
- data/extras/CoffeeScript.tmbundle/Preferences/CoffeeScript.tmPreferences +0 -24
- data/extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage +0 -361
- data/extras/CoffeeScript.tmbundle/info.plist +0 -10
- data/extras/EXTRAS +0 -20
- data/extras/coffee.vim +0 -111
- data/lib/coffee_script/coffee-script.js +0 -50
- data/lib/coffee_script/command_line.rb +0 -235
- data/lib/coffee_script/grammar.y +0 -481
- data/lib/coffee_script/lexer.js +0 -363
- data/lib/coffee_script/lexer.rb +0 -272
- data/lib/coffee_script/narwhal/coffee-script.js +0 -96
- data/lib/coffee_script/nodes.js +0 -443
- data/lib/coffee_script/nodes.rb +0 -1050
- data/lib/coffee_script/parse_error.rb +0 -29
- data/lib/coffee_script/parser.js +0 -477
- data/lib/coffee_script/parser.rb +0 -2611
- data/lib/coffee_script/repl.js +0 -33
- data/lib/coffee_script/rewriter.js +0 -377
- data/lib/coffee_script/rewriter.rb +0 -289
- data/lib/coffee_script/runner.js +0 -11
- data/lib/coffee_script/scope.js +0 -73
- data/lib/coffee_script/scope.rb +0 -91
- data/lib/coffee_script/value.rb +0 -64
- data/package.json +0 -8
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010
|
1
|
+
Copyright (c) 2010 Joshua Peek
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person
|
4
4
|
obtaining a copy of this software and associated documentation
|
@@ -19,4 +19,4 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
19
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
20
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
21
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Ruby CoffeeScript
|
2
|
+
=================
|
3
|
+
|
4
|
+
Ruby CoffeeScript is a thin wrapper around the `coffee` binary.
|
5
|
+
|
6
|
+
CoffeeScript.compile File.open("script.coffee")
|
7
|
+
|
8
|
+
Dependencies
|
9
|
+
------------
|
10
|
+
|
11
|
+
This is **not** the CoffeeScript parser. This means you need to install `node` and `coffee`.
|
12
|
+
|
13
|
+
If your `coffee` binary is in a weird location, you can specify the path by hand.
|
14
|
+
|
15
|
+
CoffeeScript.coffee_bin = "/usr/local/bin/coffee"
|
data/lib/coffee-script.rb
CHANGED
@@ -1,21 +1 @@
|
|
1
|
-
|
2
|
-
require "coffee_script/lexer"
|
3
|
-
require "coffee_script/parser"
|
4
|
-
require "coffee_script/nodes"
|
5
|
-
require "coffee_script/value"
|
6
|
-
require "coffee_script/scope"
|
7
|
-
require "coffee_script/rewriter"
|
8
|
-
require "coffee_script/parse_error"
|
9
|
-
|
10
|
-
# Namespace for all CoffeeScript internal classes.
|
11
|
-
module CoffeeScript
|
12
|
-
|
13
|
-
VERSION = '0.3.2' # Keep in sync with the gemspec.
|
14
|
-
|
15
|
-
# Compile a script (String or IO) to JavaScript.
|
16
|
-
def self.compile(script, options={})
|
17
|
-
script = script.read if script.respond_to?(:read)
|
18
|
-
Parser.new.parse(script).compile(options)
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
1
|
+
require 'coffee_script'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module CoffeeScript
|
2
|
+
def self.locate_coffee_bin
|
3
|
+
out = `which coffee`
|
4
|
+
if $?.success?
|
5
|
+
out.chomp
|
6
|
+
else
|
7
|
+
raise LoadError, "could not find `coffee` in PATH"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.coffee_bin
|
12
|
+
@@coffee_bin ||= locate_coffee_bin
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.coffee_bin=(path)
|
16
|
+
@@coffee_bin = path
|
17
|
+
end
|
18
|
+
|
19
|
+
# Compile a script (String or IO) to JavaScript.
|
20
|
+
def self.compile(script, options = {})
|
21
|
+
script = script.read if script.respond_to?(:read)
|
22
|
+
command = "#{coffee_bin} -sp"
|
23
|
+
command += " --no-wrap" if options[:no_wrap]
|
24
|
+
|
25
|
+
IO.popen(command, "w+") do |f|
|
26
|
+
f << script
|
27
|
+
f.close_write
|
28
|
+
f.read
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,63 +1,40 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee-script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Jeremy Ashkenas
|
14
|
+
- Joshua Peek
|
8
15
|
autorequire:
|
9
16
|
bindir: bin
|
10
17
|
cert_chain: []
|
11
18
|
|
12
|
-
date: 2010-
|
19
|
+
date: 2010-09-10 00:00:00 -05:00
|
13
20
|
default_executable:
|
14
21
|
dependencies: []
|
15
22
|
|
16
|
-
description: " CoffeeScript is a
|
17
|
-
email:
|
18
|
-
executables:
|
19
|
-
|
23
|
+
description: " Ruby CoffeeScript is a thin wrapper around the coffee binary.\n"
|
24
|
+
email: josh@joshpeek.com
|
25
|
+
executables: []
|
26
|
+
|
20
27
|
extensions: []
|
21
28
|
|
22
29
|
extra_rdoc_files: []
|
23
30
|
|
24
31
|
files:
|
25
|
-
- bin/coffee
|
26
|
-
- examples/blocks.coffee
|
27
|
-
- examples/code.coffee
|
28
|
-
- examples/poignant.coffee
|
29
|
-
- examples/potion.coffee
|
30
|
-
- examples/underscore.coffee
|
31
|
-
- extras/coffee.vim
|
32
|
-
- extras/CoffeeScript.tmbundle/info.plist
|
33
|
-
- extras/CoffeeScript.tmbundle/Preferences/CoffeeScript.tmPreferences
|
34
|
-
- extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage
|
35
|
-
- extras/EXTRAS
|
36
32
|
- lib/coffee-script.rb
|
37
|
-
- lib/coffee_script
|
38
|
-
- lib/coffee_script/command_line.rb
|
39
|
-
- lib/coffee_script/grammar.y
|
40
|
-
- lib/coffee_script/lexer.js
|
41
|
-
- lib/coffee_script/lexer.rb
|
42
|
-
- lib/coffee_script/narwhal/coffee-script.js
|
43
|
-
- lib/coffee_script/nodes.js
|
44
|
-
- lib/coffee_script/nodes.rb
|
45
|
-
- lib/coffee_script/parse_error.rb
|
46
|
-
- lib/coffee_script/parser.js
|
47
|
-
- lib/coffee_script/parser.rb
|
48
|
-
- lib/coffee_script/repl.js
|
49
|
-
- lib/coffee_script/rewriter.js
|
50
|
-
- lib/coffee_script/rewriter.rb
|
51
|
-
- lib/coffee_script/runner.js
|
52
|
-
- lib/coffee_script/scope.js
|
53
|
-
- lib/coffee_script/scope.rb
|
54
|
-
- lib/coffee_script/value.rb
|
55
|
-
- coffee-script.gemspec
|
33
|
+
- lib/coffee_script.rb
|
56
34
|
- LICENSE
|
57
|
-
- README
|
58
|
-
|
59
|
-
|
60
|
-
homepage: http://jashkenas.github.com/coffee-script/
|
35
|
+
- README.md
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/josh/ruby-coffee-script
|
61
38
|
licenses: []
|
62
39
|
|
63
40
|
post_install_message:
|
@@ -66,23 +43,30 @@ rdoc_options: []
|
|
66
43
|
require_paths:
|
67
44
|
- lib
|
68
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
69
47
|
requirements:
|
70
48
|
- - ">="
|
71
49
|
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
72
53
|
version: "0"
|
73
|
-
version:
|
74
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
75
56
|
requirements:
|
76
57
|
- - ">="
|
77
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
78
62
|
version: "0"
|
79
|
-
|
80
|
-
|
81
|
-
|
63
|
+
requirements:
|
64
|
+
- node
|
65
|
+
- coffee-script
|
82
66
|
rubyforge_project: coffee-script
|
83
|
-
rubygems_version: 1.3.
|
67
|
+
rubygems_version: 1.3.7
|
84
68
|
signing_key:
|
85
69
|
specification_version: 3
|
86
|
-
summary:
|
70
|
+
summary: Ruby CoffeeScript wrapper
|
87
71
|
test_files: []
|
88
72
|
|
data/README
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
=
|
2
|
-
{
|
3
|
-
} } {
|
4
|
-
{ { } }
|
5
|
-
} }{ {
|
6
|
-
{ }{ } } _____ __ __
|
7
|
-
( }{ }{ { ) / ____| / _|/ _|
|
8
|
-
.- { { } { }} -. | | ___ | |_| |_ ___ ___
|
9
|
-
( ( } { } { } } ) | | / _ \| _| _/ _ \/ _ \
|
10
|
-
|`-..________ ..-'| | |___| (_) | | | || __/ __/
|
11
|
-
| | \_____\___/|_| |_| \___|\___|
|
12
|
-
| ;--.
|
13
|
-
| (__ \ _____ _ _
|
14
|
-
| | ) ) / ____| (_) | |
|
15
|
-
| |/ / | (___ ___ _ __ _ _ __ | |_
|
16
|
-
| ( / \___ \ / __| '__| | '_ \| __|
|
17
|
-
| |/ ____) | (__| | | | |_) | |_
|
18
|
-
| | |_____/ \___|_| |_| .__/ \__|
|
19
|
-
`-.._________..-' | |
|
20
|
-
|_|
|
21
|
-
|
22
|
-
|
23
|
-
CoffeeScript is a little language that compiles into JavaScript.
|
24
|
-
|
25
|
-
Install the compiler:
|
26
|
-
gem install coffee-script
|
27
|
-
|
28
|
-
Compile a script:
|
29
|
-
coffee /path/to/script.coffee
|
30
|
-
|
31
|
-
For documentation, usage, and examples, see:
|
32
|
-
http://jashkenas.github.com/coffee-script/
|
33
|
-
|
34
|
-
To suggest a feature or report a bug:
|
35
|
-
http://github.com/jashkenas/coffee-script/issues/
|
36
|
-
|
37
|
-
The source repository:
|
38
|
-
git://github.com/jashkenas/coffee-script.git
|
39
|
-
|
40
|
-
To build CoffeeScript from source, install the "racc" gem and
|
41
|
-
run "rake build:parser". Then bin/coffee will work.
|
data/bin/coffee
DELETED
data/coffee-script.gemspec
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = 'coffee-script'
|
3
|
-
s.version = '0.3.2' # Keep version in sync with coffee-script.rb
|
4
|
-
s.date = '2010-2-8'
|
5
|
-
|
6
|
-
s.homepage = "http://jashkenas.github.com/coffee-script/"
|
7
|
-
s.summary = "The CoffeeScript Compiler"
|
8
|
-
s.description = <<-EOS
|
9
|
-
CoffeeScript is a little language that compiles into JavaScript. Think
|
10
|
-
of it as JavaScript's less ostentatious kid brother -- the same genes,
|
11
|
-
roughly the same height, but a different sense of style. Apart from a
|
12
|
-
handful of bonus goodies, statements in CoffeeScript correspond
|
13
|
-
one-to-one with their equivalent in JavaScript, it's just another
|
14
|
-
way of saying it.
|
15
|
-
EOS
|
16
|
-
|
17
|
-
s.authors = ['Jeremy Ashkenas']
|
18
|
-
s.email = 'jashkenas@gmail.com'
|
19
|
-
s.rubyforge_project = 'coffee-script'
|
20
|
-
s.has_rdoc = false
|
21
|
-
|
22
|
-
s.require_paths = ['lib']
|
23
|
-
s.executables = ['coffee']
|
24
|
-
|
25
|
-
s.files = Dir['bin/*', 'examples/*', 'extras/**/*', 'lib/**/*',
|
26
|
-
'coffee-script.gemspec', 'LICENSE', 'README', 'package.json']
|
27
|
-
end
|
data/examples/blocks.coffee
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# After wycats' http://yehudakatz.com/2010/02/07/the-building-blocks-of-ruby/
|
2
|
-
|
3
|
-
# Sinatra.
|
4
|
-
get '/hello', ->
|
5
|
-
'Hello World'
|
6
|
-
|
7
|
-
|
8
|
-
# Append.
|
9
|
-
append: (location, data) ->
|
10
|
-
path: new Pathname location
|
11
|
-
throw "Location does not exist" unless path.exists()
|
12
|
-
|
13
|
-
File.open path, 'a', (file) ->
|
14
|
-
file.puts YAML.dump data
|
15
|
-
|
16
|
-
data
|
17
|
-
|
18
|
-
|
19
|
-
# Rubinius' File.open implementation.
|
20
|
-
File.open: (path, mode, block) ->
|
21
|
-
io: new File path, mode
|
22
|
-
|
23
|
-
return io unless block
|
24
|
-
|
25
|
-
try
|
26
|
-
block io
|
27
|
-
finally
|
28
|
-
try
|
29
|
-
io.close() unless io.closed()
|
30
|
-
catch error
|
31
|
-
# nothing, just swallow them.
|
32
|
-
|
33
|
-
|
34
|
-
# Write.
|
35
|
-
write: (location, data) ->
|
36
|
-
path = new Pathname location
|
37
|
-
raise "Location does not exist" unless path.exists()
|
38
|
-
|
39
|
-
File.open path, 'w', (file) ->
|
40
|
-
return false if Digest.MD5.hexdigest(file.read()) is data.hash()
|
41
|
-
file.puts YAML.dump data
|
42
|
-
true
|
43
|
-
|
44
|
-
|
45
|
-
# Rails' respond_to.
|
46
|
-
index: ->
|
47
|
-
people: Person.find 'all'
|
48
|
-
|
49
|
-
respond_to (format) ->
|
50
|
-
format.html()
|
51
|
-
format.xml -> render { xml: people.xml() }
|
52
|
-
|
53
|
-
|
54
|
-
# Synchronization.
|
55
|
-
synchronize: (block) ->
|
56
|
-
lock()
|
57
|
-
try block() finally unlock()
|
data/examples/code.coffee
DELETED
@@ -1,173 +0,0 @@
|
|
1
|
-
# Functions:
|
2
|
-
square: (x) -> x * x
|
3
|
-
|
4
|
-
sum: (x, y) -> x + y
|
5
|
-
|
6
|
-
odd: (x) -> x % 2 isnt 0
|
7
|
-
|
8
|
-
even: (x) -> x % 2 is 0
|
9
|
-
|
10
|
-
run_loop: ->
|
11
|
-
fire_events((e) -> e.stopPropagation())
|
12
|
-
listen()
|
13
|
-
wait()
|
14
|
-
|
15
|
-
# Objects:
|
16
|
-
dense_object_literal: {one: 1, two: 2, three: 3}
|
17
|
-
|
18
|
-
spaced_out_multiline_object: {
|
19
|
-
pi: 3.14159
|
20
|
-
list: [1, 2, 3, 4]
|
21
|
-
regex: /match[ing](every|thing|\/)/gi
|
22
|
-
three: new Idea()
|
23
|
-
|
24
|
-
inner_obj: {
|
25
|
-
freedom: -> _.freedom()
|
26
|
-
}
|
27
|
-
}
|
28
|
-
|
29
|
-
# Arrays:
|
30
|
-
stooges: [{moe: 45}, {curly: 43}, {larry: 46}]
|
31
|
-
|
32
|
-
exponents: [(x) -> x, (x) -> x * x, (x) -> x * x * x]
|
33
|
-
|
34
|
-
empty: []
|
35
|
-
|
36
|
-
multiline: [
|
37
|
-
'line one'
|
38
|
-
'line two'
|
39
|
-
]
|
40
|
-
|
41
|
-
# Conditionals and ternaries.
|
42
|
-
if submarine.shields_up
|
43
|
-
full_speed_ahead()
|
44
|
-
fire_torpedos()
|
45
|
-
else if submarine.sinking
|
46
|
-
abandon_ship()
|
47
|
-
else
|
48
|
-
run_away()
|
49
|
-
|
50
|
-
eldest: if 25 > 21 then liz else marge
|
51
|
-
|
52
|
-
decoration: medal_of_honor if war_hero
|
53
|
-
|
54
|
-
go_to_sleep() unless coffee
|
55
|
-
|
56
|
-
# Returning early:
|
57
|
-
race: ->
|
58
|
-
run()
|
59
|
-
walk()
|
60
|
-
crawl()
|
61
|
-
if tired then return sleep()
|
62
|
-
race()
|
63
|
-
|
64
|
-
# Conditional assignment:
|
65
|
-
good ||= evil
|
66
|
-
wine &&= cheese
|
67
|
-
|
68
|
-
# Nested property access and calls.
|
69
|
-
((moon.turn(360))).shapes[3].move({x: 45, y: 30}).position['top'].offset('x')
|
70
|
-
|
71
|
-
a: b: c: 5
|
72
|
-
|
73
|
-
# Embedded JavaScript.
|
74
|
-
callback(
|
75
|
-
`function(e) { e.stop(); }`
|
76
|
-
)
|
77
|
-
|
78
|
-
# Try/Catch/Finally/Throw.
|
79
|
-
try
|
80
|
-
all_hell_breaks_loose()
|
81
|
-
dogs_and_cats_living_together()
|
82
|
-
throw "up"
|
83
|
-
catch error
|
84
|
-
print(error)
|
85
|
-
finally
|
86
|
-
clean_up()
|
87
|
-
|
88
|
-
try all_hell_breaks_loose() catch error then print(error) finally clean_up()
|
89
|
-
|
90
|
-
# While loops, break and continue.
|
91
|
-
while demand > supply
|
92
|
-
sell()
|
93
|
-
restock()
|
94
|
-
|
95
|
-
while supply > demand then buy()
|
96
|
-
|
97
|
-
while true
|
98
|
-
break if broken
|
99
|
-
continue if continuing
|
100
|
-
|
101
|
-
# Unary operators.
|
102
|
-
!!true
|
103
|
-
|
104
|
-
# Lexical scoping.
|
105
|
-
v_1: 5
|
106
|
-
change_a_and_set_b: ->
|
107
|
-
v_1: 10
|
108
|
-
v_2: 15
|
109
|
-
v_2: 20
|
110
|
-
|
111
|
-
# Array comprehensions.
|
112
|
-
supper: food.capitalize() for food in ['toast', 'cheese', 'wine']
|
113
|
-
|
114
|
-
drink(bottle) for bottle, i in ['soda', 'wine', 'lemonade'] when even(i)
|
115
|
-
|
116
|
-
# Switch statements ("else" serves as a default).
|
117
|
-
activity: switch day
|
118
|
-
when "Tuesday" then eat_breakfast()
|
119
|
-
when "Sunday" then go_to_church()
|
120
|
-
when "Saturday" then go_to_the_park()
|
121
|
-
when "Wednesday"
|
122
|
-
if day is bingo_day
|
123
|
-
go_to_bingo()
|
124
|
-
else
|
125
|
-
eat_breakfast()
|
126
|
-
go_to_work()
|
127
|
-
eat_dinner()
|
128
|
-
else go_to_work()
|
129
|
-
|
130
|
-
# Semicolons can optionally be used instead of newlines.
|
131
|
-
wednesday: -> eat_breakfast(); go_to_work(); eat_dinner()
|
132
|
-
|
133
|
-
# Array slice literals.
|
134
|
-
zero_to_nine: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
135
|
-
three_to_six: zero_to_nine[3..6]
|
136
|
-
|
137
|
-
# Multiline strings with inner quotes.
|
138
|
-
story: "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
|
139
|
-
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
|
140
|
-
aliquam erat volutpat. Ut wisi enim ad."
|
141
|
-
|
142
|
-
# Inheritance and calling super.
|
143
|
-
Animal: ->
|
144
|
-
Animal::move: (meters) ->
|
145
|
-
alert(this.name + " moved " + meters + "m.")
|
146
|
-
|
147
|
-
Snake: (name) -> this.name: name
|
148
|
-
Snake extends Animal
|
149
|
-
Snake::move: ->
|
150
|
-
alert('Slithering...')
|
151
|
-
super(5)
|
152
|
-
|
153
|
-
Horse: (name) -> this.name: name
|
154
|
-
Horse extends Animal
|
155
|
-
Horse::move: ->
|
156
|
-
alert('Galloping...')
|
157
|
-
super(45)
|
158
|
-
|
159
|
-
sam: new Snake("Sammy the Snake")
|
160
|
-
tom: new Horse("Tommy the Horse")
|
161
|
-
|
162
|
-
sam.move()
|
163
|
-
tom.move()
|
164
|
-
|
165
|
-
# Numbers.
|
166
|
-
a_googol: 1e100
|
167
|
-
hex: 0xff0000
|
168
|
-
negative: -1.0
|
169
|
-
infinity: Infinity
|
170
|
-
nan: NaN
|
171
|
-
|
172
|
-
# Deleting.
|
173
|
-
delete secret.identity
|