make erb rendering optional. render erb only if file extension contains '.erb.'

This commit is contained in:
Jack Chu 2012-06-18 11:54:28 -04:00
parent b71aaf05fa
commit 569a449fef
4 changed files with 5 additions and 3 deletions

View File

@ -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

View File

@ -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 File

@ -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