juicer 0.2.3 → 0.2.4
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.
- data/History.txt +8 -0
 - data/Rakefile +1 -0
 - data/lib/juicer.rb +1 -1
 - data/lib/juicer/command/merge.rb +4 -2
 - data/lib/juicer/core.rb +4 -2
 - data/lib/juicer/css_cache_buster.rb +11 -7
 - data/lib/juicer/jslint.rb +1 -1
 - data/test/juicer/test_css_cache_buster.rb +9 -0
 - metadata +2 -2
 
    
        data/History.txt
    CHANGED
    
    | 
         @@ -1,3 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            == 0.2.4 / 2009-04-29
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            * More robust pattern checking for url() references in CSS files
         
     | 
| 
      
 4 
     | 
    
         
            +
            * Allow skipping verification
         
     | 
| 
      
 5 
     | 
    
         
            +
            * Bug fix: Skip cache buster if type=none
         
     | 
| 
      
 6 
     | 
    
         
            +
            * Bug fix: Quote JsLint command parts to allow for spaces in jar file paths
         
     | 
| 
      
 7 
     | 
    
         
            +
            * Bug fix: cache buster type wasn't carried all the way (ie had no effect)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
       1 
9 
     | 
    
         
             
            == 0.2.3 / 2009-03-03
         
     | 
| 
       2 
10 
     | 
    
         | 
| 
       3 
11 
     | 
    
         
             
            * Cache busters in CSS files should only be appended once to each URL
         
     | 
    
        data/Rakefile
    CHANGED
    
    
    
        data/lib/juicer.rb
    CHANGED
    
    
    
        data/lib/juicer/command/merge.rb
    CHANGED
    
    | 
         @@ -29,6 +29,7 @@ module Juicer 
     | 
|
| 
       29 
29 
     | 
    
         
             
                    @relative_urls = false          # Make the merger use relative URLs
         
     | 
| 
       30 
30 
     | 
    
         
             
                    @absolute_urls = false          # Make the merger use absolute URLs
         
     | 
| 
       31 
31 
     | 
    
         
             
                    @local_hosts = []               # Host names that are served from :web_root
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @verify = true                  # Verify js files with JsLint
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
34 
     | 
    
         
             
                    @log = log || Logger.new(STDOUT)
         
     | 
| 
       34 
35 
     | 
    
         | 
| 
         @@ -57,6 +58,7 @@ the YUI Compressor the path should be the path to where the jar file is found. 
     | 
|
| 
       57 
58 
     | 
    
         
             
                      opt.on("-f", "--force", "Force overwrite of target file") { @force = true }
         
     | 
| 
       58 
59 
     | 
    
         
             
                      opt.on("-a", "--arguments arguments", "Arguments to minifyer, escape with quotes") { |arguments| @arguments = arguments }
         
     | 
| 
       59 
60 
     | 
    
         
             
                      opt.on("-i", "--ignore-problems", "Merge and minify even if verifyer finds problems") { @ignore = true }
         
     | 
| 
      
 61 
     | 
    
         
            +
                      opt.on("-s", "--skip-verification", "Skip JsLint verification (js files only). Not recomended!") { @verify = false }
         
     | 
| 
       60 
62 
     | 
    
         
             
                      opt.on("-t", "--type type", "Juicer can only guess type when files have .css or .js extensions. Specify js or\n" +
         
     | 
| 
       61 
63 
     | 
    
         
             
                                       (" " * 37) + "css with this option in cases where files have other extensions.") { |type| @type = type.to_sym }
         
     | 
| 
       62 
64 
     | 
    
         
             
                      opt.on("-h", "--hosts hosts", "Cycle asset hosts for referenced urls. Comma separated") { |hosts| @hosts = hosts.split(",") }
         
     | 
| 
         @@ -103,7 +105,7 @@ the YUI Compressor the path should be the path to where the jar file is found. 
     | 
