uservoice 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -26,19 +26,17 @@ Your API key <api_key> can be found in the API section of the admin documentatio
26
26
  Default properties are stored in a file named uservoice.yml in the config
27
27
  directory of your Rails application. Make it fitting to your needs.
28
28
 
29
- Link Uservoice javascript file and add configuration to HTML HEAD
30
- section of your template file:
31
- <%= javascript_include_tag 'uservoice' %>
29
+ Add javascript function and configuration to HTML HEAD section of your template file:
32
30
  <%= uservoice_config_javascript %>
33
31
 
34
32
  You can override default uservoice settings in your view:
35
33
  <%= uservoice_config_javascript(:alignment => 'right', :forum => 12983) %>
36
34
 
37
35
 
38
- == Single Sign-on
36
+ == Single Sign-On
39
37
 
40
38
  Single sign-on authenticates your users automatically against the Uservoice
41
- service. The second login is not needed any more.
39
+ service. A second login is not needed any more.
42
40
 
43
41
  Uservoice is allowing single sign-on starting from the Bronze plan.
44
42
  http://uservoice.com/signup?ref=nav
@@ -47,12 +45,10 @@ To use single sign-on with on uservoice you have to set your api_key in
47
45
  config/uservoice.yml. Find it on
48
46
  https://ACCOUNT.uservoice.com/admin2/docs#/legacy_api
49
47
 
50
- Set user data in your controller action.
51
- def index
52
- set_uservoice_sso(:guid => @current_user.id, :email => @current_user.email)
53
- end
48
+ The user properties can be set via the :sso parameter.
49
+ <%= uservoice_config_javascript(:sso => {:guid => @current_user.id, :email => @current_user.email}) %>
54
50
 
55
- Parameter <em>:guid</em> should be unique identifier for example the user id in your
51
+ Parameter <em>:guid</em> should be unique identifier, for example the user id in your
56
52
  system. Uservoice recommends setting <em>:email</em> parameter to enable users to get
57
53
  updates and notifications via email.
58
54
  See https://ACCOUNT.uservoice.com/admin2/docs#/sso for a list of parameters
@@ -70,6 +66,10 @@ available.
70
66
  commit by itself I can ignore when I pull)
71
67
  * Send me a pull request. Bonus points for topic branches.
72
68
 
