ruby-yui 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ruby-yui/yui.rb +36 -24
- data/spec/unit/yui_spec.rb +13 -2
- metadata +2 -2
data/lib/ruby-yui/yui.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# Auto-generated ruby debug require
|
2
|
+
require "ruby-debug"
|
3
|
+
Debugger.start
|
4
|
+
Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
|
1
5
|
# TODO md5 checksum the compressed files for spec testing to verify they were compressed correctly.
|
2
6
|
# TODO output yui.checksums.txt "#{OUT_PATH}\t#{CHECKSUM}\n"
|
3
7
|
|
@@ -11,7 +15,7 @@ class Yui
|
|
11
15
|
|
12
16
|
MAJOR = 0
|
13
17
|
MINOR = 0
|
14
|
-
RELEASE =
|
18
|
+
RELEASE = 5
|
15
19
|
def Yui.version
|
16
20
|
[MAJOR,MINOR,RELEASE].join('.')
|
17
21
|
end
|
@@ -67,9 +71,7 @@ class Yui
|
|
67
71
|
# Returns path to bundle if successful, otherwise nil
|
68
72
|
#
|
69
73
|
def bundle
|
70
|
-
if @files.empty?
|
71
|
-
raise NoInputFileException, "Nothing to do, check input path."
|
72
|
-
end
|
74
|
+
raise(NoInputFileException, "Nothing to do, check input path.")if @files.empty?
|
73
75
|
|
74
76
|
bundle_data = ""
|
75
77
|
successful_compressions = 0
|
@@ -91,7 +93,7 @@ class Yui
|
|
91
93
|
if @options[:suffix].empty?
|
92
94
|
bundle_file_name = "bundle.#{@options[:type]}"
|
93
95
|
else
|
94
|
-
bundle_file_name = "bundle
|
96
|
+
bundle_file_name = "bundle#{@options[:suffix]}.#{@options[:type]}"
|
95
97
|
end
|
96
98
|
bundle_path = File.join(outpath,bundle_file_name)
|
97
99
|
File.open(bundle_path,'w'){|f| f.write(bundle_data)}
|
@@ -102,33 +104,44 @@ class Yui
|
|
102
104
|
end
|
103
105
|
|
104
106
|
def minify
|
105
|
-
if @files.empty?
|
106
|
-
raise NoInputFileException, "Nothing to do, check input path."
|
107
|
-
end
|
107
|
+
raise(NoInputFileException, "Nothing to do, check input path.") if @files.empty?
|
108
108
|
|
109
109
|
successful_compressions = 0
|
110
110
|
|
111
111
|
@files.each do |file|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
112
|
+
#put the suffix on before the externsion if provided
|
113
|
+
if @options[:suffix].empty?
|
114
|
+
out_file = file.clone
|
115
|
+
else
|
116
|
+
out_file = file.split('.')
|
117
|
+
out_file.pop #pop off extension
|
118
|
+
out_file = out_file.join('.') << @options[:suffix] << ".#{@options[:type]}"
|
119
|
+
end
|
117
120
|
|
118
|
-
|
121
|
+
#Substitute the outpath
|
122
|
+
out_file.sub!(@inpath,outpath)
|
119
123
|
|
120
|
-
cmd = Yui.gen_cmd(file,@options)
|
121
|
-
cmd << "-o #{out_file}"
|
124
|
+
cmd = Yui.gen_cmd(file,@options) << "-o #{out_file}"
|
122
125
|
|
123
126
|
FileUtils.mkdir_p File.dirname(out_file)
|
124
127
|
|
125
128
|
puts "Compressing:\n\t #{file} =>\n\t #{out_file}"
|
126
129
|
stdin, stdout, stderr = popen3(cmd.join(' '))
|
127
130
|
|
128
|
-
|
131
|
+
stdout = stdout.read
|
132
|
+
stderr = stderr.read
|
133
|
+
|
134
|
+
if stdout.empty? && stderr.empty?
|
129
135
|
successful_compressions += 1
|
130
136
|
else
|
131
137
|
puts "Failed to compress: #{file}"
|
138
|
+
if @options[:rename_on_fail] && !@options[:suffix].empty?
|
139
|
+
puts "Copying:\n\t #{file} =>\n\t #{out_file}"
|
140
|
+
FileUtils.cp file, out_file
|
141
|
+
end
|
142
|
+
|
143
|
+
puts "OUT: #{stdout}"
|
144
|
+
puts "ERR: #{stderr}"
|
132
145
|
end
|
133
146
|
end
|
134
147
|
|
@@ -141,11 +154,10 @@ class Yui
|
|
141
154
|
if suffix.empty?
|
142
155
|
glob_path = File.join(path,"**.#{type}")
|
143
156
|
else
|
144
|
-
glob_path = File.join(path,"**","
|
157
|
+
glob_path = File.join(path,"**","*#{suffix}.#{type}")
|
145
158
|
end
|
146
159
|
|
147
|
-
|
148
|
-
files.each do |file|
|
160
|
+
Dir.glob(glob_path).each do |file|
|
149
161
|
puts "Clobbering #{file}..."
|
150
162
|
FileUtils.rm file
|
151
163
|
end
|
@@ -157,8 +169,7 @@ class Yui
|
|
157
169
|
# Was 100% of files compressed
|
158
170
|
#
|
159
171
|
def Yui.compress(inpath,options={})
|
160
|
-
|
161
|
-
_yui_obj.minify
|
172
|
+
Yui.new(inpath,options).minify
|
162
173
|
end
|
163
174
|
|
164
175
|
protected
|
@@ -178,14 +189,15 @@ class Yui
|
|
178
189
|
:clobber => false,
|
179
190
|
:java_cli => "java -jar",
|
180
191
|
:yui_jar => File.join(YUI_ROOT,"ext","yuicompressor-2.4.2.jar"),
|
181
|
-
:suffix => "yui-min",
|
192
|
+
:suffix => ".yui-min",
|
182
193
|
:out_path => nil, #file_path.sub(inpath,outpath)
|
183
194
|
:type => :js,
|
184
195
|
:charset => nil,
|
185
196
|
:preserve_semi => false,
|
186
197
|
:disable_opt => false,
|
187
198
|
:nomunge => false,
|
188
|
-
:stomp => false #destroys originls if NO suffix and NO out_path
|
199
|
+
:stomp => false, #destroys originls if NO suffix and NO out_path
|
200
|
+
:rename_on_fail => false #If failed to compress and suffix given, original file will be renamed still
|
189
201
|
}
|
190
202
|
end
|
191
203
|
end
|
data/spec/unit/yui_spec.rb
CHANGED
@@ -57,10 +57,21 @@ describe Yui do
|
|
57
57
|
}.should raise_error(Exception)
|
58
58
|
end
|
59
59
|
|
60
|
+
it 'should be able to specify an alternate out path' do
|
61
|
+
yui = Yui.new "./test/data/javascripts", :out_path => "./test/data/alt_out_path/javascripts"
|
62
|
+
yui.minify
|
63
|
+
|
64
|
+
File.exist?("./test/data/alt_out_path/javascripts/prototype.yui-min.js").should be(true)
|
65
|
+
File.exist?("./test/data/alt_out_path/javascripts/jquery-1.2.6.yui-min.js").should be(true)
|
66
|
+
|
67
|
+
FileUtils.rm "./test/data/alt_out_path/javascripts/prototype.yui-min.js"
|
68
|
+
FileUtils.rm "./test/data/alt_out_path/javascripts/jquery-1.2.6.yui-min.js"
|
69
|
+
end
|
70
|
+
|
60
71
|
it 'should have an identical file name (optionally path) if no suffix is supplied' do
|
61
72
|
yui = Yui.new "./test/data/javascripts", :suffix => nil, :out_path => "./test/data/alt_out_path/javascripts"
|
62
73
|
yui.minify
|
63
|
-
|
74
|
+
|
64
75
|
File.exist?("./test/data/alt_out_path/javascripts/prototype.js").should be(true)
|
65
76
|
File.exist?("./test/data/alt_out_path/javascripts/jquery-1.2.6.js").should be(true)
|
66
77
|
|
@@ -76,7 +87,7 @@ describe Yui do
|
|
76
87
|
|
77
88
|
pre_md5.should_not == post_md5
|
78
89
|
|
79
|
-
#restore backups
|
90
|
+
#restore backups after testing...
|
80
91
|
FileUtils.cp "./test/data/backups/stompable.js", "./test/data/stompers/stompable.js"
|
81
92
|
|
82
93
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-yui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cory O'Daniel
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-25 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|