|
| 
       103 
105 
     | 
    
         
             
                                                       :hosts => @hosts)
         
     | 
| 
       104 
106 
     | 
    
         | 
| 
       105 
107 
     | 
    
         
             
                    # Fail if syntax trouble (js only)
         
     | 
| 
       106 
     | 
    
         
            -
                    if !Juicer::Command::Verify.check_all(merger.files.reject { |f| f =~ /\.css$/ }, @log)
         
     | 
| 
      
 108 
     | 
    
         
            +
                    if @verify && !Juicer::Command::Verify.check_all(merger.files.reject { |f| f =~ /\.css$/ }, @log)
         
     | 
| 
       107 
109 
     | 
    
         
             
                      @log.error "Problems were detected during verification"
         
     | 
| 
       108 
110 
     | 
    
         
             
                      raise SystemExit.new("Input files contain problems") unless @ignore
         
     | 
| 
       109 
111 
     | 
    
         
             
                      @log.warn "Ignoring detected problems"
         
     | 
| 
         @@ -169,7 +171,7 @@ the YUI Compressor the path should be the path to where the jar file is found. 
     | 
|
| 
       169 
171 
     | 
    
         
             
                  # Load cache buster, only available for CSS files
         
     | 
| 
       170 
172 
     | 
    
         
             
                  #
         
     | 
| 
       171 
173 
     | 
    
         
             
                  def cache_buster(file)
         
     | 
| 
       172 
     | 
    
         
            -
                    return nil if !file || file !~ /\.css$/
         
     | 
| 
      
 174 
     | 
    
         
            +
                    return nil if !file || file !~ /\.css$/ || @cache_buster.nil?
         
     | 
| 
       173 
175 
     | 
    
         
             
                    Juicer::CssCacheBuster.new(:web_root => @web_root, :type => @cache_buster, :hosts => @local_hosts)
         
     | 
| 
       174 
176 
     | 
    
         
             
                  end
         
     | 
| 
       175 
177 
     | 
    
         | 
    
        data/lib/juicer/core.rb
    CHANGED
    
    | 
         @@ -31,8 +31,10 @@ class String 
     | 
|
| 
       31 
31 
     | 
    
         
             
              #
         
     | 
| 
       32 
32 
     | 
    
         
             
              # Turn a camelcase string into underscore string
         
     | 
| 
       33 
33 
     | 
    
         
             
              #
         
     | 
| 
       34 
     | 
    
         
            -
               
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
      
 34 
     | 
    
         
            +
              unless String.method_defined?(:underscore)
         
     | 
| 
      
 35 
     | 
    
         
            +
                def underscore
         
     | 
| 
      
 36 
     | 
    
         
            +
                  self.split(/([A-Z][^A-Z]*)/).find_all { |str| str != "" }.join("_").downcase
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
       36 
38 
     | 
    
         
             
              end
         
     | 
| 
       37 
39 
     | 
    
         
             
            end
         
     | 
| 
       38 
40 
     | 
    
         | 
| 
         @@ -39,13 +39,17 @@ module Juicer 
     | 
|
| 
       39 
39 
     | 
    
         
             
                  used = []
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                  urls(file).each do |url|
         
     | 
| 
       42 
     | 
    
         
            -
                     
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 43 
     | 
    
         
            +
                      path = resolve(url, file)
         
     | 
| 
      
 44 
     | 
    
         
            +
                      next if used.include?(path)
         
     | 
| 
       44 
45 
     | 
    
         | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
                      if path != url
         
     | 
| 
      
 47 
     | 
    
         
            +
                        used << path
         
     | 
| 
      
 48 
     | 
    
         
            +
                        basename = File.basename(Juicer::CacheBuster.path(path, @type))
         
     | 
| 
      
 49 
     | 
    
         
            +
                        @contents.gsub!(url, File.join(File.dirname(url), basename))
         
     | 