69
+
70
+ This project is using {Semantic Versioning}[http://semver.org].
71
+
72
+
73
73
  == Copyright
74
74
 
75
75
  Copyright (c) 2010 {il tempo}[http://github.com/iltempo] -
data/Rakefile CHANGED
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'rake'
3
2
 
4
3
  begin
@@ -11,8 +10,11 @@ begin
11
10
  gem.email = 'alexxx@iltempo.de'
12
11
  gem.homepage = 'http://github.com/iltempo/uservoice'
13
12
  gem.authors = ['Alexander Greim']
14
- gem.version = '0.2.2'
13
+ gem.version = '0.3.0'
15
14
  gem.add_dependency('ezcrypto', '>= 0.7.2')
15
+ gem.add_dependency('activesupport', '>= 2.1')
16
+ gem.add_dependency('actionpack', '>= 2.1')
17
+ gem.add_dependency('rails', '>= 2.1')
16
18
  gem.has_rdoc = true
17
19
  gem.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
18
20
  end
@@ -1,4 +1,5 @@
1
1
  class UservoiceGenerator < Rails::Generator::Base
2
+
2
3
  def manifest
3
4
  unless [2, 3].include?(args.length)
4
5
  puts usage_message
@@ -8,9 +9,7 @@ class UservoiceGenerator < Rails::Generator::Base
8
9
  record do |m|
9
10
  m.directory('config')
10
11
  m.template 'uservoice_template.yml', 'config/uservoice.yml'
11
-
12
- m.directory('public/javascripts')
13
- m.file 'uservoice.js', 'public/javascripts/uservoice.js'
14
12
  end
15
13
  end
14
+
16
15
  end
@@ -9,14 +9,11 @@
9
9
  module Uservoice
10
10
  module InstanceMethods
11
11
 
12
- # Loads uservoice configuration into a controller
13
- # instance variable
12
+ # Making helper method available when module
13
+ # gets included into ActionController::Base.
14
14
  #
15
- def load_uservoice_config
16
- @uservoice_configuration = begin
17
- configuration = YAML::load(IO.read(uservoice_configuration_file))
18
- HashWithIndifferentAccess.new(configuration)
19
- end
15
+ def self.included(mod)
16
+ mod.send(:helper_method, :uservoice_configuration)
20
17
  end
21
18
 
22
19
  # Set uservoice configuration file path.
@@ -26,16 +23,14 @@ module Uservoice
26
23
  "#{RAILS_ROOT}/config/uservoice.yml"
27
24
  end
28
25
 
29
- # Generates token for uservoice single sign-on
30
- # that will be delivered by uservoice helper.
31
- # See https://ACCOUNT.uservoice.com/admin2/docs#/sso for
32
- # properties available.
26
+ # Returns the uservoice configuration hash.
27
+ # It's been lazy loaded and cached in the controller class.
33
28
  #
34
- def set_uservoice_sso(user_data)
35
- @uservoice_sso_token = Uservoice::Token.new(
36
- @uservoice_configuration['uservoice_options']['key'],
37
- @uservoice_configuration['uservoice_api']['api_key'],
38
- user_data)
29
+ def uservoice_configuration
30
+ @@uservoice_configuration ||= begin
31
+ configuration = YAML::load(IO.read(uservoice_configuration_file))
32
+ HashWithIndifferentAccess.new(configuration)
33
+ end
39
34
  end
40
35
 
41
36
  end
File without changes
@@ -0,0 +1,44 @@
1
+ # This module holds all frontend helper methods
2
+ # for uservoice in a Rails app.
3
+ #
4
+ # Author:: Alexander Greim (mailto:alexxx@iltempo.de)
5
+ # Copyright:: Copyright (c) 2010 il tempo
6
+ # License:: Distributes under the same terms as Ruby
7
+
8
+ module Uservoice
9
+ module UservoiceViewHelpers
10
+
11
+ # Renders javascript to configure uservoice feedback widget. Options
12
+ # can be used to override default settings like forum id.
13
+ # e.g. uservoice_config_javascript(forum_id => 12345)
14
+ # See https://ACCOUNT.uservoice.com/admin2/docs#/widget for options
15
+ # available.
16
+ #
17
+ def uservoice_config_javascript(options={})
18
+ config = uservoice_configuration['uservoice_options'].dup
19
+ config.merge!(options)
20
+
21
+ if config[:sso] && config[:sso][:guid]
22
+ config.merge!(:params => {:sso => Uservoice::Token.new(
23
+ uservoice_configuration['uservoice_options']['key'],
24
+ uservoice_configuration['uservoice_api']['api_key'],
25
+ config.delete(:sso)).to_s})
26
+ end
27
+
28
+ <<-EOS
29
+ <script type=\"text/javascript\">
30
+ function _loadUserVoice() {
31
+ var s = document.createElement('script');
32
+ s.setAttribute('type', 'text/javascript');
33
+ s.setAttribute('src', ("https:" == document.location.protocol ? "https://" : "http://") + "cdn.uservoice.com/javascripts/widgets/tab.js");
34
+ document.getElementsByTagName('head')[0].appendChild(s);
35
+ }
36
+ _loadSuper = window.onload;
37
+ window.onload = (typeof window.onload != 'function') ? _loadUserVoice : function() { _loadSuper(); _loadUserVoice(); };
38
+ var uservoiceOptions = #{config.to_json};
39
+ </script>
40
+ EOS
41
+ end
42
+
43
+ end
44
+ end
data/lib/uservoice.rb CHANGED
@@ -1,26 +1,11 @@
1
- path = File.join(File.dirname(__FILE__), 'uservoice')
2
- $LOAD_PATH << path
3
- ActiveSupport::Dependencies.load_paths << path
4
- ActiveSupport::Dependencies.load_once_paths.delete(path)
5
-
6
1
  module Uservoice
7
2
  end
8
3
 
9
4
  require 'cgi'
10
- require 'rubygems'
11
5
  require 'ezcrypto'
12
- require 'uservoice_token'
13
- require 'instance_methods'
14
-
15
- module ActionController #:nodoc:
16
- class Base #:nodoc:
17
- helper :uservoice
18
- before_filter :load_uservoice_config
6
+ require 'uservoice/token'
7
+ require 'uservoice/instance_methods'
8
+ require 'uservoice/view_helpers'
19
9
 
20
- include Uservoice::InstanceMethods
21
-
22
- def self.enable_uservoice
23
- warn "[DEPRECATION] 'enable_uservoice' is deprecated. Uservoice is loaded by default in every controller now."
24
- end
25
- end
26
- end
10
+ ActionController::Base.send(:include, Uservoice::InstanceMethods)
11
+ ActionView::Base.send(:include, Uservoice::UservoiceViewHelpers)
@@ -42,23 +42,22 @@ class UservoiceControllerTest < ActionController::TestCase
42
42
 
43
43
  def test_config_javascript_default
44
44
  get :config_js_default
45
- assert_match Regexp.new('<script type="text/javascript">\s*var uservoiceOptions = .*\s*</script>'), @response.body
46
- assert_match Regexp.new('"host":"test.uservoice.com"'), @response.body
47
- assert_match Regexp.new('"forum":12345'), @response.body
45
+ assert_match Regexp.new('^\s*<script type="text/javascript">(.*)</script>\s*$', Regexp::MULTILINE), @response.body
46
+ assert_match /var uservoiceOptions = \{.*\}/, @response.body
47
+ assert_match /"host":"test.uservoice.com"/, @response.body
48
+ assert_match /"forum":12345/, @response.body
48
49
  end
49
50
 
50
51
  def test_config_custom_forum
51
52
  get :config_js_custom_forum
52
- assert_match Regexp.new('<script type="text/javascript">\s*var uservoiceOptions = .*\s*</script>'), @response.body
53
- assert_match Regexp.new('"forum":815'), @response.body
54
- assert_no_match Regexp.new('"forum":12345'), @response.body
53
+ assert_match /"forum":815/, @response.body
54
+ assert_no_match /"forum":12345/, @response.body
55
55
  end
56
56
 
57
57
  def test_config_custom_alignment
58
58
  get :config_js_custom_alignment
59
- assert_match Regexp.new('<script type="text/javascript">\s*var uservoiceOptions = .*\s*</script>'), @response.body
60
- assert_match Regexp.new('"forum":12345'), @response.body
61
- assert_match Regexp.new('"alignment":"right"'), @response.body
59
+ assert_match /"forum":12345/, @response.body
60
+ assert_match /"alignment":"right"/, @response.body
62
61
  end
63
62
  end
64
63
 
@@ -15,10 +15,7 @@ class UservoiceGeneratorTest < Test::Unit::TestCase
15
15
  run_generator('uservoice', 'test', '12345')
16
16
  new_files = file_list - @original_files
17
17
  expected_files = ['config',
18
- 'config/uservoice.yml',
19
- 'public',
20
- 'public/javascripts',
21
- 'public/javascripts/uservoice.js']
18
+ 'config/uservoice.yml']
22
19
 
23
20
  assert_equal expected_files, new_files
24
21
  end
@@ -3,12 +3,11 @@ require 'helper'
3
3
  class MyUservoiceSsoController < ActionController::Base
4
4
 
5
5
  def uservoice_configuration_file
6
- File.dirname(__FILE__) + '/uservoice_sso_test.yml'
6
+ File.dirname(__FILE__) + '/uservoice_test.yml'
7
7
  end
8
8
 
9
9
  def action_with_sso
10
- set_uservoice_sso(:guid => 123, :display_name => 'Bancheff', :email => 'chef@bahn.de')
11
- render :inline => '<%= uservoice_config_javascript %>'
10
+ render :inline => '<%= uservoice_config_javascript(:sso => {:guid => 123, :display_name => "Bancheff", :email => "chef@bahn.de"}) %>'
12
11
  end
13
12
 
14
13
  end
@@ -28,8 +27,8 @@ class UservoiceSsoTest < ActionController::TestCase
28
27
 
29
28
  def test_sso_token_set
30
29
  get :action_with_sso
31
- assert_match Regexp.new('<script type="text/javascript">\s*var uservoiceOptions = .*\s*</script>'), @response.body
32
- assert_match Regexp.new('"params":\{"sso":".*"\}'), @response.body
30
+ assert_match Regexp.new('<script type="text/javascript">.*var uservoiceOptions = .*\s*</script>', Regexp::MULTILINE), @response.body
31
+ assert_match /"params":\{"sso":".*"\}/, @response.body
33
32
  end
34
33
 
35
34
  def test_api_key_not_to_appear
@@ -8,3 +8,6 @@ uservoice_options:
8
8
  text_color: white
9
9
  hover_color: "#06C"
10
10
  lang: en
11
+
12
+ uservoice_api:
13
+ api_key: testapikey
data/uservoice.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{uservoice}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alexander Greim"]
12
- s.date = %q{2010-05-25}
12
+ s.date = %q{2010-06-09}
13
13
  s.description = %q{This adds Uservoice support to your Rails application
14
14
  including single sign-on.}
15
15
  s.email = %q{alexxx@iltempo.de}
@@ -25,20 +25,18 @@ Gem::Specification.new do |s|
25
25
  "README.rdoc",
26
26
  "Rakefile",
27
27
  "generators/uservoice/USAGE",
28
- "generators/uservoice/templates/uservoice.js",
29
28
  "generators/uservoice/templates/uservoice_template.yml",
30
29
  "generators/uservoice/uservoice_generator.rb",
31
30
  "init.rb",
32
31
  "lib/uservoice.rb",
33
32
  "lib/uservoice/instance_methods.rb",
34
- "lib/uservoice/uservoice_helper.rb",
35
- "lib/uservoice/uservoice_token.rb",
33
+ "lib/uservoice/token.rb",
34
+ "lib/uservoice/view_helpers.rb",
36
35
  "test/helper.rb",
37
36
  "test/test_uservoice.rb",
38
37
  "test/test_uservoice_generator.rb",
39
38
  "test/test_uservoice_sso.rb",
40
39
  "test/test_uservoice_token.rb",
41
- "test/uservoice_sso_test.yml",
42
40
  "test/uservoice_test.yml",
43
41
  "uservoice.gemspec"
44
42
  ]
