yuicompressor 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/yuicompressor.rb CHANGED
@@ -1,13 +1,9 @@
1
1
  require 'stringio'
2
2
 
3
3
  module YUICompressor
4
-
5
4
  # The path to the YUI Compressor jar file.
6
5
  JAR_FILE = File.expand_path('../yuicompressor-2.4.2.jar', __FILE__)
7
6
 
8
- autoload :JRuby, 'yuicompressor/jruby'
9
- autoload :Shell, 'yuicompressor/shell'
10
-
11
7
  module_function
12
8
 
13
9
  # Returns +true+ if the Ruby platform is JRuby.
@@ -68,12 +64,9 @@ module YUICompressor
68
64
  # If we're on JRuby we can use the YUI Compressor Java classes directly. This
69
65
  # gives a huge speed boost. Otherwise we need to make a system call to the
70
66
  # Java interpreter and stream IO to/from the shell.
71
- mod = jruby? ? JRuby : Shell
72
-
73
- include mod
74
-
75
- mod.instance_methods.each do |name|
76
- module_function name
67
+ if jruby?
68
+ require 'yuicompressor/jruby'
69
+ else
70
+ require 'yuicompressor/shell'
77
71
  end
78
-
79
72
  end
@@ -2,85 +2,83 @@ require 'java'
2
2
  require 'stringio'
3
3
 
4
4
  module YUICompressor
5
- # This module contains methods specific to the JRuby platform and is
6
- # automatically used when JRuby is detected. It provides a significant
7
- # increase in performance over the Shell module.
8
- module JRuby
5
+ # This file contains methods specific to the JRuby platform and is
6
+ # automatically used when JRuby is detected.
9
7
 
10
- require JAR_FILE
8
+ require JAR_FILE
11
9
 
12
- import java.io.InputStreamReader
13
- import java.io.OutputStreamWriter
14
- import com.yahoo.platform.yui.compressor.JavaScriptCompressor
15
- import com.yahoo.platform.yui.compressor.CssCompressor
10
+ import java.io.InputStreamReader
11
+ import java.io.OutputStreamWriter
12
+ import com.yahoo.platform.yui.compressor.JavaScriptCompressor
13
+ import com.yahoo.platform.yui.compressor.CssCompressor
16
14
 
17
- class ErrorReporter #:nodoc:
18
- def error(message, source_name, line, line_source, line_offset)
19
- if line < 0
20
- "\n[ERROR] %s" % message
21
- else
22
- "\n[ERROR] %s:%s:%s" % [line, line_offset, message]
23
- end
15
+ class ErrorReporter #:nodoc:
16
+ def error(message, source_name, line, line_source, line_offset)
17
+ if line < 0
18
+ "\n[ERROR] %s" % message
19
+ else
20
+ "\n[ERROR] %s:%s:%s" % [line, line_offset, message]
24
21
  end
22
+ end
25
23
 
26
- def runtimeError(*args)
27
- raise RuntimeError, 'Compression failed. %s' % error(*args)
28
- end
24
+ def runtimeError(*args)
25
+ raise RuntimeError, 'Compression failed. %s' % error(*args)
29
26
  end
27
+ end
30
28
 
31
- # Returns the set of arguments that are needed to instantiate a compressor
32
- # using the given +options+.
33
- def command_arguments(options={})
34
- args = [ options[:line_break] ? options[:line_break].to_i : -1 ]
29
+ module_function
35
30
 
36
- if options[:type].to_s == 'js'
37
- args << !! options[:munge]
38
- args << false # verbose?
39
- args << !! options[:preserve_semicolons]
40
- args << ! options[:optimize] # disable optimizations?
41
- end
31
+ # Returns the set of arguments that are needed to instantiate a compressor
32
+ # using the given +options+.
33
+ def command_arguments(options={})
34
+ args = [ options[:line_break] ? options[:line_break].to_i : -1 ]
42
35
 