| 
      
 50 
     | 
    
         
            +
                      end
         
     | 
| 
      
 51 
     | 
    
         
            +
                    rescue Errno::ENOENT
         
     | 
| 
      
 52 
     | 
    
         
            +
                      puts "Unable to locate file #{path || url}, skipping"
         
     | 
| 
       49 
53 
     | 
    
         
             
                    end
         
     | 
| 
       50 
54 
     | 
    
         
             
                  end
         
     | 
| 
       51 
55 
     | 
    
         | 
| 
         @@ -62,7 +66,7 @@ module Juicer 
     | 
|
| 
       62 
66 
     | 
    
         
             
                def urls(file)
         
     | 
| 
       63 
67 
     | 
    
         
             
                  @contents = File.read(file) unless @contents
         
     | 
| 
       64 
68 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
                  @contents.scan(/url\(([^\)]*)\)/m).collect do |match|
         
     | 
| 
      
 69 
     | 
    
         
            +
                  @contents.scan(/url\([\s"']*([^\)"'\s]*)[\s"']*\)/m).collect do |match|
         
     | 
| 
       66 
70 
     | 
    
         
             
                    match.first
         
     | 
| 
       67 
71 
     | 
    
         
             
                  end
         
     | 
| 
       68 
72 
     | 
    
         
             
                end
         
     | 
    
        data/lib/juicer/jslint.rb
    CHANGED
    
    | 
         @@ -32,7 +32,7 @@ module Juicer 
     | 
|
| 
       32 
32 
     | 
    
         
             
                  raise FileNotFoundError.new("Unable to locate JsLint '#{js_file}'") if !js_file || !File.exists?(js_file)
         
     | 
| 
       33 
33 
     | 
    
         
             
                  raise FileNotFoundError.new("Unable to locate input file '#{file}'") unless File.exists?(file)
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
                  lines = execute(%Q{-jar #{rhino} #{locate_lib} "#{file}"}).split("\n")
         
     | 
| 
      
 35 
     | 
    
         
            +
                  lines = execute(%Q{-jar "#{rhino}" "#{locate_lib}" "#{file}"}).split("\n")
         
     | 
| 
       36 
36 
     | 
    
         
             
                  return Report.new if lines.length == 1 && lines[0] =~ /jslint: No problems/
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
                  report = Report.new
         
     | 
| 
         @@ -79,4 +79,13 @@ class TestCssCacheBuster < Test::Unit::TestCase 
     | 
|
| 
       79 
79 
     | 
    
         | 
| 
       80 
80 
     | 
    
         
             
                buster.urls(output).each { |url| assert url !~ /(jcb=\d+).*(jcb=\d+)/, url }
         
     | 
| 
       81 
81 
     | 
    
         
             
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
              def test_type_hard_should_produce_hard_buster_urls
         
     | 
| 
      
 84 
     | 
    
         
            +
                File.open(path("a2.css"), "w") { |f| f.puts "" }
         
     | 
| 
      
 85 
     | 
    
         
            +
                file = path("path_test2.css")
         
     | 
| 
      
 86 
     | 
    
         
            +
                output = path("path_test3.css")
         
     | 
| 
      
 87 
     | 
    
         
            +
                buster = Juicer::CssCacheBuster.new :web_root => path(""), :type => :hard
         
     | 
| 
      
 88 
     | 
    
         
            +
                buster.save file, output
         
     | 
| 
      
 89 
     | 
    
         
            +
                buster.urls(output).each { |url| assert url =~ /-\d+\.[a-z]{3}/, url }
         
     | 
| 
      
 90 
     | 
    
         
            +
              end
         
     | 
| 
       82 
91 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: juicer
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Christian Johansen
         
     | 
| 
         @@ -9,7 +9,7 @@ autorequire: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            date: 2009- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2009-05-04 00:00:00 +02:00
         
     | 
| 
       13 
13 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     |