Skip to content

Commit 20f7a8e

Browse files
committed
Merge branch 'master' of https://github.com/christoffer/jammit
2 parents 1a9262e + 127c9e3 commit 20f7a8e

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

lib/jammit.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ def self.load_configuration(config_path, soft=false)
6464
return false if soft && !exists
6565
raise ConfigurationNotFound, "could not find the \"#{config_path}\" configuration file" unless exists
6666
conf = YAML.load(ERB.new(File.read(config_path)).result)
67+
68+
# Optionally overwrite configurations based on the environment
69+
rails_env = defined?(Rails) ? Rails.env : RAILS_ENV
70+
if conf.has_key?(rails_env) && conf[rails_env].is_a?(Hash)
71+
conf.merge!(conf.delete(rails_env))
72+
end
73+
6774
@config_path = config_path
6875
@configuration = symbolize_keys(conf)
6976
@package_path = conf[:package_path] || DEFAULT_PACKAGE_PATH

test/config/assets-environment.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
compress_assets: on
2+
gzip_assets: on
3+
4+
development:
5+
compress_assets: off
6+
7+
test:
8+
gzip_assets: off

test/unit/test_configuration.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,15 @@ def test_jst_compilation
6262
assert packed == File.read('test/fixtures/jammed/jst_test.js')
6363
end
6464

65+
def test_environment_specific_configuration
66+
Object.send(:remove_const, :RAILS_ENV)
67+
Object.const_set :RAILS_ENV, "development"
68+
Jammit.load_configuration('test/config/assets-environment.yml')
69+
70+
assert !Jammit.compress_assets # Should override with environment specific configuration
71+
assert Jammit.gzip_assets # but keep the general configuration
72+
73+
Object.send(:remove_const, :RAILS_ENV)
74+
Object.const_set :RAILS_ENV, "test"
75+
end
6576
end

0 commit comments

Comments
 (0)