juicer 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -15,6 +15,7 @@ end
15
15
 
16
16
  ensure_in_path 'lib'
17
17
  require 'juicer'
18
+ load 'tasks/test/setup.rake'
18
19
 
19
20
  task :default => 'test:run'
20
21
 
@@ -3,7 +3,7 @@ require "logger"
3
3
  module Juicer
4
4
 
5
5
  # :stopdoc:
6
- VERSION = '0.2.3'
6
+ VERSION = '0.2.4'
7
7
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
8
8
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
9
9
  LOGGER = Logger.new(STDOUT)
@@ -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
 
@@ -31,8 +31,10 @@ class String
31
31
  #
32
32
  # Turn a camelcase string into underscore string
33
33
  #
34
- def underscore
35
- self.split(/([A-Z][^A-Z]*)/).find_all { |str| str != "" }.join("_").downcase
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
- path = resolve(url, file)
43
- next if used.include?(path)
42
+ begin
43
+ path = resolve(url, file)
44
+ next if used.include?(path)
44
45
 
45
- if path != url
46
- used << path
47
- basename = File.basename(Juicer::CacheBuster.path(path))
48
- @contents.sub!(url, File.join(File.dirname(url), basename))
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
@@ -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.3
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-03-01 00:00:00 +01:00
12
+ date: 2009-05-04 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency