uservoice 0.1.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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ rdoc/
3
+ coverage/
4
+ pkg/uservoice-0.1.0.gem
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 il tempo - Alexander Greim
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,61 @@
1
+ = Uservoice feedback for Ruby on Rails
2
+
3
+ This adds {Uservoice}[http://www.uservoice.com] feedback to your
4
+ Rails application. You can set Uservoice properties in a central configuration
5
+ file and override settings like forum id (for payed accounts) in your layout or
6
+ view.
7
+
8
+ == Installation
9
+
10
+ === As a gem
11
+ gem install uservoice --source http://gemcutter.org
12
+
13
+ === As a Rails dependency
14
+ config.gem 'uservoice', :source => 'http://gemcutter.org'
15
+
16
+ === As a Rails plugin
17
+ ./script/plugin install http://github.com/iltempo/uservoice.git
18
+
19
+
20
+ == Configuration
21
+
22
+ Generate files for your app:
23
+ ./script/generate uservoice <key> <forum>
24
+ Where <key> is the Uservoice account name and <forum> the id of your main forum.
25
+ Find both settings in widgets section of the admin interface of Uservoice.
26
+
27
+ Default properties are stored in a file named uservoice.yml in the config directory
28
+ of your Rails application. Make it fit to your needs.
29
+
30
+ Enable Uservoice in controllers of your choice. Add to ApplicationController
31
+ directly to enable uservoice for every controller.
32
+
33
+ class MyController < ApplicationController
34
+ enable_uservoice
35
+ ...
36
+ end
37
+
38
+ Link Uservoice javascript file and add configuration to HTML HEAD section of
39
+ your template file:
40
+ <%= javascript_include_tag 'uservoice' %>
41
+ <%= uservoice_config_javascript %>
42
+
43
+ You can even override default uservoice settings in your view:
44
+ <%= uservoice_config_javascript(:alignment => 'right', :forum => 12983) %>
45
+
46
+
47
+ == Note on Patches/Pull Requests
48
+
49
+ * Fork the project.
50
+ * Make your feature addition or bug fix.
51
+ * Add tests for it. This is important so I don't break it in a
52
+ future version unintentionally.
53
+ * Commit, do not mess with rakefile, version, or history.
54
+ (if you want to have your own version, that is fine but bump version in a
55
+ commit by itself I can ignore when I pull)
56
+ * Send me a pull request. Bonus points for topic branches.
57
+
58
+ == Copyright
59
+
60
+ Copyright (c) 2010 {il tempo}[http://github.com/iltempo] -
61
+ {Alexander Greim}[http://github.com/iltempo], released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "uservoice"
8
+ gem.summary = %Q{Uservoice for your Rails application}
9
+ gem.description = %Q{This adds Uservoice user feedback to your Rails application.
10
+ You can set Uservoice properties in a central configuration file and override
11
+ settings like forum id (for payed accounts) in your layout or view.}
12
+ gem.email = 'alexxx@iltempo.de'
13
+ gem.homepage = 'http://github.com/iltempo/uservoice'
14
+ gem.authors = ['Alexander Greim']
15
+ gem.version = '0.1.0'
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "uservoice #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
@@ -0,0 +1,14 @@
1
+ Name
2
+ uservoice - creates uservoice files
3
+
4
+ Description:
5
+ This generator creates all files needed for uservoice integration.
6
+
7
+ ./script/generate uservoice <uservoice_key> <main_forum_id>
8
+
9
+ Please add to head section of your layout file:
10
+ <%= javascript_include_tag 'uservoice' %>
11
+ <%= uservoice_config_javascript %>
12
+
13
+ Example:
14
+ ./script/generate uservoice mypage 12345
@@ -0,0 +1,8 @@
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(); };
@@ -0,0 +1,12 @@
1
+ uservoice_options:
2
+ # required
3
+ key: <%= args.first %>
4
+ host: <%= args.first %>.uservoice.com
5
+ forum: <%= args.second %>
6
+ showTab: true
7
+ # optional
8
+ alignment: left
9
+ background_color: "#f00"
10
+ text_color: white
11
+ hover_color: "#06C"
12
+ lang: en
@@ -0,0 +1,16 @@
1
+ class UservoiceGenerator < Rails::Generator::Base
2
+ def manifest
3
+ unless args.length == 2
4
+ puts usage_message
5
+ exit 1
6
+ end
7
+
8
+ record do |m|
9
+ m.directory('config')
10
+ m.template 'uservoice_template.yml', 'config/uservoice.yml'
11
+
12
+ m.directory('public/javascripts')
13
+ m.file 'uservoice.js', 'public/javascripts/uservoice.js'
14
+ end
15
+ end
16
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'uservoice'
@@ -0,0 +1,26 @@
1
+ # This module holds all class methods to be
2
+ # included into ActionController::Base class
3
+ # for enabling uservoice in a Rails app.
4
+ #
5
+ # Author:: Alexander Greim (mailto:alexxx@iltempo.de)
6
+ # Copyright:: Copyright (c) 2010 il tempo
7
+ # License:: Distributes under the same terms as Ruby
8
+
9
+ module Uservoice
10
+ module ClassMethods
11
+
12
+ # Loads uservoice configuration from yaml file.
13
+ #
14
+ def enable_uservoice
15
+ self.uservoice_configuration ||= begin
16
+ configuration = YAML::load(IO.read(self.uservoice_configuration_file))
17
+ HashWithIndifferentAccess.new(configuration['uservoice_options'])
18
+ end
19
+ end
20
+
21
+ def uservoice_configuration_file #:nodoc:
22
+ "#{RAILS_ROOT}/config/uservoice.yml"
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # This module holds all instance methods to be
2
+ # included into ActionController::Base class
3
+ # for enabling uservoice in a Rails app.
4
+ #
5
+ # Author:: Alexander Greim (mailto:alexxx@iltempo.de)
6
+ # Copyright:: Copyright (c) 2010 il tempo
7
+ # License:: Distributes under the same terms as Ruby
8
+
9
+ module Uservoice
10
+ module InstanceMethods
11
+
12
+ # Enables uservoice configuration as controller
13
+ # instance variable
14
+ #
15
+ def uservoice_init
16
+ @uservoice_configuration ||= self.class.uservoice_configuration
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,20 @@
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 configuration to be integrated
11
+ # into layout file.
12
+ # Takes a forum id if different from default one.
13
+ #
14
+ def uservoice_config_javascript(options={})
15
+ config = @uservoice_configuration.dup
16
+ config.merge!(options)
17
+ "<script type=\"text/javascript\"> var uservoiceOptions = #{config.to_json}; </script>"
18
+ end
19
+
20
+ end
data/lib/uservoice.rb ADDED
@@ -0,0 +1,21 @@
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
+ module Uservoice
7
+ end
8
+
9
+ require 'class_methods'
10
+ require 'instance_methods'
11
+
12
+ module ActionController #:nodoc:
13
+ class Base #:nodoc:
14
+ cattr_accessor :uservoice_configuration
15
+ before_filter :uservoice_init
16
+ helper :uservoice
17
+
18
+ include Uservoice::InstanceMethods
19
+ extend Uservoice::ClassMethods
20
+ end
21
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ require 'active_support'
5
+ require 'active_support/test_case'
6
+
7
+ require 'action_controller'
8
+ require 'action_controller/test_process'
9
+
10
+ require 'rails_generator'
11
+ require 'rails_generator/scripts/generate'
12
+ generator_source = Rails::Generator::PathSource.new(:uservoice, File.dirname(__FILE__) + '/../generators')
13
+ Rails::Generator::Base.append_sources(generator_source)
14
+
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
17
+ require 'uservoice'
18
+
19
+ class Test::Unit::TestCase
20
+ end
21
+
22
+ begin
23
+ require 'redgreen' unless ENV['TM_FILENAME']
24
+ rescue LoadError
25
+ end
@@ -0,0 +1,89 @@
1
+ require 'helper'
2
+
3
+ class MyUservoiceController < ActionController::Base
4
+ def self.uservoice_configuration_file
5
+ File.dirname(__FILE__) + '/uservoice_test.yml'
6
+ end
7
+ enable_uservoice
8
+
9
+ def assignment
10
+ render :text => nil
11
+ end
12
+
13
+ def config_js_default
14
+ render :inline => "<%= uservoice_config_javascript %>"
15
+ end
16
+
17
+ def config_js_custom_forum
18
+ render :inline => "<%= uservoice_config_javascript(:forum => 815) %>"
19
+ end
20
+
21
+ def config_js_custom_alignment
22
+ render :inline => "<%= uservoice_config_javascript(:alignment => 'right') %>"
23
+ end
24
+ end
25
+
26
+ class UservoiceTest < ActiveSupport::TestCase
27
+
28
+ def setup
29
+ @my_controller = MyUservoiceController.new
30
+ end
31
+
32
+ ['uservoice_configuration_file'].each do |method|
33
+ test "should add class method '#{method}' to controller classes" do
34
+ assert MyUservoiceController.methods.include?(method)
35
+ end
36
+ end
37
+
38
+ ['uservoice_init'].each do |method|
39
+ test "should add instance method '#{method}' to controller classes" do
40
+ assert @my_controller.methods.include?(method)
41
+ end
42
+ end
43
+ end
44
+
45
+ class MyUservoiceControllerTest < ActionController::TestCase
46
+ tests MyUservoiceController
47
+
48
+ def setup
49
+ @my_controller = MyUservoiceController.new
50
+ @request = ActionController::TestRequest.new
51
+ @response = ActionController::TestResponse.new
52
+
53
+ ActionController::Routing::Routes.draw do |map|
54
+ map.connect 'assignment', :controller => 'my_uservoice', :action => :assignment
55
+ map.connect 'config_js_default', :controller => 'my_uservoice', :action => :config_js_default
56
+ map.connect 'config_js_custom_forum', :controller => 'my_uservoice', :action => :config_js_custom_forum
57
+ map.connect 'config_js_custom_alignment', :controller => 'my_uservoice', :action => :config_js_custom_alignment
58
+ end
59
+ end
60
+
61
+ def test_controller
62
+ get :assignment
63
+ config = assigns('uservoice_configuration')
64
+ assert config.is_a?(Hash)
65
+ assert_equal 'test', config['key']
66
+ end
67
+
68
+ def test_config_javascript_default
69
+ get :config_js_default
70
+ assert_match Regexp.new('<script type="text/javascript"> var uservoiceOptions = .*</script>'), @response.body
71
+ assert_match Regexp.new('"host":"test.uservoice.com"'), @response.body
72
+ assert_match Regexp.new('"forum":12345'), @response.body
73
+ end
74
+
75
+ def test_config_custom_forum
76
+ get :config_js_custom_forum
77
+ assert_match Regexp.new('<script type="text/javascript"> var uservoiceOptions = .*</script>'), @response.body
78
+ assert_match Regexp.new('"forum":815'), @response.body
79
+ assert_no_match Regexp.new('"forum":12345'), @response.body
80
+ end
81
+
82
+ def test_config_custom_alignment
83
+ get :config_js_custom_alignment
84
+ assert_match Regexp.new('<script type="text/javascript"> var uservoiceOptions = .*</script>'), @response.body
85
+ assert_match Regexp.new('"forum":12345'), @response.body
86
+ assert_match Regexp.new('"alignment":"right"'), @response.body
87
+ end
88
+ end
89
+
@@ -0,0 +1,54 @@
1
+ require 'helper'
2
+
3
+ class UservoiceGeneratorTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ FileUtils.mkdir_p(fake_rails_root)
7
+ @original_files = file_list
8
+ end
9
+
10
+ def teardown
11
+ FileUtils.rm_r(fake_rails_root)
12
+ end
13
+
14
+ def test_generates_correct_files
15
+ run_generator('uservoice', 'test', '12345')
16
+ new_files = file_list - @original_files
17
+ expected_files = ['config',
18
+ 'config/uservoice.yml',
19
+ 'public',
20
+ 'public/javascripts',
21
+ 'public/javascripts/uservoice.js']
22
+
23
+ assert_equal expected_files, new_files
24
+ end
25
+
26
+ def test_config_file_contains_settings
27
+ run_generator('uservoice', 'my_name', '98765')
28
+ config = read_config_file
29
+ assert_equal 'my_name', config['key']
30
+ assert_equal 'my_name.uservoice.com', config['host']
31
+ assert_equal 98765, config['forum']
32
+ end
33
+
34
+ private
35
+
36
+ def fake_rails_root
37
+ File.join(File.dirname(__FILE__), 'rails_root')
38
+ end
39
+
40
+ def file_list
41
+ Dir.chdir(fake_rails_root) do
42
+ Dir.glob('**/*')
43
+ end
44
+ end
45
+
46
+ def read_config_file
47
+ YAML::load(IO.read(File.join(fake_rails_root, 'config/uservoice.yml')))['uservoice_options']
48
+ end
49
+
50
+ def run_generator(*options)
51
+ Rails::Generator::Scripts::Generate.new.run(options, :destination => fake_rails_root, :quiet => true)
52
+ end
53
+
54
+ end
@@ -0,0 +1,12 @@
1
+ uservoice_options:
2
+ # required
3
+ key: test
4
+ host: test.uservoice.com
5
+ forum: 12345
6
+ showTab: true
7
+ # optional
8
+ alignment: left
9
+ background_color: "#f00"
10
+ text_color: white
11
+ hover_color: "#06C"
12
+ lang: en
data/uservoice.gemspec ADDED
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{uservoice}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alexander Greim"]
12
+ s.date = %q{2010-01-01}
13
+ s.description = %q{This adds Uservoice user feedback to your Rails application.
14
+ You can set Uservoice properties in a central configuration file and override
15
+ settings like forum id (for payed accounts) in your layout or view.}
16
+ s.email = %q{alexxx@iltempo.de}
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "generators/uservoice/USAGE",
27
+ "generators/uservoice/templates/uservoice.js",
28
+ "generators/uservoice/templates/uservoice_template.yml",
29
+ "generators/uservoice/uservoice_generator.rb",
30
+ "init.rb",
31
+ "lib/uservoice.rb",
32
+ "lib/uservoice/class_methods.rb",
33
+ "lib/uservoice/instance_methods.rb",
34
+ "lib/uservoice/uservoice_helper.rb",
35
+ "test/helper.rb",
36
+ "test/test_uservoice.rb",
37
+ "test/test_uservoice_generator.rb",
38
+ "test/uservoice_test.yml",
39
+ "uservoice.gemspec"
40
+ ]
41
+ s.homepage = %q{http://github.com/iltempo/uservoice}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.5}
45
+ s.summary = %q{Uservoice for your Rails application}
46
+ s.test_files = [
47
+ "test/helper.rb",
48
+ "test/test_uservoice.rb",
49
+ "test/test_uservoice_generator.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
57
+ else
58
+ end
59
+ else
60
+ end
61
+ end
62
+
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uservoice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Greim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-01 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: |-
17
+ This adds Uservoice user feedback to your Rails application.
18
+ You can set Uservoice properties in a central configuration file and override
19
+ settings like forum id (for payed accounts) in your layout or view.
20
+ email: alexxx@iltempo.de
21
+ executables: []
22
+
23
+ extensions: []
24
+
25
+ extra_rdoc_files:
26
+ - LICENSE
27
+ - README.rdoc
28
+ files:
29
+ - .gitignore
30
+ - LICENSE
31
+ - README.rdoc
32
+ - Rakefile
33
+ - generators/uservoice/USAGE
34
+ - generators/uservoice/templates/uservoice.js
35
+ - generators/uservoice/templates/uservoice_template.yml
36
+ - generators/uservoice/uservoice_generator.rb
37
+ - init.rb
38
+ - lib/uservoice.rb
39
+ - lib/uservoice/class_methods.rb
40
+ - lib/uservoice/instance_methods.rb
41
+ - lib/uservoice/uservoice_helper.rb
42
+ - test/helper.rb
43
+ - test/test_uservoice.rb
44
+ - test/test_uservoice_generator.rb
45
+ - test/uservoice_test.yml
46
+ - uservoice.gemspec
47
+ has_rdoc: true
48
+ homepage: http://github.com/iltempo/uservoice
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Uservoice for your Rails application
75
+ test_files:
76
+ - test/helper.rb
77
+ - test/test_uservoice.rb
78
+ - test/test_uservoice_generator.rb