yui-compressor 0.10.0 → 0.11.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.
Files changed (4) hide show
  1. data/README.rdoc +2 -2
  2. data/Rakefile +3 -3
  3. data/lib/yui/compressor.rb +35 -28
  4. metadata +22 -54
@@ -2,7 +2,7 @@
2
2
 
3
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
4
 
5
- <b>Latest version:</b> 0.10.0 (includes YUI Compressor 2.4.7)
5
+ <b>Latest version:</b> 0.11.0 (includes YUI Compressor 2.4.7)
6
6
 
7
7
  * {API documentation}[http://yui.rubyforge.org/]
8
8
  * {Source code}[http://github.com/sstephenson/ruby-yui-compressor/]
@@ -21,7 +21,7 @@ Ruby-YUI Compressor is distributed as a Ruby Gem (<tt>yui-compressor</tt>). Beca
21
21
 
22
22
  You can also install Ruby-YUI Compressor with the {Rip package manager}[http://hellorip.com/]:
23
23
 
24
- $ rip install git://github.com/sstephenson/ruby-yui-compressor.git 0.10.0
24
+ $ rip install git://github.com/sstephenson/ruby-yui-compressor.git 0.11.0
25
25
  $ irb -rrip
26
26
  >> require "yui/compressor"
27
27
  => true
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
1
  require "rubygems"
2
- require "rubygems/package_task"
3
- require "rdoc/task"
2
+ require "rake/gempackagetask"
3
+ require "rake/rdoctask"
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
- Gem::PackageTask.new(eval(IO.read(File.join(File.dirname(__FILE__), "yui-compressor.gemspec")))) do |pkg|
18
+ Rake::GemPackageTask.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
@@ -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.10.0"
8
+ VERSION = "0.11.0"
8
9
 
9
10
  class Error < StandardError; end
10
11
  class OptionError < Error; end
@@ -31,7 +32,21 @@ module YUI #:nodoc:
31
32
  end
32
33
 
33
34
  def command #:nodoc:
34
- @command.map { |word| Shellwords.escape(word) }.join(" ")
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(" ")
35
50
  end
36
51
 
37
52
  # Compress a stream or string of code with YUI Compressor. (A stream is
@@ -69,27 +84,27 @@ module YUI #:nodoc:
69
84
  #
70
85
  def compress(stream_or_string)
71
86
  streamify(stream_or_string) do |stream|
72
- output = true
73
- status = POpen4.popen4(command, "b") do |stdout, stderr, stdin, pid|
74
- begin
75
- stdin.binmode
76
- transfer(stream, stdin)
77
-
78
- if block_given?
79
- yield stdout
80
- else
81
- output = stdout.read
82
- end
83
-
84
- rescue Exception => e
85
- raise RuntimeError, "compression failed"
86
- 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!
87
99
  end
88
100
 
89
- if status.exitstatus.zero?
101
+ if $?.exitstatus.zero?
90
102
  output
91
103
  else
92
- raise RuntimeError, "compression failed"
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
93
108
  end
94
109
  end
95
110
  end
@@ -127,14 +142,6 @@ module YUI #:nodoc:
127
142
  end
128
143
  end
129
144
 
130
- def transfer(from_stream, to_stream)
131
- while buffer = from_stream.read(4096)
132
- to_stream.write(buffer)
133
- end
134
- from_stream.close
135
- to_stream.close
136
- end
137
-
138
145
  def command_option_for_type
139
146
  ["--type", self.class.compressor_type.to_s]
140
147
  end
metadata CHANGED
@@ -1,86 +1,54 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: yui-compressor
3
- version: !ruby/object:Gem::Version
4
- hash: 55
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.11.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 10
9
- - 0
10
- version: 0.10.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Sam Stephenson
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-03-30 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: POpen4
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 19
29
- segments:
30
- - 0
31
- - 1
32
- - 4
33
- version: 0.1.4
34
- type: :runtime
35
- version_requirements: *id001
12
+ date: 2013-07-14 00:00:00.000000000 Z
13
+ dependencies: []
36
14
  description: A Ruby interface to YUI Compressor for minifying JavaScript and CSS assets.
37
15
  email: sstephenson@gmail.com
38
16
  executables: []
39
-
40
17
  extensions: []
41
-
42
18
  extra_rdoc_files: []
43
-
44
- files:
19
+ files:
45
20
  - README.rdoc
46
21
  - Rakefile
47
22
  - lib/yui/compressor.rb
48
23
  - lib/yuicompressor-2.4.7.jar
49
24
  - test/compressor_test.rb
50
25
  homepage: http://github.com/sstephenson/ruby-yui-compressor/
51
- licenses:
26
+ licenses:
52
27
  - MIT
53
28
  - BSD-3-clause
54
29
  - MPL
55
30
  post_install_message:
56
31
  rdoc_options: []
57
-
58
- require_paths:
32
+ require_paths:
59
33
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
34
+ required_ruby_version: !ruby/object:Gem::Requirement
61
35
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
41
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
78
46
  requirements: []
79
-
80
47
  rubyforge_project: yui
81
- rubygems_version: 1.8.24
48
+ rubygems_version: 1.8.23
82
49
  signing_key:
83
50
  specification_version: 3
84
51
  summary: JavaScript and CSS minification library
85
- test_files:
52
+ test_files:
86
53
  - test/compressor_test.rb
54
+ has_rdoc: true