From 60e1a5aa69320ea32a1b48cada36cdf5521994c4 Mon Sep 17 00:00:00 2001 From: Britt Ballard Date: Fri, 14 Feb 2014 13:35:30 -0800 Subject: [PATCH] Use ERB when importing conf files into app --- app/models/global_setting.rb | 2 +- config/discourse_defaults.conf | 1 + spec/models/global_setting_spec.rb | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb index 387468d9b..850f75f5a 100644 --- a/app/models/global_setting.rb +++ b/app/models/global_setting.rb @@ -63,7 +63,7 @@ class GlobalSetting end def read - File.read(@file).split("\n").each do |line| + ERB.new(File.read(@file)).result().split("\n").each do |line| if line =~ /([a-z_]+)\s*=\s*(\"([^\"]*)\"|\'([^\']*)\'|[^#]*)/ @data[$1.strip.to_sym] = ($4 || $3 || $2).strip end diff --git a/config/discourse_defaults.conf b/config/discourse_defaults.conf index ebaa77e5d..424a0371c 100644 --- a/config/discourse_defaults.conf +++ b/config/discourse_defaults.conf @@ -1,6 +1,7 @@ # # DO NOT EDIT THIS FILE # If you need to make changes create a file called discourse.conf in this directory with your changes +# On inport this file will be imported using ERB # # Discourse supports multiple mechanisms for production config. diff --git a/spec/models/global_setting_spec.rb b/spec/models/global_setting_spec.rb index 54d81c9a9..eb02e192f 100644 --- a/spec/models/global_setting_spec.rb +++ b/spec/models/global_setting_spec.rb @@ -31,4 +31,16 @@ describe GlobalSetting::FileProvider do f.unlink end + it "uses ERB" do + f = Tempfile.new('foo') + f.write("a = <%= 500 %> # this is a comment\n") + f.close + + provider = GlobalSetting::FileProvider.from(f.path) + + provider.lookup(:a,"").should == 500 + + f.unlink + end + end