yui-compressor 0.9.6 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.10.0 (includes YUI Compressor 2.4.7)
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.10.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.7.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 "rake/gempackagetask"
3
- require "rake/rdoctask"
2
+ require "rubygems/package_task"
3
+ require "rdoc/task"
4
4
  require "rake/testtask"
5
5
 
6
6
  task :default => :test
@@ -15,7 +15,7 @@ Rake::RDocTask.new do |t|
15
15
  t.rdoc_files.include("README.rdoc", "lib/**/*.rb")
16
16
  end
17
17
 
18
- Rake::GemPackageTask.new(eval(IO.read(File.join(File.dirname(__FILE__), "yui-compressor.gemspec")))) do |pkg|
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
@@ -4,7 +4,7 @@ require "stringio"
4
4
 
5
5
  module YUI #:nodoc:
6
6
  class Compressor
7
- VERSION = "0.9.6"
7
+ VERSION = "0.10.0"
8
8
 
9
9
  class Error < StandardError; end
10
10
  class OptionError < Error; end
@@ -22,7 +22,12 @@ module YUI #:nodoc:
22
22
 
23
23
  def initialize(options = {}) #:nodoc:
24
24
  @options = self.class.default_options.merge(options)
25
- @command = [path_to_java, "-jar", path_to_jar_file, *(command_option_for_type + command_options)]
25
+ @command = [path_to_java]
26
+ @command.push(*java_opts)
27
+ @command.push("-jar")
28
+ @command.push(path_to_jar_file)
29
+ @command.push(*(command_option_for_type + command_options))
30
+ @command.compact!
26
31
  end
27
32
 
28
33
  def command #:nodoc:
@@ -106,8 +111,12 @@ module YUI #:nodoc:
106
111
  options.delete(:java) || "java"
107
112
  end
108
113
 
114
+ def java_opts
115
+ options.delete(:java_opts).to_s.split(/\s+/)
116
+ end
117
+
109
118
  def path_to_jar_file
110
- options.delete(:jar_file) || File.join(File.dirname(__FILE__), *%w".. yuicompressor-2.4.4.jar")
119
+ options.delete(:jar_file) || File.join(File.dirname(__FILE__), *%w".. yuicompressor-2.4.7.jar")
111
120
  end
112
121
 
113
122
  def streamify(stream_or_string)
@@ -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
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 9
9
- - 6
10
- version: 0.9.6
8
+ - 10
9
+ - 0
10
+ version: 0.10.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Stephenson
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-30 00:00:00 -05:00
19
- default_executable:
18
+ date: 2011-03-30 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: POpen4
@@ -43,14 +42,16 @@ extensions: []
43
42
  extra_rdoc_files: []
44
43
 
45
44
  files:
45
+ - README.rdoc
46
46
  - Rakefile
47
47
  - lib/yui/compressor.rb
48
- - lib/yuicompressor-2.4.4.jar
48
+ - lib/yuicompressor-2.4.7.jar
49
49
  - test/compressor_test.rb
50
- has_rdoc: true
51
50
  homepage: http://github.com/sstephenson/ruby-yui-compressor/
52
- licenses: []
53
-
51
+ licenses:
52
+ - MIT
53
+ - BSD-3-clause
54
+ - MPL
54
55
  post_install_message:
55
56
  rdoc_options: []
56
57
 
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  requirements: []
78
79
 
79
80
  rubyforge_project: yui
80
- rubygems_version: 1.5.0
81
+ rubygems_version: 1.8.24
81
82
  signing_key:
82
83
  specification_version: 3
83
84
  summary: JavaScript and CSS minification library