closure-compiler 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +1 -1
- data/closure-compiler.gemspec +2 -2
- data/lib/closure-compiler.rb +1 -1
- data/lib/closure/compiler.rb +11 -6
- data/lib/closure/popen.rb +45 -26
- metadata +3 -3
data/README.textile
CHANGED
@@ -2,7 +2,7 @@ h1. The Closure Compiler (as a Ruby Gem)
|
|
2
2
|
|
3
3
|
The *closure-compiler* gem is a svelte wrapper around the "Google Closure Compiler":http://code.google.com/closure/compiler/ for JavaScript compression.
|
4
4
|
|
5
|
-
Latest Version: *"0.3.
|
5
|
+
Latest Version: *"0.3.1":http://gemcutter.org/gems/closure-compiler*
|
6
6
|
|
7
7
|
The Closure Compiler's *2010-05-15* JAR-file is included with the gem, so you'll need *Java 6* installed in order to run the compiler.
|
8
8
|
|
data/closure-compiler.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'closure-compiler'
|
3
|
-
s.version = '0.3.
|
4
|
-
s.date = '2010-6-
|
3
|
+
s.version = '0.3.1' # Keep version in sync with closure-compiler.rb
|
4
|
+
s.date = '2010-6-11'
|
5
5
|
|
6
6
|
s.homepage = "http://github.com/documentcloud/closure-compiler/"
|
7
7
|
s.summary = "Ruby Wrapper for the Google Closure Compiler"
|
data/lib/closure-compiler.rb
CHANGED
data/lib/closure/compiler.rb
CHANGED
@@ -19,7 +19,7 @@ module Closure
|
|
19
19
|
# block, for streaming.
|
20
20
|
def compile(io)
|
21
21
|
result, error = nil, nil
|
22
|
-
|
22
|
+
Closure::Popen.popen(command) do |stdin, stdout, stderr|
|
23
23
|
if io.respond_to? :read
|
24
24
|
while buffer = io.read(4096) do
|
25
25
|
stdin.write(buffer)
|
@@ -28,12 +28,17 @@ module Closure
|
|
28
28
|
stdin.write(io.to_s)
|
29
29
|
end
|
30
30
|
stdin.close
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
if Closure::Popen::WINDOWS
|
32
|
+
stderr.close
|
33
|
+
result = stdout.read
|
34
|
+
error = "Stderr cannot be read on Windows."
|
35
|
+
else
|
36
|
+
out_thread = Thread.new { result = stdout.read }
|
37
|
+
err_thread = Thread.new { error = stderr.read }
|
38
|
+
out_thread.join and err_thread.join
|
39
|
+
end
|
34
40
|
yield(StringIO.new(result)) if block_given?
|
35
41
|
end
|
36
|
-
Process.waitpid pid
|
37
42
|
raise Error, error unless $?.success?
|
38
43
|
result
|
39
44
|
end
|
@@ -48,7 +53,7 @@ module Closure
|
|
48
53
|
end
|
49
54
|
|
50
55
|
def command
|
51
|
-
[@java, '-jar', @jar, @options].flatten.join(' ')
|
56
|
+
[@java, '-jar', "\"#{@jar}\"", @options].flatten.join(' ')
|
52
57
|
end
|
53
58
|
|
54
59
|
end
|
data/lib/closure/popen.rb
CHANGED
@@ -4,37 +4,56 @@ module Closure
|
|
4
4
|
# grandchild process, and returns the pid of the external process.
|
5
5
|
module Popen
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
WINDOWS = RUBY_PLATFORM.match(/mswin32/)
|
8
|
+
if WINDOWS
|
9
|
+
require 'rubygems'
|
10
|
+
require 'win32/open3'
|
11
|
+
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def self.popen(cmd)
|
14
|
+
pid = nil
|
15
|
+
if WINDOWS
|
16
|
+
error, pid = nil, nil
|
17
|
+
Open4.popen4(cmd) do |stdin, stdout, stderr, win_pid|
|
18
|
+
yield(stdin, stdout, stderr) if block_given?
|
19
|
+
stdout.read unless stdout.closed? or stdout.eof?
|
20
|
+
unless stderr.closed?
|
21
|
+
stderr.rewind
|
22
|
+
error = stderr.read
|
23
|
+
end
|
24
|
+
pid = win_pid
|
25
|
+
end
|
26
|
+
else
|
27
|
+
# pipe[0] for read, pipe[1] for write
|
28
|
+
pw, pr, pe = IO.pipe, IO.pipe, IO.pipe
|
15
29
|
|
16
|
-
|
17
|
-
|
18
|
-
|
30
|
+
pid = fork {
|
31
|
+
pw[1].close
|
32
|
+
STDIN.reopen(pw[0])
|
33
|
+
pw[0].close
|
19
34
|
|
20
|
-
|
21
|
-
|
22
|
-
|
35
|
+
pr[0].close
|
36
|
+
STDOUT.reopen(pr[1])
|
37
|
+
pr[1].close
|
23
38
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
39
|
+
pe[0].close
|
40
|
+
STDERR.reopen(pe[1])
|
41
|
+
pe[1].close
|
42
|
+
|
43
|
+
exec(cmd)
|
44
|
+
}
|
45
|
+
|
46
|
+
pw[0].close
|
47
|
+
pr[1].close
|
48
|
+
pe[1].close
|
49
|
+
pi = [pw[1], pr[0], pe[0]]
|
50
|
+
pw[1].sync = true
|
51
|
+
begin
|
52
|
+
yield(*pi) if block_given?
|
53
|
+
ensure
|
54
|
+
pi.each{|p| p.close unless p.closed?}
|
35
55
|
end
|
36
|
-
|
37
|
-
pi.each{|p| p.close unless p.closed?}
|
56
|
+
Process.waitpid pid
|
38
57
|
end
|
39
58
|
pid
|
40
59
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 1
|
9
|
+
version: 0.3.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jeremy Ashkenas
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-06-
|
18
|
+
date: 2010-06-11 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|