@@ -61,11 +59,20 @@ Gem::Specification.new do |s|
61
59
 
62
60
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
63
61
  s.add_runtime_dependency(%q<ezcrypto>, [">= 0.7.2"])
62
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.1"])
63
+ s.add_runtime_dependency(%q<actionpack>, [">= 2.1"])
64
+ s.add_runtime_dependency(%q<rails>, [">= 2.1"])
64
65
  else
65
66
  s.add_dependency(%q<ezcrypto>, [">= 0.7.2"])
67
+ s.add_dependency(%q<activesupport>, [">= 2.1"])
68
+ s.add_dependency(%q<actionpack>, [">= 2.1"])
69
+ s.add_dependency(%q<rails>, [">= 2.1"])
66
70
  end
67
71
  else
68
72
  s.add_dependency(%q<ezcrypto>, [">= 0.7.2"])
73
+ s.add_dependency(%q<activesupport>, [">= 2.1"])
74
+ s.add_dependency(%q<actionpack>, [">= 2.1"])
75
+ s.add_dependency(%q<rails>, [">= 2.1"])
69
76
  end
70
77
  end
71
78
 
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Greim
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-25 00:00:00 +02:00
18
+ date: 2010-06-09 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -34,6 +34,51 @@ dependencies:
34
34
  version: 0.7.2
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 1
46
+ segments:
47
+ - 2
48
+ - 1
49
+ version: "2.1"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: actionpack
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 1
61
+ segments:
62
+ - 2
63
+ - 1
64
+ version: "2.1"
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rails
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 1
76
+ segments:
77
+ - 2
78
+ - 1
79
+ version: "2.1"
80
+ type: :runtime
81
+ version_requirements: *id004
37
82
  description: |-
