@@ -44,7 +44,7 @@ def precache_all(output_dir=nil, base_url=nil)
4444 if Jammit . embed_assets
4545 cache ( p , 'css' , pack_stylesheets ( p , :datauri ) , output_dir , :datauri )
4646 if Jammit . mhtml_enabled && base_url
47- mtime = Time . now
47+ mtime = latest_mtime package_for ( p , :css ) [ :paths ]
4848 asset_url = "#{ base_url } #{ Jammit . asset_url ( p , :css , :mhtml , mtime ) } "
4949 cache ( p , 'css' , pack_stylesheets ( p , :mhtml , asset_url ) , output_dir , :mhtml , mtime )
5050 end
@@ -55,9 +55,10 @@ def precache_all(output_dir=nil, base_url=nil)
5555 # Caches a single prebuilt asset package and gzips it at the highest
5656 # compression level. Ensures that the modification time of both both
5757 # variants is identical, for web server caching modules, as well as MHTML.
58- def cache ( package , extension , contents , output_dir , suffix = nil , mtime = Time . now )
58+ def cache ( package , extension , contents , output_dir , suffix = nil , mtime = nil )
5959 FileUtils . mkdir_p ( output_dir ) unless File . exists? ( output_dir )
6060 raise OutputNotWritable , "Jammit doesn't have permission to write to \" #{ output_dir } \" " unless File . writable? ( output_dir )
61+ mtime ||= latest_mtime package_for ( package , extension . to_sym ) [ :paths ]
6162 files = [ ]
6263 files << file_name = File . join ( output_dir , Jammit . filename ( package , extension , suffix ) )
6364 File . open ( file_name , 'wb+' ) { |f | f . write ( contents ) }
@@ -105,6 +106,12 @@ def glob_files(glob)
105106 Jammit . warn ( "No assets match '#{ glob } '" ) if paths . empty?
106107 paths
107108 end
109+
110+ # Get the latest mtime of a list of files (plus the config path).
111+ def latest_mtime ( paths )
112+ paths += [ Jammit . config_path ]
113+ paths . map { |p | File . mtime ( p ) } . max || Time . now
114+ end
108115
109116 # Return a list of all of the packages that should be cached. If "force" is
110117 # true, this is all of them -- otherwise only the packages that are missing
0 commit comments