lib/jammit/packager.rb in jammit-0.2.4 vs lib/jammit/packager.rb in jammit-0.2.5
- old
+ new
@@ -5,11 +5,11 @@
# contents of an asset package, the Packager knows how to cache that package
# with the correct timestamps.
class Packager
# In Rails, the difference between a path and an asset URL is "public".
- PATH_TO_URL = /\A\/?public/
+ PATH_TO_URL = /\A#{ASSET_ROOT}(\/public)?/
# Creating a new Packager will rebuild the list of assets from the
# Jammit.configuration. When assets.yml is being changed on the fly,
# create a new Packager.
def initialize
@@ -86,18 +86,24 @@
def package_for(package, extension)
pack = @packages[extension] && @packages[extension][package]
pack || not_found(package, extension)
end
+ # Absolute globs are absolute -- relative globs are relative to ASSET_ROOT.
+ def glob_files(glob)
+ absolute = Pathname.new(glob).absolute?
+ Dir[absolute ? glob : File.join(ASSET_ROOT, glob)]
+ end
+
# Compiles the list of assets that goes into each package. Runs an ordered
# list of Dir.globs, taking the merged unique result.
def create_packages(config)
packages = {}
return packages if !config
config.each do |name, globs|
globs ||= []
packages[name] = {}
- paths = globs.map {|glob| Dir[glob] }.flatten.uniq
+ paths = globs.map {|glob| glob_files(glob) }.flatten.uniq
packages[name][:paths] = paths
packages[name][:urls] = paths.map {|path| path.sub(PATH_TO_URL, '') }
end
packages
end
\ No newline at end of file