Skip to content

Commit eb71ba6

Browse files
committed
fix nasty-ish bug where JS would always be recompiled, regardless.
1 parent e70e0aa commit eb71ba6

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

lib/jammit/packager.rb

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ module Jammit
66
# with the correct timestamps.
77
class Packager
88

9+
# In Rails, the difference between a path and an asset URL is "public".
10+
PATH_DIFF = PUBLIC_ROOT.sub(ASSET_ROOT, '')
11+
PATH_TO_URL = /\A#{Regexp.escape(ASSET_ROOT)}(\/?#{Regexp.escape(PATH_DIFF)})?/
912

1013
# Set force to false to allow packages to only be rebuilt when their source
1114
# files have changed since the last time their package was built.
@@ -15,10 +18,6 @@ class Packager
1518
# Jammit.configuration. When assets.yml is being changed on the fly,
1619
# create a new Packager.
1720
def initialize
18-
# In Rails, the difference between a path and an asset URL is "public".
19-
@path_diff = Jammit.public_root.sub(ASSET_ROOT, '')
20-
@path_to_url = /\A#{Regexp.escape(ASSET_ROOT)}(\/?#{Regexp.escape(@path_diff)})?/
21-
2221
@compressor = Compressor.new
2322
@force = false
2423
@package_names = nil
@@ -38,7 +37,7 @@ def initialize
3837
# Unless forced, will only rebuild assets whose source files have been
3938
# changed since their last package build.
4039
def precache_all(output_dir=nil, base_url=nil)
41-
output_dir ||= File.join(Jammit.public_root, Jammit.package_path)
40+
output_dir ||= File.join(PUBLIC_ROOT, Jammit.package_path)
4241
cacheable(:js, output_dir).each {|p| cache(p, 'js', pack_javascripts(p), output_dir) }
4342
cacheable(:css, output_dir).each do |p|
4443
cache(p, 'css', pack_stylesheets(p), output_dir)
@@ -126,8 +125,10 @@ def cacheable(extension, output_dir)
126125
return names.select do |name|
127126
pack = package_for(name, extension)
128127
cached = [Jammit.filename(name, extension)]
129-
cached.push Jammit.filename(name, extension, :datauri) if Jammit.embed_assets
130-
cached.push Jammit.filename(name, extension, :mhtml) if Jammit.mhtml_enabled
128+
if extension == :css
129+
cached.push Jammit.filename(name, extension, :datauri) if Jammit.embed_assets
130+
cached.push Jammit.filename(name, extension, :mhtml) if Jammit.mhtml_enabled
131+
end
131132
cached.map! {|file| File.join(output_dir, file) }
132133
if cached.any? {|file| !File.exists?(file) }
133134
true
@@ -154,10 +155,10 @@ def create_packages(config)
154155
paths = globs.flatten.uniq.map {|glob| glob_files(glob) }.flatten.uniq
155156
packages[name][:paths] = paths
156157
if !paths.grep(Jammit.template_extension_matcher).empty?
157-
packages[name][:urls] = paths.grep(JS_EXTENSION).map {|path| path.sub(@path_to_url, '') }
158+
packages[name][:urls] = paths.grep(JS_EXTENSION).map {|path| path.sub(PATH_TO_URL, '') }
158159
packages[name][:urls] += [Jammit.asset_url(name, Jammit.template_extension)]
159160
else
160-
packages[name][:urls] = paths.map {|path| path.sub(@path_to_url, '') }
161+
packages[name][:urls] = paths.map {|path| path.sub(PATH_TO_URL, '') }
161162
end
162163
end
163164
packages

0 commit comments

Comments
 (0)