public
Rubygem
Description: Blender is like ant or make for the front-end. It aggregates and compresses CSS and/or JavaScript assets for a site into efficient, production-ready files.
Homepage: http://front-end-architect.lighthouseapp.com/projects/11475-blender/overview
Clone URL: git://github.com/front-end/front-end-blender.git
Added minifier argument, current valid options are 'yui' and 'none'. [#28 
responsible:"Chris Griego" milestone:"1.1" state:resolved]
cgriego (author)
Mon Aug 11 09:15:29 -0700 2008
commit  12f37aa13d44deebe84fe4b3fac75780023f2931
tree    640305b19e35dbad0dc4b16188271ef5b5abd6c7
parent  cdc10f2fdca1516f878cce895558d672f46060c4
...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
 
 
 
 
 
 
 
 
 
 
 
27
28
29
...
13
14
15
 
 
 
 
 
 
 
 
 
 
 
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
0
@@ -13,17 +13,18 @@ require 'front_end_architect/blender'
0
 options = {}
0
 
0
 opts = OptionParser.new do |opts|
0
-  opts.on('-h',              '--help',                               "Show this message")                                               {    puts opts; exit 0                                     }
0
-  opts.on('-V',              '--version',                            "Show the version number")                                         {    puts "Front-End Blender v#{Blender::VERSION}"; exit 0 }
0
-  opts.on('-g',              '--generate',              String,      "Generate a stub Blendfile")                                       {    options[:generate]     = true                         }
0
-  opts.on('-f FILE',         '--file FILE',             String,      "Use given Blendfile")                                             {|f| options[:blendfile]    = f                            }
0
-  opts.on('-r ROOT',         '--root ROOT',             String,      "Set the path to the web root directory")                          {|r| options[:root]         = r                            }
0
-  opts.on('-t TYPE',         '--type TYPE',             [:css, :js], "Select file type to blend (css, js)")                             {|t| options[:file_type]    = t                            }
0
-  opts.on('-c [BUSTER]',     '--cache-buster [BUSTER]', String,      "Append cache busters to URLs in CSS, defaults to timestamps")     {|b| options[:cache_buster] = b.nil? ? :mtime : b          }
0
-  opts.on(                   '--force',                 String,      "Force blending when source files aren't newer than output files") {    options[:force]        = true                         }
0
-  opts.on(                   '--yui=YUIOPTS',           String,      "Pass arguments to YUI Compressor")                                {|o| options[:yuiopts]      = o                            }
0
-  opts.on('-d',              '--data',                  String,      "EXPERIMENTAL Convert url(file.ext) to url(data:) in CSS files")   {    options[:data]         = true                         }
0
-  opts.on('-z',              '--gzip',                  String,      "EXPERIMENTAL Also create gzip output files")                      {    options[:gzip]         = true                         }
0
+  opts.on('-h',              '--help',                                 "Show this message")                                               {    puts opts; exit 0                                     }
0
+  opts.on('-V',              '--version',                              "Show the version number")                                         {    puts "Front-End Blender v#{Blender::VERSION}"; exit 0 }
0
+  opts.on('-g',              '--generate',              String,        "Generate a stub Blendfile")                                       {    options[:generate]     = true                         }
0
+  opts.on('-f FILE',         '--file FILE',             String,        "Use given Blendfile")                                             {|f| options[:blendfile]    = f                            }
0
+  opts.on('-r ROOT',         '--root ROOT',             String,        "Set the path to the web root directory")                          {|r| options[:root]         = r                            }
0
+  opts.on('-t TYPE',         '--type TYPE',             [:css, :js],   "Select file type to blend (css, js)")                             {|t| options[:file_type]    = t                            }
0
+  opts.on('-m MINIFIER',     '--min MINIFIER',          [:yui, :none], "Select minifier to use (yui, none), default is YUI")              {|m| options[:min]          = m.to_sym                     }
0
+  opts.on('-c [BUSTER]',     '--cache-buster [BUSTER]', String,        "Append cache busters to URLs in CSS, defaults to timestamps")     {|b| options[:cache_buster] = b.nil? ? :mtime : b          }
0
+  opts.on(                   '--force',                 String,        "Force blending when source files aren't newer than output files") {    options[:force]        = true                         }
0
+  opts.on(                   '--yui=YUIOPTS',           String,        "Pass arguments to YUI Compressor")                                {|o| options[:yuiopts]      = o                            }
0
+  opts.on('-d',              '--data',                  String,        "EXPERIMENTAL Convert url(file.ext) to url(data:) in CSS files")   {    options[:data]         = true                         }
0
+  opts.on('-z',              '--gzip',                  String,        "EXPERIMENTAL Also create gzip output files")                      {    options[:gzip]         = true                         }
0
   
0
   opts.parse!(ARGV) rescue return false
0
 end
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 Gem::Specification.new do |s|
0
-  s.version            = '0.14'
0
+  s.version            = '0.15'
0
   s.date               = Time.now
0
   
0
   s.name               = 'blender'
...
20
21
22
23
 
24
25
26
...
31
32
33
 
34
35
36
...
179
180
181
182
183
184
185
186
187
188
 
 
189
190
191
192
 
 
 
193
194
195
196
197
198
199
200
201
202
203
 
 
 
 
 
204
205
206
207
 
 
 
208
209
210
211
 
 
 
 
 
 
 
 
 
 
 
 
 
212
 
 
213
214
215
...
20
21
22
 
23
24
25
26
...
31
32
33
34
35
36
37
...
180
181
182
 
 
 
 
 
 
 
183
184
185
 
 
 
186
187
188
189
 
 
 
 
 
 
 
 
 
 
190
191
192
193
194
195
196
197
 
198
199
200
201
202
 
 
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
0
@@ -20,7 +20,7 @@ require 'front_end_architect/hash'
0
 
0
 module FrontEndArchitect
0
   class Blender
0
-    VERSION      = '0.14'
0
+    VERSION      = '0.15'
0
     
0
     FILTER_REGEX = /filter: ?[^?]+\(src=(['"])([^\?'"]+)(\?(?:[^'"]+)?)?\1,[^?]+\1\);/im
0
     IMPORT_REGEX = /@import(?: url\(| )(['"]?)([^\?'"\)\s]+)(\?(?:[^'"\)]+)?)?\1\)?(?:[^?;]+)?;/im
0
@@ -31,6 +31,7 @@ module FrontEndArchitect
0
       :data      => false,
0
       :force     => false,
0
       :root      => File.dirname(:blendfile.to_s),
0
+      :min       => :yui,
0
     }
0
     
0
     def initialize(opts)
0
@@ -179,37 +180,42 @@ module FrontEndArchitect
0
         end
0
         
0
         # Compress
0
-        libdir = File.join(File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__), *%w[.. .. lib])
0
-        
0
-        IO.popen("java -jar #{libdir}/yui/yuicompressor.jar #{@options[:yuiopts]} --type #{type}", 'r+') do |io|
0
-          io.write output
0
-          io.close_write
0
-          
0
-          output = io.read
0
+        if @options[:min] == :yui
0
+          libdir = File.join(File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__), *%w[.. .. lib])
0
           
0
-          if File.extname(output_name) == '.css'
0
-            output.gsub! ' and(', ' and (' # Workaround for YUI Compressor Bug #1938329
0
-            output.gsub! '*/;}',  '*/}'    # Workaround for YUI Compressor Bug #1961175
0
+          IO.popen("java -jar #{libdir}/yui/yuicompressor.jar #{@options[:yuiopts]} --type #{type}", 'r+') do |io|
0
+            io.write output
0
+            io.close_write
0
             
0
-            if @options[:data]
0
-              output = output.gsub(URL_REGEX) do
0
-                unless $2.include?('.css')
0
-                  mime_type    = MIME::Types.type_for($2)
0
-                  url_contents = make_data_uri(IO.read($2), mime_type[0])
0
-                else
0
-                  url_contents = $2
0
-                end
0
-                  %Q!url(#{url_contents})!
0
-              end
0
+            output = io.read
0
+            
0
+            if File.extname(output_name) == '.css'
0
+              output.gsub! ' and(', ' and (' # Workaround for YUI Compressor Bug #1938329
0
+              output.gsub! '*/;}',  '*/}'    # Workaround for YUI Compressor Bug #1961175
0
             end
0
           end
0
           
0
-          output_file << output
0
+          if $? == 32512 # command not found
0
+            raise "\nBlender requires Java, v1.4 or greater, to be installed for YUI Compressor"
0
+          end
0
         end
0
         
0
-        if $? == 32512 # command not found
0
-          raise "\nBlender requires Java, v1.4 or greater, to be installed for YUI Compressor"
0
+        # Data
0
+        if @options[:data]
0
+          if File.extname(output_name) == '.css'
0
+            output = output.gsub(URL_REGEX) do
0
+              unless $2.include?('.css')
0
+                mime_type    = MIME::Types.type_for($2)
0
+                url_contents = make_data_uri(IO.read($2), mime_type[0])
0
+              else
0
+                url_contents = $2
0
+              end
0
+                %Q!url(#{url_contents})!
0
+            end
0
+          end
0
         end
0
+        
0
+        output_file << output
0
       end
0
       
0
       puts output_name

Comments