44# to all of the configuration options.
55module Jammit
66
7- VERSION = "0.6.3 "
7+ VERSION = "0.6.5 "
88
99 ROOT = File . expand_path ( File . dirname ( __FILE__ ) + '/..' )
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
@@ -26,8 +26,6 @@ module Jammit
2626
2727 DEFAULT_COMPRESSOR = :yui
2828
29- RAILS_ENV = ( defined? ( Rails ) ? Rails . env : ENV [ 'RAILS_ENV' ] || "development" )
30-
3129 # Extension matchers for JavaScript and JST, which need to be disambiguated.
3230 JS_EXTENSION = /\. js\Z /
3331 DEFAULT_JST_EXTENSION = "jst"
@@ -37,7 +35,7 @@ module Jammit
3735 class PackageNotFound < NameError ; end
3836
3937 # Jammit raises a MissingConfiguration exception when you try to load the
40- # configuration of an assets.yml file that doesn't exist, or are missing
38+ # configuration of an assets.yml file that doesn't exist, or are missing
4139 # a piece of required configuration.
4240 class MissingConfiguration < NameError ; end
4341
@@ -54,12 +52,13 @@ class << self
5452 :package_path , :mhtml_enabled , :include_jst_script , :config_path ,
5553 :javascript_compressor , :compressor_options , :css_compressor_options ,
5654 :template_extension , :template_extension_matcher , :allow_debugging ,
57- :rewrite_relative_paths
55+ :rewrite_relative_paths , :public_root
5856 attr_accessor :compressors
5957 end
6058
6159 # The minimal required configuration.
6260 @configuration = { }
61+ @public_root = DEFAULT_PUBLIC_ROOT
6362 @package_path = DEFAULT_PACKAGE_PATH
6463 @compressors = COMPRESSORS
6564
@@ -72,7 +71,8 @@ def self.load_configuration(config_path, soft=false)
7271 conf = YAML . load ( ERB . new ( File . read ( config_path ) ) . result )
7372
7473 # Optionally overwrite configuration based on the environment.
75- conf . merge! conf . delete RAILS_ENV if conf . has_key? RAILS_ENV
74+ rails_env = ( defined? ( Rails ) ? ::Rails . env : ENV [ 'RAILS_ENV' ] || "development" )
75+ conf . merge! conf . delete rails_env if conf . has_key? rails_env
7676
7777 @config_path = config_path
7878 @configuration = symbolize_keys ( conf )
@@ -90,6 +90,7 @@ def self.load_configuration(config_path, soft=false)
9090 set_template_function ( conf [ :template_function ] )
9191 set_template_namespace ( conf [ :template_namespace ] )
9292 set_template_extension ( conf [ :template_extension ] )
93+ set_public_root ( conf [ :public_root ] ) if conf [ :public_root ]
9394 symbolize_keys ( conf [ :stylesheets ] ) if conf [ :stylesheets ]
9495 symbolize_keys ( conf [ :javascripts ] ) if conf [ :javascripts ]
9596 check_for_deprecations
@@ -127,16 +128,24 @@ def self.package!(options={})
127128 :config_path => Jammit ::DEFAULT_CONFIG_PATH ,
128129 :output_folder => nil ,
129130 :base_url => nil ,
131+ :public_root => nil ,
130132 :force => false
131133 } . merge ( options )
132134 load_configuration ( options [ :config_path ] )
135+ set_public_root ( options [ :public_root ] ) if options [ :public_root ]
133136 packager . force = options [ :force ]
134137 packager . package_names = options [ :package_names ]
135138 packager . precache_all ( options [ :output_folder ] , options [ :base_url ] )
136139 end
137140
138141 private
139142
143+ # Allows command-line definition of `PUBLIC_ROOT`, for those using Jammit
144+ # outside of Rails.
145+ def self . set_public_root ( public_root = nil )
146+ @public_root = public_root if public_root
147+ end
148+
140149 # Ensure that the JavaScript compressor is a valid choice.
141150 def self . set_javascript_compressor ( value )
142151 value = value && value . to_sym
0 commit comments