coffee-script 1.0.0 → 1.1.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/lib/coffee_script.rb +55 -22
- metadata +4 -4
data/lib/coffee_script.rb
CHANGED
@@ -1,31 +1,64 @@
|
|
1
1
|
module CoffeeScript
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
class << self
|
3
|
+
def locate_coffee_bin
|
4
|
+
out = `which coffee`
|
5
|
+
if $?.success?
|
6
|
+
out.chomp
|
7
|
+
else
|
8
|
+
raise LoadError, "could not find `coffee` in PATH"
|
9
|
+
end
|
8
10
|
end
|
9
|
-
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def coffee_bin
|
13
|
+
@@coffee_bin ||= locate_coffee_bin
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def coffee_bin=(path)
|
17
|
+
@@coffee_bin = path
|
18
|
+
end
|
19
|
+
|
20
|
+
def version
|
21
|
+
`#{coffee_bin} --version`[/(\d|\.)+/]
|
22
|
+
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
command = "#{coffee_bin} -sp"
|
23
|
-
command += " --no-wrap" if options[:no_wrap]
|
24
|
+
# Compile a script (String or IO) to JavaScript.
|
25
|
+
def compile(script, options = {})
|
26
|
+
args = "-sp"
|
24
27
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
if options[:wrap] == false ||
|
29
|
+
options.key?(:bare) ||
|
30
|
+
options.key?(:no_wrap)
|
31
|
+
args += " --#{no_wrap_flag}"
|
32
|
+
end
|
33
|
+
|
34
|
+
execute_coffee(script, args)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Evaluate a script (String or IO) and return the stdout.
|
38
|
+
# Note: the first argument will be process.argv[3], the second
|
39
|
+
# process.argv[4], etc.
|
40
|
+
def evaluate(script, *args)
|
41
|
+
execute_coffee(script, "-s #{args.join(' ')}")
|
29
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def execute_coffee(script, args)
|
46
|
+
command = "#{coffee_bin} #{args}"
|
47
|
+
script = script.read if script.respond_to?(:read)
|
48
|
+
|
49
|
+
IO.popen(command, "w+") do |f|
|
50
|
+
f << script
|
51
|
+
f.close_write
|
52
|
+
f.read
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def no_wrap_flag
|
57
|
+
if `#{coffee_bin} --help`.lines.grep(/--no-wrap/).any?
|
58
|
+
'no-wrap'
|
59
|
+
else
|
60
|
+
'bare'
|
61
|
+
end
|
62
|
+
end
|
30
63
|
end
|
31
64
|
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeremy Ashkenas
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-10-29 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|