Skip to content
Browse files

make erb rendering optional. render erb only if file extension contai…

…ns '.erb.'
1 parent b8d68a7 commit ec13f8dbd84d13cf047c3e0e8189f127a27129ed @kamui kamui committed Jun 18, 2012
View
4 lib/sinatra/config_file.rb
@@ -115,7 +115,9 @@ def config_file(*paths)
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
View
2 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",
View
0 spec/config_file/with_erb.yml → spec/config_file/key_value.erb.yml
File renamed without changes.
View
2 spec/config_file_spec.rb
@@ -24,7 +24,7 @@ def config_file(*args, &block)
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

0 comments on commit ec13f8d

Please sign in to comment.
Something went wrong with that request. Please try again.