yui-compressor 0.9.6 → 0.12.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.
- checksums.yaml +7 -0
- data/README.rdoc +147 -0
- data/Rakefile +4 -4
- data/lib/yui/compressor.rb +46 -30
- data/lib/yuicompressor-2.4.8.jar +0 -0
- data/test/compressor_test.rb +15 -0
- metadata +30 -63
- data/lib/yuicompressor-2.4.4.jar +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d9b97c893c00c609838029f8a8611fd04f7177cf
|
4
|
+
data.tar.gz: 4aa379e225be91d06684d374baaf9d565b27db1c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9bc26358a6156d278dfba4d515e55aa308f02651d37af2787260f440e136fb1b9f0abe7f18e268a0ae7ffae1bd91289982fe27ccba8095366b6f64a85b8fc8b
|
7
|
+
data.tar.gz: 860bdf77773af18d195c945f429fbdbc22ce26efdc1890c4e7bb4d976938823d2d54eac3fda6622f7ca958d264cdc74155e058f8809a72b0562e5aefd0e7ece4
|
data/README.rdoc
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
= Ruby-YUI Compressor
|
2
|
+
|
3
|
+
Ruby-YUI Compressor provides a Ruby interface to the {YUI Compressor Java library}[http://developer.yahoo.com/yui/compressor/] for minifying JavaScript and CSS assets.
|
4
|
+
|
5
|
+
<b>Latest version:</b> 0.12.0 (includes YUI Compressor 2.4.8)
|
6
|
+
|
7
|
+
* {API documentation}[http://yui.rubyforge.org/]
|
8
|
+
* {Source code}[http://github.com/sstephenson/ruby-yui-compressor/]
|
9
|
+
* {Bug tracker}[http://github.com/sstephenson/ruby-yui-compressor/issues]
|
10
|
+
|
11
|
+
Tested on Mac OS X Ruby 1.8.7 and Ruby 1.9.2.
|
12
|
+
|
13
|
+
=== Installing and loading Ruby-YUI Compressor
|
14
|
+
|
15
|
+
Ruby-YUI Compressor is distributed as a Ruby Gem (<tt>yui-compressor</tt>). Because YUI Compressor's .jar file is included in the box, Java >= 1.4 is its only dependency.
|
16
|
+
|
17
|
+
$ sudo gem install -r yui-compressor
|
18
|
+
$ irb -rubygems
|
19
|
+
>> require "yui/compressor"
|
20
|
+
=> true
|
21
|
+
|
22
|
+
You can also install Ruby-YUI Compressor with the {Rip package manager}[http://hellorip.com/]:
|
23
|
+
|
24
|
+
$ rip install git://github.com/sstephenson/ruby-yui-compressor.git 0.12.0
|
25
|
+
$ irb -rrip
|
26
|
+
>> require "yui/compressor"
|
27
|
+
=> true
|
28
|
+
|
29
|
+
=== Using Ruby-YUI Compressor
|
30
|
+
|
31
|
+
Create either a YUI::CssCompressor or a YUI::JavaScriptCompressor. Then pass an IO or string to the YUI::Compressor#compress method and get the compressed contents back as a string or have them yielded to a block.
|
32
|
+
|
33
|
+
==== Example: Compress JavaScript
|
34
|
+
compressor = YUI::JavaScriptCompressor.new
|
35
|
+
compressor.compress('(function () { var foo = {}; foo["bar"] = "baz"; })()')
|
36
|
+
# => "(function(){var foo={};foo.bar=\"baz\"})();"
|
37
|
+
|
38
|
+
==== Example: Compress JavaScript and shorten local variable names
|
39
|
+
compressor = YUI::JavaScriptCompressor.new(:munge => true)
|
40
|
+
compressor.compress('(function () { var foo = {}; foo["bar"] = "baz"; })()')
|
41
|
+
# => "(function(){var a={};a.bar=\"baz\"})();"
|
42
|
+
|
43
|
+
==== Example: Compress CSS
|
44
|
+
compressor = YUI::CssCompressor.new
|
45
|
+
compressor.compress(<<-END_CSS)
|
46
|
+
div.error {
|
47
|
+
color: red;
|
48
|
+
}
|
49
|
+
div.warning {
|
50
|
+
display: none;
|
51
|
+
}
|
52
|
+
END_CSS
|
53
|
+
# => "div.error{color:red;}div.warning{display:none;}"
|
54
|
+
|
55
|
+
==== Overriding the path to Java or the YUI Compressor .jar file
|
56
|
+
|
57
|
+
By default, YUI::Compressor looks for Java as the +java+ command in your path, and uses the YUI Compressor .jar file in YUI::Compressor's vendor directory. You can override both with the :java and :jar_file options:
|
58
|
+
|
59
|
+
YUI::JavaScriptCompressor.new(
|
60
|
+
:java => "/usr/bin/java",
|
61
|
+
:jar_file => "/path/to/my/yuicompressor-2.4.8.jar"
|
62
|
+
)
|
63
|
+
|
64
|
+
==== Additional compression options
|
65
|
+
|
66
|
+
See the YUI::CssCompressor and YUI::JavaScriptCompressor documentation for more information on format-specific compression options.
|
67
|
+
|
68
|
+
|
69
|
+
== Licenses
|
70
|
+
|
71
|
+
==== Ruby-YUI Compressor code and documentation (MIT license)
|
72
|
+
|
73
|
+
Copyright (c) 2011 Sam Stephenson
|
74
|
+
|
75
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
76
|
+
a copy of this software and associated documentation files (the
|
77
|
+
"Software"), to deal in the Software without restriction, including
|
78
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
79
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
80
|
+
permit persons to whom the Software is furnished to do so, subject to
|
81
|
+
the following conditions:
|
82
|
+
|
83
|
+
The above copyright notice and this permission notice shall be
|
84
|
+
included in all copies or substantial portions of the Software.
|
85
|
+
|
86
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
87
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
88
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
89
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
90
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
91
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
92
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
93
|
+
|
94
|
+
==== YUI Compressor (BSD license)
|
95
|
+
|
96
|
+
Copyright (c) 2009, Yahoo! Inc.
|
97
|
+
All rights reserved.
|
98
|
+
|
99
|
+
Redistribution and use of this software in source and binary forms,
|
100
|
+
with or without modification, are permitted provided that the following
|
101
|
+
conditions are met:
|
102
|
+
|
103
|
+
* Redistributions of source code must retain the above
|
104
|
+
copyright notice, this list of conditions and the
|
105
|
+
following disclaimer.
|
106
|
+
|
107
|
+
* Redistributions in binary form must reproduce the above
|
108
|
+
copyright notice, this list of conditions and the
|
109
|
+
following disclaimer in the documentation and/or other
|
110
|
+
materials provided with the distribution.
|
111
|
+
|
112
|
+
* Neither the name of Yahoo! Inc. nor the names of its
|
113
|
+
contributors may be used to endorse or promote products
|
114
|
+
derived from this software without specific prior
|
115
|
+
written permission of Yahoo! Inc.
|
116
|
+
|
117
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
118
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
119
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
120
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
121
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
122
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
123
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
124
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
125
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
126
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
127
|
+
|
128
|
+
This software also requires access to software from the following sources:
|
129
|
+
|
130
|
+
The Jarg Library v 1.0 ( http://jargs.sourceforge.net/ ) is available
|
131
|
+
under a BSD License. Copyright (c) 2001-2003 Steve Purcell,
|
132
|
+
Copyright (c) 2002 Vidar Holen, Copyright (c) 2002 Michal Ceresna and
|
133
|
+
Copyright (c) 2005 Ewan Mellor.
|
134
|
+
|
135
|
+
The Rhino Library ( http://www.mozilla.org/rhino/ ) is dually available
|
136
|
+
under an MPL 1.1/GPL 2.0 license, with portions subject to a BSD license.
|
137
|
+
|
138
|
+
Additionally, this software contains modified versions of the following
|
139
|
+
component files from the Rhino Library:
|
140
|
+
|
141
|
+
[org/mozilla/javascript/Decompiler.java]
|
142
|
+
[org/mozilla/javascript/Parser.java]
|
143
|
+
[org/mozilla/javascript/Token.java]
|
144
|
+
[org/mozilla/javascript/TokenStream.java]
|
145
|
+
|
146
|
+
The modified versions of these files are distributed under the MPL v 1.1
|
147
|
+
( http://www.mozilla.org/MPL/MPL-1.1.html )
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "rubygems"
|
2
|
-
require "
|
3
|
-
require "
|
2
|
+
require "rubygems/package_task"
|
3
|
+
require "rdoc/task"
|
4
4
|
require "rake/testtask"
|
5
5
|
|
6
6
|
task :default => :test
|
@@ -11,11 +11,11 @@ Rake::TestTask.new do |t|
|
|
11
11
|
t.verbose = true
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
RDoc::Task.new do |t|
|
15
15
|
t.rdoc_files.include("README.rdoc", "lib/**/*.rb")
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
Gem::PackageTask.new(eval(IO.read(File.join(File.dirname(__FILE__), "yui-compressor.gemspec")))) do |pkg|
|
19
19
|
pkg.need_zip = true
|
20
20
|
pkg.need_tar = true
|
21
21
|
end
|
data/lib/yui/compressor.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require "popen4"
|
2
1
|
require "shellwords"
|
3
2
|
require "stringio"
|
3
|
+
require "tempfile"
|
4
|
+
require "rbconfig"
|
4
5
|
|
5
6
|
module YUI #:nodoc:
|
6
7
|
class Compressor
|
7
|
-
VERSION = "0.
|
8
|
+
VERSION = "0.12.0"
|
8
9
|
|
9
10
|
class Error < StandardError; end
|
10
11
|
class OptionError < Error; end
|
@@ -22,11 +23,30 @@ module YUI #:nodoc:
|
|
22
23
|
|
23
24
|
def initialize(options = {}) #:nodoc:
|
24
25
|
@options = self.class.default_options.merge(options)
|
25
|
-
@command = [path_to_java
|
26
|
+
@command = [path_to_java]
|
27
|
+
@command.push(*java_opts)
|
28
|
+
@command.push("-jar")
|
29
|
+
@command.push(path_to_jar_file)
|
30
|
+
@command.push(*(command_option_for_type + command_options))
|
31
|
+
@command.compact!
|
26
32
|
end
|
27
33
|
|
28
34
|
def command #:nodoc:
|
29
|
-
|
35
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
36
|
+
# Shellwords is only for bourne shells, so windows shells get this
|
37
|
+
# extremely remedial escaping
|
38
|
+
escaped_cmd = @command.map do |word|
|
39
|
+
if word =~ / /
|
40
|
+
word = "\"%s\"" % word
|
41
|
+
end
|
42
|
+
|
43
|
+
word
|
44
|
+
end
|
45
|
+
else
|
46
|
+
escaped_cmd = @command.map { |word| Shellwords.escape(word) }
|
47
|
+
end
|
48
|
+
|
49
|
+
escaped_cmd.join(" ")
|
30
50
|
end
|
31
51
|
|
32
52
|
# Compress a stream or string of code with YUI Compressor. (A stream is
|
@@ -64,27 +84,27 @@ module YUI #:nodoc:
|
|
64
84
|
#
|
65
85
|
def compress(stream_or_string)
|
66
86
|
streamify(stream_or_string) do |stream|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
rescue Exception => e
|
80
|
-
raise RuntimeError, "compression failed"
|
81
|
-
end
|
87
|
+
tempfile = Tempfile.new('yui_compress')
|
88
|
+
tempfile.write stream.read
|
89
|
+
tempfile.flush
|
90
|
+
full_command = "%s %s" % [command, tempfile.path]
|
91
|
+
|
92
|
+
begin
|
93
|
+
output = `#{full_command}`
|
94
|
+
rescue Exception => e
|
95
|
+
# windows shells tend to blow up here when the command fails
|
96
|
+
raise RuntimeError, "compression failed: %s" % e.message
|
97
|
+
ensure
|
98
|
+
tempfile.close!
|
82
99
|
end
|
83
100
|
|
84
|
-
if
|
101
|
+
if $?.exitstatus.zero?
|
85
102
|
output
|
86
103
|
else
|
87
|
-
|
104
|
+
# Bourne shells tend to blow up here when the command fails, usually
|
105
|
+
# because java is missing
|
106
|
+
raise RuntimeError, "Command '%s' returned non-zero exit status" %
|
107
|
+
full_command
|
88
108
|
end
|
89
109
|
end
|
90
110
|
end
|
@@ -106,8 +126,12 @@ module YUI #:nodoc:
|
|
106
126
|
options.delete(:java) || "java"
|
107
127
|
end
|
108
128
|
|
129
|
+
def java_opts
|
130
|
+
options.delete(:java_opts).to_s.split(/\s+/)
|
131
|
+
end
|
132
|
+
|
109
133
|
def path_to_jar_file
|
110
|
-
options.delete(:jar_file) || File.join(File.dirname(__FILE__), *%w".. yuicompressor-2.4.
|
134
|
+
options.delete(:jar_file) || File.join(File.dirname(__FILE__), *%w".. yuicompressor-2.4.8.jar")
|
111
135
|
end
|
112
136
|
|
113
137
|
def streamify(stream_or_string)
|
@@ -118,14 +142,6 @@ module YUI #:nodoc:
|
|
118
142
|
end
|
119
143
|
end
|
120
144
|
|
121
|
-
def transfer(from_stream, to_stream)
|
122
|
-
while buffer = from_stream.read(4096)
|
123
|
-
to_stream.write(buffer)
|
124
|
-
end
|
125
|
-
from_stream.close
|
126
|
-
to_stream.close
|
127
|
-
end
|
128
|
-
|
129
145
|
def command_option_for_type
|
130
146
|
["--type", self.class.compressor_type.to_s]
|
131
147
|
end
|
Binary file
|
data/test/compressor_test.rb
CHANGED
@@ -36,6 +36,21 @@ module YUI
|
|
36
36
|
|
37
37
|
FIXTURE_ERROR_JS = "var x = {class: 'name'};"
|
38
38
|
|
39
|
+
def test_js_java_opts_one_opt
|
40
|
+
@compressor = YUI::JavaScriptCompressor.new(:java_opts => "-Xms64M")
|
41
|
+
assert_match(/^java -Xms64M/, @compressor.command)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_css_java_opts_two_opts
|
45
|
+
@compressor = YUI::CssCompressor.new(:java_opts => "-Xms64M -Xmx64M")
|
46
|
+
assert_match(/^java -Xms64M -Xmx64M/, @compressor.command)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_js_java_opts_no_opts
|
50
|
+
@compressor = YUI::JavaScriptCompressor.new()
|
51
|
+
assert_match(/^java -jar/, @compressor.command)
|
52
|
+
end
|
53
|
+
|
39
54
|
def test_compressor_should_raise_when_instantiated
|
40
55
|
assert_raises YUI::Compressor::Error do
|
41
56
|
YUI::Compressor.new
|
metadata
CHANGED
@@ -1,85 +1,52 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: yui-compressor
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
- 6
|
10
|
-
version: 0.9.6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.12.0
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Sam Stephenson
|
8
|
+
- Stephen Crosby
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
default_executable:
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
22
|
-
name: POpen4
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 19
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 1
|
33
|
-
- 4
|
34
|
-
version: 0.1.4
|
35
|
-
type: :runtime
|
36
|
-
version_requirements: *id001
|
12
|
+
date: 2013-09-29 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
37
14
|
description: A Ruby interface to YUI Compressor for minifying JavaScript and CSS assets.
|
38
|
-
email:
|
15
|
+
email: stevecrozz@gmail.com
|
39
16
|
executables: []
|
40
|
-
|
41
17
|
extensions: []
|
42
|
-
|
43
18
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
|
19
|
+
files:
|
20
|
+
- README.rdoc
|
46
21
|
- Rakefile
|
22
|
+
- lib/yuicompressor-2.4.8.jar
|
47
23
|
- lib/yui/compressor.rb
|
48
|
-
- lib/yuicompressor-2.4.4.jar
|
49
24
|
- test/compressor_test.rb
|
50
|
-
has_rdoc: true
|
51
25
|
homepage: http://github.com/sstephenson/ruby-yui-compressor/
|
52
|
-
licenses:
|
53
|
-
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
- BSD-3-clause
|
29
|
+
- MPL
|
30
|
+
metadata: {}
|
54
31
|
post_install_message:
|
55
32
|
rdoc_options: []
|
56
|
-
|
57
|
-
require_paths:
|
33
|
+
require_paths:
|
58
34
|
- lib
|
59
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
none: false
|
70
|
-
requirements:
|
71
|
-
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
hash: 3
|
74
|
-
segments:
|
75
|
-
- 0
|
76
|
-
version: "0"
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
77
45
|
requirements: []
|
78
|
-
|
79
46
|
rubyforge_project: yui
|
80
|
-
rubygems_version:
|
47
|
+
rubygems_version: 2.0.0
|
81
48
|
signing_key:
|
82
|
-
specification_version:
|
49
|
+
specification_version: 4
|
83
50
|
summary: JavaScript and CSS minification library
|
84
|
-
test_files:
|
51
|
+
test_files:
|
85
52
|
- test/compressor_test.rb
|
data/lib/yuicompressor-2.4.4.jar
DELETED
Binary file
|