@@ -6,10 +6,6 @@ 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 ) } )?/
12-
139 # Set force to false to allow packages to only be rebuilt when their source
1410 # files have changed since the last time their package was built.
1511 attr_accessor :force , :package_names
@@ -37,7 +33,7 @@ def initialize
3733 # Unless forced, will only rebuild assets whose source files have been
3834 # changed since their last package build.
3935 def precache_all ( output_dir = nil , base_url = nil )
40- output_dir ||= File . join ( PUBLIC_ROOT , Jammit . package_path )
36+ output_dir ||= File . join ( Jammit . public_root , Jammit . package_path )
4137 cacheable ( :js , output_dir ) . each { |p | cache ( p , 'js' , pack_javascripts ( p ) , output_dir ) }
4238 cacheable ( :css , output_dir ) . each do |p |
4339 cache ( p , 'css' , pack_stylesheets ( p ) , output_dir )
@@ -89,6 +85,7 @@ def pack_javascripts(package)
8985 def pack_templates ( package )
9086 @compressor . compile_jst ( package_for ( package , :js ) [ :paths ] )
9187 end
88+
9289
9390 private
9491
@@ -107,6 +104,11 @@ def glob_files(glob)
107104 Jammit . warn ( "No assets match '#{ glob } '" ) if paths . empty?
108105 paths
109106 end
107+
108+ # In Rails, the difference between a path and an asset URL is "public".
109+ def path_to_url
110+ @path_to_url ||= /\A #{ Regexp . escape ( ASSET_ROOT ) } (\/ ?#{ Regexp . escape ( Jammit . public_root . sub ( ASSET_ROOT , '' ) ) } )?/
111+ end
110112
111113 # Get the latest mtime of a list of files (plus the config path).
112114 def latest_mtime ( paths )
@@ -155,10 +157,10 @@ def create_packages(config)
155157 paths = globs . flatten . uniq . map { |glob | glob_files ( glob ) } . flatten . uniq
156158 packages [ name ] [ :paths ] = paths
157159 if !paths . grep ( Jammit . template_extension_matcher ) . empty?
158- packages [ name ] [ :urls ] = paths . grep ( JS_EXTENSION ) . map { |path | path . sub ( PATH_TO_URL , '' ) }
160+ packages [ name ] [ :urls ] = paths . grep ( JS_EXTENSION ) . map { |path | path . sub ( path_to_url , '' ) }
159161 packages [ name ] [ :urls ] += [ Jammit . asset_url ( name , Jammit . template_extension ) ]
160162 else
161- packages [ name ] [ :urls ] = paths . map { |path | path . sub ( PATH_TO_URL , '' ) }
163+ packages [ name ] [ :urls ] = paths . map { |path | path . sub ( path_to_url , '' ) }
162164 end
163165 end
164166 packages
0 commit comments