diff --git a/sinatra-contrib/lib/sinatra/config_file.rb b/sinatra-contrib/lib/sinatra/config_file.rb index d117d53c..1c2e4c16 100644 --- a/sinatra-contrib/lib/sinatra/config_file.rb +++ b/sinatra-contrib/lib/sinatra/config_file.rb @@ -115,7 +115,9 @@ module Sinatra paths.each do |pattern| Dir.glob(pattern) do |file| $stderr.puts "loading config file '#{file}'" if logging? - yaml = config_for_env(YAML.load(ERB.new(IO.read(file)).result)) || {} + document = IO.read(file) + document = ERB.new(document).result if file.include?('.erb.') + yaml = config_for_env(YAML.load(document)) || {} yaml.each_pair do |key, value| for_env = config_for_env(value) set key, for_env unless value and for_env.nil? and respond_to? key diff --git a/sinatra-contrib/sinatra-contrib.gemspec b/sinatra-contrib/sinatra-contrib.gemspec index eb8937ff..768cf994 100644 --- a/sinatra-contrib/sinatra-contrib.gemspec +++ b/sinatra-contrib/sinatra-contrib.gemspec @@ -55,11 +55,11 @@ Gem::Specification.new do |s| "lib/sinatra/test_helpers.rb", "sinatra-contrib.gemspec", "spec/capture_spec.rb", + "spec/config_file/key_value.erb.yml", "spec/config_file/key_value.yml", "spec/config_file/key_value_override.yml", "spec/config_file/missing_env.yml", "spec/config_file/with_envs.yml", - "spec/config_file/with_erb.yml", "spec/config_file/with_nested_envs.yml", "spec/config_file_spec.rb", "spec/content_for/different_key.erb", diff --git a/sinatra-contrib/spec/config_file/with_erb.yml b/sinatra-contrib/spec/config_file/key_value.erb.yml similarity index 100% rename from sinatra-contrib/spec/config_file/with_erb.yml rename to sinatra-contrib/spec/config_file/key_value.erb.yml diff --git a/sinatra-contrib/spec/config_file_spec.rb b/sinatra-contrib/spec/config_file_spec.rb index 28837daa..fc198540 100644 --- a/sinatra-contrib/spec/config_file_spec.rb +++ b/sinatra-contrib/spec/config_file_spec.rb @@ -24,7 +24,7 @@ describe Sinatra::ConfigFile do end it 'should render options in ERB tags' do - config_file 'with_erb.yml' + config_file 'key_value.erb.yml' settings.foo.should == "bar" settings.something.should == 42 settings.nested['a'].should == 1