43
- args
36
+ if options[:type].to_s == 'js'
37
+ args << !! options[:munge]
38
+ args << false # verbose?
39
+ args << !! options[:preserve_semicolons]
40
+ args << ! options[:optimize] # disable optimizations?
44
41
  end
45
42
 
46
- # Compresses the given +stream_or_string+ of code using the given +options+.
47
- # When using this method directly, at least the +:type+ option must be
48
- # specified, and should be one of <tt>"css"</tt> or <tt>"js"</tt>. See
49
- # YUICompressor#compress_css and YUICompressor#compress_js for details about
50
- # which options are acceptable for each type of compressor.
51
- #
52
- # If a block is given, it will receive the IO output object. Otherwise the
53
- # output will be returned as a string.
54
- def compress(stream_or_string, options={})
55
- raise ArgumentError, 'Option :type required' unless options.key?(:type)
43
+ args
44
+ end
56
45
 
57
- stream = streamify(stream_or_string)
58
- output = StringIO.new
46
+ # Compresses the given +stream_or_string+ of code using the given +options+.
47
+ # When using this method directly, at least the +:type+ option must be
48
+ # specified, and should be one of <tt>"css"</tt> or <tt>"js"</tt>. See
49
+ # YUICompressor#compress_css and YUICompressor#compress_js for details about
50
+ # which options are acceptable for each type of compressor.
51
+ #
52
+ # If a block is given, it will receive the IO output object. Otherwise the
53
+ # output will be returned as a string.
54
+ def compress(stream_or_string, options={})
55
+ raise ArgumentError, 'Option :type required' unless options.key?(:type)
59
56
 
60
- reader = InputStreamReader.new(stream.to_inputstream)
61
- writer = OutputStreamWriter.new(output.to_outputstream)
57
+ stream = streamify(stream_or_string)
58
+ output = StringIO.new
62
59
 
63
- compressor = case options[:type].to_s
64
- when 'js'
65
- options = default_js_options.merge(options)
66
- JavaScriptCompressor.new(reader, ErrorReporter.new)
67
- when 'css'
68
- options = default_css_options.merge(options)
69
- CssCompressor.new(reader)
70
- else
71
- raise ArgumentError, 'Unknown resource type: %s' % options[:type]
72
- end
73
-
74
- compressor.compress(writer, *command_arguments(options))
75
- writer.flush
76
- output.rewind
60
+ reader = InputStreamReader.new(stream.to_inputstream)
61
+ writer = OutputStreamWriter.new(output.to_outputstream)
77
62
 
78
- if block_given?
79
- yield output
80
- else
81
- output.read
82
- end
63
+ compressor = case options[:type].to_s
64
+ when 'js'
65
+ options = default_js_options.merge(options)
66
+ JavaScriptCompressor.new(reader, ErrorReporter.new)
67
+ when 'css'
68
+ options = default_css_options.merge(options)
69
+ CssCompressor.new(reader)
70
+ else
71
+ raise ArgumentError, 'Unknown resource type: %s' % options[:type]
83
72
  end
84
73
 
74
+ compressor.compress(writer, *command_arguments(options))
75
+ writer.flush
76
+ output.rewind
77
+
78
+ if block_given?
79
+ yield output
80
+ else
81
+ output.read
82
+ end
85
83
  end
86
84
  end
@@ -5,78 +5,77 @@ rescue LoadError
5
5
  end
6
6
 
7
7
  module YUICompressor
8
- # This module contains methods that allow the YUI Compressor to be used by
8
+ # This file contains methods that allow the YUI Compressor to be used by
9
9
  # piping IO to a separate Java process via the system shell. It is used on all
10
10
  # Ruby platforms except for JRuby.
11
- module Shell
12
11
 
13
- # Returns an array of flags that should be passed to the jar file on the
14
- # command line for the given set of +options+.
15
- def command_arguments(options={})
16
- args = []
17
- args.concat(['--type', options[:type].to_s]) if options[:type]
18
- args.concat(['--line-break', options[:line_break].to_s]) if options[:line_break]
12
+ module_function
19
13
 
