closure-compiler 1.1.2 → 1.1.3
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.textile +1 -1
- data/closure-compiler.gemspec +1 -1
- data/lib/closure-compiler-20110322.jar +0 -0
- data/lib/closure-compiler.rb +1 -2
- data/lib/closure/compiler.rb +32 -23
- metadata +4 -4
- data/lib/closure/popen.rb +0 -66
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: *"1.1.
|
5
|
+
Latest Version: *"1.1.3":http://gemcutter.org/gems/closure-compiler*
|
6
6
|
|
7
7
|
The Closure Compiler's *2011-08-11* JAR-file is included with the gem.
|
8
8
|
|
data/closure-compiler.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'closure-compiler'
|
3
|
-
s.version = '1.1.
|
3
|
+
s.version = '1.1.3' # Keep version in sync with closure-compiler.rb
|
4
4
|
s.date = '2011-08-12'
|
5
5
|
|
6
6
|
s.homepage = "http://github.com/documentcloud/closure-compiler/"
|
Binary file
|
data/lib/closure-compiler.rb
CHANGED
data/lib/closure/compiler.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'stringio'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
module Closure
|
4
5
|
|
@@ -8,40 +9,42 @@ module Closure
|
|
8
9
|
# The Closure::Compiler is a basic wrapper around the actual JAR. There's not
|
9
10
|
# much to see here.
|
10
11
|
class Compiler
|
12
|
+
|
13
|
+
DEFAULT_OPTIONS = {:warning_level => 'QUIET'}
|
11
14
|
|
12
15
|
# When you create a Compiler, pass in the flags and options.
|
13
16
|
def initialize(options={})
|
14
17
|
@java = options.delete(:java) || JAVA_COMMAND
|
15
18
|
@jar = options.delete(:jar_file) || COMPILER_JAR
|
16
|
-
@options = serialize_options(options)
|
19
|
+
@options = serialize_options(DEFAULT_OPTIONS.merge(options))
|
17
20
|
end
|
18
21
|
|
19
22
|
# Can compile a JavaScript string or open IO object. Returns the compiled
|
20
23
|
# JavaScript as a string or yields an IO object containing the response to a
|
21
24
|
# block, for streaming.
|
22
25
|
def compile(io)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
stdin.write(buffer)
|
28
|
-
end
|
29
|
-
else
|
30
|
-
stdin.write(io.to_s)
|
31
|
-
end
|
32
|
-
stdin.close
|
33
|
-
if Closure::Popen::WINDOWS
|
34
|
-
stderr.close
|
35
|
-
result = stdout.read
|
36
|
-
error = "Stderr cannot be read on Windows."
|
37
|
-
else
|
38
|
-
out_thread = Thread.new { result = stdout.read }
|
39
|
-
err_thread = Thread.new { error = stderr.read }
|
40
|
-
out_thread.join and err_thread.join
|
26
|
+
tempfile = Tempfile.new('closure_compiler')
|
27
|
+
if io.respond_to? :read
|
28
|
+
while buffer = io.read(4096) do
|
29
|
+
tempfile.write(buffer)
|
41
30
|
end
|
42
|
-
|
31
|
+
else
|
32
|
+
tempfile.write(io.to_s)
|
33
|
+
end
|
34
|
+
tempfile.flush
|
35
|
+
|
36
|
+
begin
|
37
|
+
result = `#{command} --js #{tempfile.path}`
|
38
|
+
rescue Exception
|
39
|
+
raise Error, "compression failed"
|
40
|
+
ensure
|
41
|
+
tempfile.close!
|
43
42
|
end
|
44
|
-
|
43
|
+
unless $?.exitstatus.zero?
|
44
|
+
raise Error, result
|
45
|
+
end
|
46
|
+
|
47
|
+
yield(StringIO.new(result)) if block_given?
|
45
48
|
result
|
46
49
|
end
|
47
50
|
alias_method :compress, :compile
|
@@ -51,7 +54,13 @@ module Closure
|
|
51
54
|
|
52
55
|
# Serialize hash options to the command-line format.
|
53
56
|
def serialize_options(options)
|
54
|
-
options.map
|
57
|
+
options.map do |k, v|
|
58
|
+
if (v.is_a?(Array))
|
59
|
+
v.map {|v2| ["--#{k}", v2.to_s]}
|
60
|
+
else
|
61
|
+
["--#{k}", v.to_s]
|
62
|
+
end
|
63
|
+
end.flatten
|
55
64
|
end
|
56
65
|
|
57
66
|
def command
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: closure-compiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 3
|
10
|
+
version: 1.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeremy Ashkenas
|
@@ -29,7 +29,7 @@ extra_rdoc_files: []
|
|
29
29
|
|
30
30
|
files:
|
31
31
|
- lib/closure/compiler.rb
|
32
|
-
- lib/closure
|
32
|
+
- lib/closure-compiler-20110322.jar
|
33
33
|
- lib/closure-compiler-20110811.jar
|
34
34
|
- lib/closure-compiler.rb
|
35
35
|
- closure-compiler.gemspec
|
data/lib/closure/popen.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
module Closure
|
2
|
-
|
3
|
-
# A slightly modified version of Ruby 1.8's Open3, that doesn't use a
|
4
|
-
# grandchild process, and returns the pid of the external process.
|
5
|
-
module Popen
|
6
|
-
|
7
|
-
WINDOWS = RUBY_PLATFORM.match(/(win|w)32$/)
|
8
|
-
ONE_NINE = RUBY_VERSION >= "1.9"
|
9
|
-
if WINDOWS
|
10
|
-
if ONE_NINE
|
11
|
-
require 'open3'
|
12
|
-
else
|
13
|
-
require 'rubygems'
|
14
|
-
require 'win32/open3'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.popen(cmd)
|
19
|
-
if WINDOWS
|
20
|
-
error = nil
|
21
|
-
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thread|
|
22
|
-
yield(stdin, stdout, stderr) if block_given?
|
23
|
-
stdout.read unless stdout.closed? or stdout.eof?
|
24
|
-
unless stderr.closed?
|
25
|
-
stderr.rewind
|
26
|
-
error = stderr.read
|
27
|
-
end
|
28
|
-
return wait_thread.value if wait_thread.is_a? Thread
|
29
|
-
end
|
30
|
-
else
|
31
|
-
# pipe[0] for read, pipe[1] for write
|
32
|
-
pw, pr, pe = IO.pipe, IO.pipe, IO.pipe
|
33
|
-
|
34
|
-
pid = fork {
|
35
|
-
pw[1].close
|
36
|
-
STDIN.reopen(pw[0])
|
37
|
-
pw[0].close
|
38
|
-
|
39
|
-
pr[0].close
|
40
|
-
STDOUT.reopen(pr[1])
|
41
|
-
pr[1].close
|
42
|
-
|
43
|
-
pe[0].close
|
44
|
-
STDERR.reopen(pe[1])
|
45
|
-
pe[1].close
|
46
|
-
|
47
|
-
exec(cmd)
|
48
|
-
}
|
49
|
-
|
50
|
-
pw[0].close
|
51
|
-
pr[1].close
|
52
|
-
pe[1].close
|
53
|
-
pi = [pw[1], pr[0], pe[0]]
|
54
|
-
pw[1].sync = true
|
55
|
-
begin
|
56
|
-
yield(*pi) if block_given?
|
57
|
-
ensure
|
58
|
-
pi.each{|p| p.close unless p.closed?}
|
59
|
-
end
|
60
|
-
Process.waitpid pid
|
61
|
-
end
|
62
|
-
$?
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|