38
83
  This adds Uservoice support to your Rails application
39
84
  including single sign-on.
@@ -53,20 +98,18 @@ files:
53
98
  - README.rdoc
54
99
  - Rakefile
55
100
  - generators/uservoice/USAGE
56
- - generators/uservoice/templates/uservoice.js
57
101
  - generators/uservoice/templates/uservoice_template.yml
58
102
  - generators/uservoice/uservoice_generator.rb
59
103
  - init.rb
60
104
  - lib/uservoice.rb
61
105
  - lib/uservoice/instance_methods.rb
62
- - lib/uservoice/uservoice_helper.rb
63
- - lib/uservoice/uservoice_token.rb
106
+ - lib/uservoice/token.rb
107
+ - lib/uservoice/view_helpers.rb
64
108
  - test/helper.rb
65
109
  - test/test_uservoice.rb
66
110
  - test/test_uservoice_generator.rb
67
111
  - test/test_uservoice_sso.rb
68
112
  - test/test_uservoice_token.rb
69
- - test/uservoice_sso_test.yml
70
113
  - test/uservoice_test.yml
71
114
  - uservoice.gemspec
72
115
  has_rdoc: true
@@ -1,8 +0,0 @@
1
- function _loadUserVoice() {
2
- var s = document.createElement('script');
3
- s.setAttribute('type', 'text/javascript');
4
- s.setAttribute('src', ("https:" == document.location.protocol ? "https://" : "http://") + "cdn.uservoice.com/javascripts/widgets/tab.js");
5
- document.getElementsByTagName('head')[0].appendChild(s);
6
- }
7
- _loadSuper = window.onload;
8
- window.onload = (typeof window.onload != 'function') ? _loadUserVoice : function() { _loadSuper(); _loadUserVoice(); };
@@ -1,31 +0,0 @@
1
- # This module holds all frontend helper methods
2
- # for uservoice in a Rails app.
3
- #
4
- # Author:: Alexander Greim (mailto:alexxx@iltempo.de)
5
- # Copyright:: Copyright (c) 2010 il tempo
6
- # License:: Distributes under the same terms as Ruby
7
-
8
- module UservoiceHelper
9
-
10
- # Renders javascript to configure uservoice feedback widget. Options
11
- # can be used to override default settings like forum id.
12
- # e.g. uservoice_config_javascript(forum_id => 12345)
13
- # See https://ACCOUNT.uservoice.com/admin2/docs#/widget for options
14
- # available.
15
- #
16
- def uservoice_config_javascript(options={})
17
- config = @uservoice_configuration['uservoice_options'].dup
18
- config.merge!(options)
19
-
20
- if @uservoice_sso_token
21
- config.merge!({:params => {:sso => @uservoice_sso_token.data}})
22
- end
23
-
24
- <<-EOS
25
- <script type=\"text/javascript\">
26
- var uservoiceOptions = #{config.to_json};
27
- </script>
28
- EOS
29
- end
30
-
31
- end
@@ -1,13 +0,0 @@
1
- uservoice_options:
2
- key: test
3
- host: test.uservoice.com
4
- forum: 12345
5
- showTab: true
6
- alignment: left
7
- background_color: "#f00"
8
- text_color: white
9
- hover_color: "#06C"
10
- lang: en
11
-
12
- uservoice_api:
13
- api_key: testapikey