coffee-script 2.1.3 → 2.2.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/README.md +4 -18
- data/lib/coffee_script.rb +7 -125
- metadata +9 -9
data/README.md
CHANGED
@@ -31,27 +31,13 @@ variable:
|
|
31
31
|
|
32
32
|
export COFFEESCRIPT_SOURCE_PATH=/path/to/coffee-script/extras/coffee-script.js
|
33
33
|
|
34
|
+
### JSON
|
35
|
+
|
34
36
|
The `json` library is also required but is not explicitly stated as a
|
35
37
|
gem dependency. If you're on Ruby 1.8 you'll need to install the
|
36
38
|
`json` or `json_pure` gem. On Ruby 1.9, `json` is included in the
|
37
39
|
standard library.
|
38
40
|
|
41
|
+
### ExecJS
|
39
42
|
|
40
|
-
|
41
|
-
-------
|
42
|
-
|
43
|
-
The `coffee-script` library will automatically choose the best
|
44
|
-
JavaScript engine for your platform. The currently implemented engines
|
45
|
-
are:
|
46
|
-
|
47
|
-
* **Node.js**. If the `node` binary is available in `$PATH`, it will
|
48
|
-
be used to invoke the CoffeeScript compiler.
|
49
|
-
|
50
|
-
* **JavaScript Core**. If you're on OS X and don't have Node.js
|
51
|
-
installed, the library will fall back to the built-in JavaScript
|
52
|
-
Core binary, `jsc`. This way you don't need to install any
|
53
|
-
additional dependencies.
|
54
|
-
|
55
|
-
* **V8**. Shelling out to Node.js may be too slow for your production
|
56
|
-
environment. In this case, install `therubyracer` gem, which
|
57
|
-
provides a fast bridge between Ruby and V8.
|
43
|
+
The [ExecJS](https://github.com/sstephenson/execjs) library is used to automatically choose the best JavaScript engine for your platform. Check out its [README](https://github.com/sstephenson/execjs/blob/master/README.md) for a complete list of supported engines.
|
data/lib/coffee_script.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
require '
|
2
|
-
require 'tempfile'
|
3
|
-
|
1
|
+
require 'execjs'
|
4
2
|
require 'coffee_script/source'
|
5
3
|
|
6
4
|
module CoffeeScript
|
7
|
-
|
8
|
-
|
9
|
-
class CompilationError < Error; end
|
5
|
+
EngineError = ExecJS::RuntimeError
|
6
|
+
CompilationError = ExecJS::ProgramError
|
10
7
|
|
11
8
|
module Source
|
12
9
|
def self.path
|
@@ -14,7 +11,7 @@ module CoffeeScript
|
|
14
11
|
end
|
15
12
|
|
16
13
|
def self.path=(path)
|
17
|
-
@contents = @version = @bare_option = nil
|
14
|
+
@contents = @version = @bare_option = @context = nil
|
18
15
|
@path = path
|
19
16
|
end
|
20
17
|
|
@@ -29,126 +26,17 @@ module CoffeeScript
|
|
29
26
|
def self.bare_option
|
30
27
|
@bare_option ||= contents.match(/noWrap/) ? 'noWrap' : 'bare'
|
31
28
|
end
|
32
|
-
end
|
33
|
-
|
34
|
-
module ExternalEngine
|
35
|
-
class << self
|
36
|
-
def compile(command, script, options)
|
37
|
-
yield f = Tempfile.open("coffee.js")
|
38
|
-
f.puts compile_js(script, options)
|
39
|
-
f.close
|
40
|
-
|
41
|
-
execute("#{command} #{f.path}")
|
42
|
-
ensure
|
43
|
-
f.close! if f
|
44
|
-
end
|
45
|
-
|
46
|
-
def execute(command)
|
47
|
-
out = `#{command}`.chomp
|
48
|
-
if $?.success?
|
49
|
-
status, result = out[0, 1], out[1..-1]
|
50
|
-
if status == "+"
|
51
|
-
result
|
52
|
-
else
|
53
|
-
raise CompilationError, result[/^(?:Error: )?(.*)/, 1]
|
54
|
-
end
|
55
|
-
else
|
56
|
-
raise EngineError, out
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def compile_js(script, options)
|
61
|
-
options = options[:bare] ? "{#{Source.bare_option} : true}" : "{}"
|
62
|
-
<<-JS
|
63
|
-
try {
|
64
|
-
print('+' + CoffeeScript.compile(#{script.to_json}, #{options}));
|
65
|
-
} catch (e) {
|
66
|
-
print('-' + e);
|
67
|
-
}
|
68
|
-
JS
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
module Engines
|
74
|
-
module JavaScriptCore
|
75
|
-
BIN = "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc"
|
76
|
-
|
77
|
-
class << self
|
78
|
-
def supported?
|
79
|
-
File.exist?(BIN)
|
80
|
-
end
|
81
|
-
|
82
|
-
def compile(script, options = {})
|
83
|
-
ExternalEngine.compile(BIN, script, options) do |f|
|
84
|
-
f.puts "load(#{Source.path.to_json});"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
module Node
|
91
|
-
class << self
|
92
|
-
|
93
|
-
def binary
|
94
|
-
@binary ||= `sh -c "which nodejs node"`.split("\n").first
|
95
|
-
end
|
96
|
-
|
97
|
-
def binary=(value)
|
98
|
-
@binary = value.nil? ? nil : value.to_s
|
99
|
-
end
|
100
|
-
|
101
|
-
def supported?
|
102
|
-
binary
|
103
|
-
end
|
104
|
-
|
105
|
-
def compile(script, options = {})
|
106
|
-
ExternalEngine.compile(binary, script, options) do |f|
|
107
|
-
f.puts Source.contents
|
108
|
-
f.puts "var CoffeeScript = this.CoffeeScript, print = console.log;"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
module V8
|
115
|
-
class << self
|
116
|
-
def supported?
|
117
|
-
require 'v8'
|
118
|
-
true
|
119
|
-
rescue LoadError
|
120
|
-
false
|
121
|
-
end
|
122
|
-
|
123
|
-
def compile(script, options = {})
|
124
|
-
coffee_module['compile'].call(script, Source.bare_option => options[:bare])
|
125
|
-
rescue ::V8::JSError => e
|
126
|
-
raise CompilationError, e.message
|
127
|
-
end
|
128
29
|
|
129
|
-
|
130
|
-
|
131
|
-
@coffee_module ||= build_coffee_module
|
132
|
-
end
|
133
|
-
|
134
|
-
def build_coffee_module
|
135
|
-
context = ::V8::Context.new
|
136
|
-
context.eval(Source.contents)
|
137
|
-
context['CoffeeScript']
|
138
|
-
rescue ::V8::JSError => e
|
139
|
-
raise EngineError, e.message
|
140
|
-
end
|
141
|
-
end
|
30
|
+
def self.context
|
31
|
+
@context ||= ExecJS.compile(contents)
|
142
32
|
end
|
143
33
|
end
|
144
34
|
|
145
35
|
class << self
|
146
36
|
def engine
|
147
|
-
@engine ||= nil
|
148
37
|
end
|
149
38
|
|
150
39
|
def engine=(engine)
|
151
|
-
@engine = engine
|
152
40
|
end
|
153
41
|
|
154
42
|
def version
|
@@ -166,13 +54,7 @@ module CoffeeScript
|
|
166
54
|
options[:bare] = false
|
167
55
|
end
|
168
56
|
|
169
|
-
|
57
|
+
Source.context.call("CoffeeScript.compile", script, options)
|
170
58
|
end
|
171
59
|
end
|
172
|
-
|
173
|
-
self.engine ||= [
|
174
|
-
Engines::V8,
|
175
|
-
Engines::Node,
|
176
|
-
Engines::JavaScriptCore
|
177
|
-
].detect(&:supported?)
|
178
60
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coffee-script
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 2.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 2.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeremy Ashkenas
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-
|
20
|
+
date: 2010-03-11 00:00:00 -06:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: execjs
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
segments:
|
47
47
|
- 0
|
48
48
|
version: "0"
|
49
|
-
type: :
|
49
|
+
type: :runtime
|
50
50
|
version_requirements: *id002
|
51
51
|
description: " Ruby CoffeeScript is a bridge to the JS CoffeeScript compiler.\n"
|
52
52
|
email: josh@joshpeek.com
|
@@ -90,8 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: "0"
|
91
91
|
requirements: []
|
92
92
|
|
93
|
-
rubyforge_project:
|
94
|
-
rubygems_version: 1.
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.5.3
|
95
95
|
signing_key:
|
96
96
|
specification_version: 3
|
97
97
|
summary: Ruby CoffeeScript Compiler
|