From 13546dc9a32af656a7d18f10210f882ac64e8b10 Mon Sep 17 00:00:00 2001 From: yalab Date: Sun, 14 Oct 2012 16:14:16 +0900 Subject: [PATCH] It can use erb tag on configuration.yml. --- lib/redmine/configuration.rb | 3 ++- test/fixtures/configuration/erb.yml | 2 ++ test/unit/lib/redmine/configuration_test.rb | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/configuration/erb.yml diff --git a/lib/redmine/configuration.rb b/lib/redmine/configuration.rb index 99ca92b36..caa19caa9 100644 --- a/lib/redmine/configuration.rb +++ b/lib/redmine/configuration.rb @@ -81,7 +81,8 @@ def with(settings) def load_from_yaml(filename, env) yaml = nil begin - yaml = YAML::load_file(filename) + body = File.read(filename) + yaml = YAML::load(Erubis::Eruby.new(body).evaluate) rescue ArgumentError $stderr.puts "Your Redmine configuration file located at #{filename} is not a valid YAML file and could not be loaded." exit 1 diff --git a/test/fixtures/configuration/erb.yml b/test/fixtures/configuration/erb.yml new file mode 100644 index 000000000..6b1952931 --- /dev/null +++ b/test/fixtures/configuration/erb.yml @@ -0,0 +1,2 @@ +default: + somesetting: <%= ENV['somesetting'] %> diff --git a/test/unit/lib/redmine/configuration_test.rb b/test/unit/lib/redmine/configuration_test.rb index b4cd650be..95f28997c 100644 --- a/test/unit/lib/redmine/configuration_test.rb +++ b/test/unit/lib/redmine/configuration_test.rb @@ -41,6 +41,12 @@ def test_overrides assert_equal 'bar', @conf['somesetting'] end + def test_use_erb + ENV['somesetting'] = 'foobar' + load_conf('erb.yml', 'test') + assert_equal ENV['somesetting'], @conf['somesetting'] + end + def test_with load_conf('default.yml', 'test') assert_equal 'foo', @conf['somesetting']