Navigation Menu

Skip to content
This repository has been archived by the owner on Jan 12, 2020. It is now read-only.

Commit

Permalink
Parse the config file with ERB to allow for ENV values to be substitu…
Browse files Browse the repository at this point in the history
…ted (useful when deploying to heroku)
  • Loading branch information
ewollesen committed Jul 1, 2010
1 parent 825aa47 commit b787dfa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/uservoice/instance_methods.rb
Expand Up @@ -6,6 +6,8 @@
# Copyright:: Copyright (c) 2010 il tempo
# License:: Distributes under the same terms as Ruby

require "erb"

module Uservoice
module InstanceMethods

Expand All @@ -28,7 +30,8 @@ def uservoice_configuration_file #:nodoc:
#
def uservoice_configuration
@@uservoice_configuration ||= begin
configuration = YAML::load(IO.read(uservoice_configuration_file))
config = ERB.new(IO.read(uservoice_configuration_file)).result
configuration = YAML::load(config)
HashWithIndifferentAccess.new(configuration)
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/test_uservoice.rb
Expand Up @@ -21,6 +21,10 @@ def config_js_custom_forum
def config_js_custom_alignment
render :inline => "<%= uservoice_config_javascript(:alignment => 'right') %>"
end

def config_js_erb
render :inline => "<%= uservoice_config_javascript %>"
end
end


Expand All @@ -37,6 +41,7 @@ def setup
map.connect 'config_js_default', :controller => 'my_uservoice', :action => :config_js_default
map.connect 'config_js_custom_forum', :controller => 'my_uservoice', :action => :config_js_custom_forum
map.connect 'config_js_custom_alignment', :controller => 'my_uservoice', :action => :config_js_custom_alignment
map.connect 'config_js_erb', :controller => 'my_uservoice', :action => :config_js_erb
end
end

Expand All @@ -59,5 +64,10 @@ def test_config_custom_alignment
assert_match /"forum":12345/, @response.body
assert_match /"alignment":"right"/, @response.body
end

def test_config_erb
get :config_js_erb
assert_match /"erb_value":"testing 1 2 3"/, @response.body
end
end

2 changes: 2 additions & 0 deletions test/uservoice_test.yml
@@ -1,3 +1,4 @@
<% test_value = "testing 1 2 3" %>
uservoice_options:
key: test
host: test.uservoice.com
Expand All @@ -8,6 +9,7 @@ uservoice_options:
text_color: white
hover_color: "#06C"
lang: en
erb_value: <%= test_value %>

uservoice_api:
api_key: testapikey
2 changes: 1 addition & 1 deletion uservoice.gemspec
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Alexander Greim"]
s.date = %q{2010-06-09}
s.date = %q{2010-07-01}
s.description = %q{This adds Uservoice support to your Rails application
including single sign-on.}
s.email = %q{alexxx@iltempo.de}
Expand Down

0 comments on commit b787dfa

Please sign in to comment.