20
- if options[:type].to_s == 'js'
21
- args << '--nomunge' unless options[:munge]
22
- args << '--preserve-semi' if options[:preserve_semicolons]
23
- args << '--disable-optimizations' unless options[:optimize]
24
- end
14
+ # Returns an array of flags that should be passed to the jar file on the
15
+ # command line for the given set of +options+.
16
+ def command_arguments(options={})
17
+ args = []
18
+ args.concat(['--type', options[:type].to_s]) if options[:type]
19
+ args.concat(['--line-break', options[:line_break].to_s]) if options[:line_break]
25
20
 
26
- args
21
+ if options[:type].to_s == 'js'
22
+ args << '--nomunge' unless options[:munge]
23
+ args << '--preserve-semi' if options[:preserve_semicolons]
24
+ args << '--disable-optimizations' unless options[:optimize]
27
25
  end
28
26
 
29
- # Compresses the given +stream_or_string+ of code using the given +options+.
30
- # When using this method directly, at least the +:type+ option must be
31
- # specified, and should be one of <tt>"css"</tt> or <tt>"js"</tt>. See
32
- # YUICompressor#compress_css and YUICompressor#compress_js for details about
33
- # which options are acceptable for each type of compressor.
34
- #
35
- # In addition to the standard options, this method also accepts a
36
- # <tt>:java</tt> option that can be used to specify the location of the Java
37
- # binary. This option will default to using <tt>"java"</tt> unless otherwise
38
- # specified.
39
- #
40
- # If a block is given, it will receive the IO output object. Otherwise the
41
- # output will be returned as a string.
42
- def compress(stream_or_string, options={})
43
- raise ArgumentError, 'Option :type required' unless options.key?(:type)
27
+ args
28
+ end
44
29
 
45
- stream = streamify(stream_or_string)
30
+ # Compresses the given +stream_or_string+ of code using the given +options+.
31
+ # When using this method directly, at least the +:type+ option must be
32
+ # specified, and should be one of <tt>"css"</tt> or <tt>"js"</tt>. See
33
+ # YUICompressor#compress_css and YUICompressor#compress_js for details about
34
+ # which options are acceptable for each type of compressor.
35
+ #
36
+ # In addition to the standard options, this method also accepts a
37
+ # <tt>:java</tt> option that can be used to specify the location of the Java
38
+ # binary. This option will default to using <tt>"java"</tt> unless otherwise
39
+ # specified.
40
+ #
41
+ # If a block is given, it will receive the IO output object. Otherwise the
42
+ # output will be returned as a string.
43
+ def compress(stream_or_string, options={})
44
+ raise ArgumentError, 'Option :type required' unless options.key?(:type)
46
45
 
47
- case options[:type].to_s
48
- when 'js'
49
- options = default_js_options.merge(options)
50
- when 'css'
51
- options = default_css_options.merge(options)
52
- else
53
- raise ArgumentError, 'Unknown resource type: %s' % options[:type]
54
- end
46
+ stream = streamify(stream_or_string)
55
47
 
56
- command = [ options.delete(:java) || 'java', '-jar', JAR_FILE ]
57
- command.concat(command_arguments(options))
48
+ case options[:type].to_s
49
+ when 'js'
50
+ options = default_js_options.merge(options)
51
+ when 'css'
52
+ options = default_css_options.merge(options)
53
+ else
54
+ raise ArgumentError, 'Unknown resource type: %s' % options[:type]
55
+ end
58
56
 
59
- Open3.popen3(command.join(' ')) do |input, output, stderr|
60
- begin
61
- while buffer = stream.read(4096)
62
- input.write(buffer)
63
- end
57
+ command = [ options.delete(:java) || 'java', '-jar', JAR_FILE ]
58
+ command.concat(command_arguments(options))
64
59
 
