closure-compiler 1.1.7 → 1.1.8
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 +16 -6
- data/closure-compiler.gemspec +3 -3
- data/lib/closure-compiler-20121212.jar +0 -0
- data/lib/closure-compiler.rb +2 -2
- data/lib/closure/compiler.rb +28 -8
- metadata +5 -5
- data/lib/closure-compiler-20120710.jar +0 -0
data/README.textile
CHANGED
@@ -2,19 +2,19 @@ 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.8":http://rubygems.org/gems/closure-compiler*
|
6
6
|
|
7
|
-
The Closure Compiler's *2012-
|
7
|
+
The Closure Compiler's *2012-12-12* JAR-file is included with the gem.
|
8
8
|
|
9
9
|
h2. Installation
|
10
10
|
|
11
11
|
<pre>
|
12
12
|
sudo gem install closure-compiler
|
13
13
|
</pre>
|
14
|
-
|
14
|
+
|
15
15
|
h2. Usage
|
16
16
|
|
17
|
-
The @Closure::Compiler@ has a
|
17
|
+
The @Closure::Compiler@ has a @compile@ method, which can be passed a string or an open @IO@ object, and returns the compiled JavaScript. The result is returned as a string, or, if a block is passed, yields as an @IO@ object for streaming writes.
|
18
18
|
|
19
19
|
<pre>
|
20
20
|
require 'rubygems'
|
@@ -23,13 +23,23 @@ Closure::Compiler.new.compile(File.open('underscore.js', 'r'))
|
|
23
23
|
|
24
24
|
=> "(function(){var j=this,m=j._;function i(a){......
|
25
25
|
</pre>
|
26
|
-
|
26
|
+
|
27
|
+
The @Closure::Compiler@ also has @compile_file@ and @compile_files@ methods, which can be passed a file path or an array of file paths respectively. The files are concatenated and compiled and, like the @compile@ method, the result is returned as a string or, if block is passed, yields an @IO@ object.
|
28
|
+
|
29
|
+
<pre>
|
30
|
+
require 'rubygems'
|
31
|
+
require 'closure-compiler'
|
32
|
+
Closure::Compiler.new.compile_files(['underscore.js', 'jasmine.js']))
|
33
|
+
|
34
|
+
=> "(function(){var j=this,m=j._;function i(a){......
|
35
|
+
</pre>
|
36
|
+
|
27
37
|
When creating a @Closure::Compiler@, you can pass "any options that the command-line compiler accepts":http://code.google.com/closure/compiler/docs/gettingstarted_app.html to the initializer and they'll be forwarded. For example, to raise the compilation level up a notch:
|
28
38
|
|
29
39
|
<pre>
|
30
40
|
closure = Closure::Compiler.new(:compilation_level => 'ADVANCED_OPTIMIZATIONS')
|
31
41
|
closure.compile(File.open('underscore.js', 'r'))
|
32
|
-
|
42
|
+
|
33
43
|
=> "(function(){var j=this,m=j.h;function i(a){......
|
34
44
|
</pre>
|
35
45
|
|
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 = '1.1.
|
4
|
-
s.date = '2012-
|
3
|
+
s.version = '1.1.8' # Keep version in sync with closure-compiler.rb
|
4
|
+
s.date = '2012-12-28'
|
5
5
|
|
6
6
|
s.homepage = "http://github.com/documentcloud/closure-compiler/"
|
7
7
|
s.summary = "Ruby Wrapper for the Google Closure Compiler"
|
@@ -21,4 +21,4 @@ Gem::Specification.new do |s|
|
|
21
21
|
|
22
22
|
s.files = Dir['lib/**/*', 'vendor/**/*', 'closure-compiler.gemspec', 'README.textile', 'LICENSE', 'COPYING']
|
23
23
|
|
24
|
-
end
|
24
|
+
end
|
Binary file
|
data/lib/closure-compiler.rb
CHANGED
data/lib/closure/compiler.rb
CHANGED
@@ -10,13 +10,16 @@ module Closure
|
|
10
10
|
# much to see here.
|
11
11
|
class Compiler
|
12
12
|
|
13
|
-
DEFAULT_OPTIONS = {
|
13
|
+
DEFAULT_OPTIONS = {
|
14
|
+
:warning_level => 'QUIET',
|
15
|
+
:language_in => 'ECMASCRIPT5'
|
16
|
+
}
|
14
17
|
|
15
18
|
# When you create a Compiler, pass in the flags and options.
|
16
19
|
def initialize(options={})
|
17
20
|
@java = options.delete(:java) || JAVA_COMMAND
|
18
21
|
@jar = options.delete(:jar_file) || COMPILER_JAR
|
19
|
-
@options =
|
22
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
20
23
|
end
|
21
24
|
|
22
25
|
# Can compile a JavaScript string or open IO object. Returns the compiled
|
@@ -34,12 +37,30 @@ module Closure
|
|
34
37
|
tempfile.flush
|
35
38
|
|
36
39
|
begin
|
37
|
-
result =
|
38
|
-
rescue Exception
|
39
|
-
raise
|
40
|
+
result = compile_files(tempfile.path)
|
41
|
+
rescue Exception => e
|
42
|
+
raise e
|
40
43
|
ensure
|
41
44
|
tempfile.close!
|
42
45
|
end
|
46
|
+
|
47
|
+
yield(StringIO.new(result)) if block_given?
|
48
|
+
result
|
49
|
+
end
|
50
|
+
alias_method :compress, :compile
|
51
|
+
|
52
|
+
# Takes an array of javascript file paths or a single path. Returns the
|
53
|
+
# resulting JavaScript as a string or yields an IO object containing the
|
54
|
+
# response to a block, for streaming.
|
55
|
+
def compile_files(files)
|
56
|
+
@options.merge!(:js => files)
|
57
|
+
|
58
|
+
begin
|
59
|
+
result = `#{command} 2>&1`
|
60
|
+
rescue Exception
|
61
|
+
raise Error, "compression failed: #{result}"
|
62
|
+
end
|
63
|
+
|
43
64
|
unless $?.exitstatus.zero?
|
44
65
|
raise Error, result
|
45
66
|
end
|
@@ -47,8 +68,7 @@ module Closure
|
|
47
68
|
yield(StringIO.new(result)) if block_given?
|
48
69
|
result
|
49
70
|
end
|
50
|
-
alias_method :
|
51
|
-
|
71
|
+
alias_method :compile_file, :compile_files
|
52
72
|
|
53
73
|
private
|
54
74
|
|
@@ -64,7 +84,7 @@ module Closure
|
|
64
84
|
end
|
65
85
|
|
66
86
|
def command
|
67
|
-
[@java, '-jar', "\"#{@jar}\"", @options].flatten.join(' ')
|
87
|
+
[@java, '-jar', "\"#{@jar}\"", serialize_options(@options)].flatten.join(' ')
|
68
88
|
end
|
69
89
|
|
70
90
|
end
|
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: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 8
|
10
|
+
version: 1.1.8
|
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: 2012-
|
19
|
+
date: 2012-12-28 00:00:00 Z
|
20
20
|
dependencies: []
|
21
21
|
|
22
22
|
description: " A Ruby Wrapper for the Google Closure Compiler.\n"
|
@@ -29,7 +29,7 @@ extra_rdoc_files: []
|
|
29
29
|
|
30
30
|
files:
|
31
31
|
- lib/closure/compiler.rb
|
32
|
-
- lib/closure-compiler-
|
32
|
+
- lib/closure-compiler-20121212.jar
|
33
33
|
- lib/closure-compiler.rb
|
34
34
|
- closure-compiler.gemspec
|
35
35
|
- README.textile
|
Binary file
|