@@ -10,7 +10,7 @@ module Jammit
1010
1111 ASSET_ROOT = File . expand_path ( ( defined? ( Rails ) && Rails . root . to_s . length > 0 ) ? Rails . root : ENV [ 'RAILS_ROOT' ] || "." ) unless defined? ( ASSET_ROOT )
1212
13- PUBLIC_ROOT = ( defined? ( Rails ) && Rails . public_path . to_s . length > 0 ) ? Rails . public_path : File . join ( ASSET_ROOT , 'public' ) unless defined? ( PUBLIC_ROOT )
13+ DEFAULT_PUBLIC_ROOT = ( defined? ( Rails ) && Rails . public_path . to_s . length > 0 ) ? Rails . public_path : File . join ( ASSET_ROOT , 'public' ) unless defined? ( PUBLIC_ROOT )
1414
1515 DEFAULT_CONFIG_PATH = File . join ( ASSET_ROOT , 'config' , 'assets.yml' )
1616
@@ -51,12 +51,14 @@ class << self
5151 :embed_assets , :package_assets , :compress_assets , :gzip_assets ,
5252 :package_path , :mhtml_enabled , :include_jst_script , :config_path ,
5353 :javascript_compressor , :compressor_options , :css_compressor_options ,
54- :template_extension , :template_extension_matcher , :allow_debugging
54+ :template_extension , :template_extension_matcher , :allow_debugging ,
55+ :public_root
5556 attr_accessor :compressors
5657 end
5758
5859 # The minimal required configuration.
5960 @configuration = { }
61+ @public_root = DEFAULT_PUBLIC_ROOT
6062 @package_path = DEFAULT_PACKAGE_PATH
6163 @compressors = COMPRESSORS
6264
@@ -87,6 +89,7 @@ def self.load_configuration(config_path, soft=false)
8789 set_template_function ( conf [ :template_function ] )
8890 set_template_namespace ( conf [ :template_namespace ] )
8991 set_template_extension ( conf [ :template_extension ] )
92+ set_public_root ( conf [ :public_root ] ) if conf [ :public_root ]
9093 symbolize_keys ( conf [ :stylesheets ] ) if conf [ :stylesheets ]
9194 symbolize_keys ( conf [ :javascripts ] ) if conf [ :javascripts ]
9295 check_for_deprecations
@@ -124,16 +127,24 @@ def self.package!(options={})
124127 :config_path => Jammit ::DEFAULT_CONFIG_PATH ,
125128 :output_folder => nil ,
126129 :base_url => nil ,
130+ :public_root => nil ,
127131 :force => false
128132 } . merge ( options )
129133 load_configuration ( options [ :config_path ] )
134+ set_public_root ( options [ :public_root ] ) if options [ :public_root ]
130135 packager . force = options [ :force ]
131136 packager . package_names = options [ :package_names ]
132137 packager . precache_all ( options [ :output_folder ] , options [ :base_url ] )
133138 end
134139
135140 private
136141
142+ # Allows command-line definition of `PUBLIC_ROOT`, for those using Jammit
143+ # outside of Rails.
144+ def self . set_public_root ( public_root = nil )
145+ @public_root = public_root if public_root
146+ end
147+
137148 # Ensure that the JavaScript compressor is a valid choice.
138149 def self . set_javascript_compressor ( value )
139150 value = value && value . to_sym
0 commit comments