65
- input.close
60
+ Open3.popen3(command.join(' ')) do |input, output, stderr|
61
+ begin
62
+ while buffer = stream.read(4096)
63
+ input.write(buffer)
64
+ end
65
+
66
+ input.close
66
67
 
67
- err = stderr.read
68
- raise err unless err.empty?
68
+ err = stderr.read
69
+ raise err unless err.empty?
69
70
 
70
- if block_given?
71
- yield output
72
- else
73
- output.read
74
- end
75
- rescue Exception => e
76
- raise RuntimeError, 'Compression failed. %s' % e
71
+ if block_given?
72
+ yield output
73
+ else
74
+ output.read
77
75
  end
76
+ rescue Exception => e
77
+ raise RuntimeError, 'Compression failed. %s' % e
78
78
  end
79
79
  end
80
-
81
80
  end
82
81
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'yuicompressor'
3
- s.version = '1.0.1'
4
- s.date = '2010-08-02'
3
+ s.version = '1.1.0'
4
+ s.date = '2010-08-04'
5
5
 
6
6
  s.summary = 'A YUI JavaScript and CSS compressor for Ruby and JRuby'
7
7
  s.description = 'A YUI JavaScript and CSS compressor for Ruby and JRuby'
metadata CHANGED
@@ -1,34 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yuicompressor
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
- - 1
7
- - 0
8
- - 1
9
- version: 1.0.1
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
10
11
  platform: ruby
11
12
  authors:
12
- - Michael Jackson
13
+ - Michael Jackson
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-02 00:00:00 -06:00
18
+ date: 2010-08-04 00:00:00 -06:00
18
19
  default_executable:
19
20
  dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rake
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :development
31
- version_requirements: *id001
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
32
35
  description: A YUI JavaScript and CSS compressor for Ruby and JRuby
33
36
  email: mjijackson@gmail.com
34
37
  executables: []
@@ -36,52 +39,56 @@ executables: []
36
39
  extensions: []
37
40
 
38
41
  extra_rdoc_files:
39
- - README
42
+ - README
40
43
  files:
41
- - lib/yuicompressor.rb
42
- - lib/yuicompressor/jruby.rb
43
- - lib/yuicompressor/shell.rb
44
- - test/css_test.rb
45
- - test/helper.rb
46
- - test/js_test.rb
47
- - yuicompressor.gemspec
48
- - Rakefile
49
- - README
44
+ - lib/yuicompressor/jruby.rb
45
+ - lib/yuicompressor/shell.rb
46
+ - lib/yuicompressor.rb
47
+ - test/css_test.rb
48
+ - test/helper.rb
49
+ - test/js_test.rb
50
+ - yuicompressor.gemspec
51
+ - Rakefile
52
+ - README
50
53
  has_rdoc: true
51
54
  homepage: http://github.com/mjijackson/yuicompressor
52
55
  licenses: []
53
56
 
54
57
  post_install_message:
55
58
  rdoc_options:
56
- - --line-numbers
57
- - --inline-source
58
- - --title
59
- - YUICompressor
60
- - --main
61
- - YUICompressor
59
+ - --line-numbers
60
+ - --inline-source
61
+ - --title
62
+ - YUICompressor
63
+ - --main
64
+ - YUICompressor
62
65
  require_paths:
63
- - lib
66
+ - lib
64
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
65
69
  requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- segments:
69
- - 0
70
- version: "0"
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
71
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
72
78
  requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- segments:
76
- - 0
77
- version: "0"
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
78
85
  requirements: []
79
86
 
80
87
  rubyforge_project:
81
- rubygems_version: 1.3.6
88
+ rubygems_version: 1.3.7
82
89
  signing_key:
83
90
  specification_version: 3
84
91
  summary: A YUI JavaScript and CSS compressor for Ruby and JRuby
85
92
  test_files:
86
- - test/css_test.rb
87
- - test/js_test.rb
93
+ - test/css_test.rb
94
+ - test/js_test.rb