disqus 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
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.textile ADDED
@@ -0,0 +1,84 @@
1
+ h1. Disqus Ruby Gem
2
+
3
+ The Disqus Gem helps you easily integrate the "Disqus":http://disqus.com
4
+ commenting system into your website. It works for any site programmed in Ruby,
5
+ not just Rails.
6
+
7
+ h2. Get it
8
+
9
+ h3. Stable release:
10
+
11
+ <code>
12
+ gem install disqus
13
+ </code>
14
+
15
+ h3. Bleeding edge:
16
+
17
+ <code>
18
+ gem install norman-disqus --source http://gems.github.com
19
+ </code>
20
+
21
+ h2. Use it:
22
+
23
+ h3. Configure it:
24
+
25
+ <pre>
26
+ <code>
27
+ Disqus::defaults[:account] = "my_account"
28
+ </code>
29
+ </pre>
30
+
31
+ h3. Show the comment threads on a post page:
32
+
33
+ <pre>
34
+ <code>
35
+ # Loads the commenting system
36
+ Disqus::Widget::thread
37
+ # Or if you're using Rails:
38
+ disqus_thread
39
+
40
+ # Appends the comment count to a end of link text for a url that ends with
41
+ # #disqus_thread. For example:
42
+ # <a href="http://my.website/article-permalink#disqus_thread">View Comments</a>
43
+ Disqus::Widget::comment_counts
44
+ # Or if you're using Rails:
45
+ disqus_comment_counts
46
+ </code>
47
+ </pre>
48
+
49
+ h3. Show the combo widget on a post page:
50
+
51
+ <pre>
52
+ <code>
53
+ Disqus::Widget::combo(:color => "blue", :hide_mods => false, :num_items => 25)
54
+ # Or if you're using Rails:
55
+ disqus_combo(:color => "blue", :hide_mods => false, :num_items => 25)
56
+ </code>
57
+ </pre>
58
+
59
+ h3. Show the comment count on a permalink:
60
+
61
+ <pre>
62
+ <code>
63
+ link_to("Permalink", post_path(@post, :anchor => "disqus_thread"))
64
+ ...
65
+ Disqus::Widget::comment_counts
66
+ # Or for Rails:
67
+ disqus_comment_counts
68
+ </code>
69
+ </pre>
70
+
71
+ h2. Hack it:
72
+
73
+ Github repository: http://github.com/norman/disqus
74
+
75
+ h2. Complain about it:
76
+
77
+ "norman@randomba.org":norman@randomba.org
78
+
79
+ h2. Learn more about Disqus:
80
+
81
+ "http://disqus.com":http://disqus.com
82
+
83
+ Copyright (c) 2008 "Norman Clarke":norman@randomba.org, released under
84
+ the MIT license
data/README.txt ADDED
@@ -0,0 +1,65 @@
1
+ Disqus Ruby Gem
2
+
3
+ The Disqus Gem helps you easily integrate the Disqus commenting system into your website. It works for any site programmed in Ruby, not just Rails.
4
+
5
+ Get it
6
+
7
+ Stable release:
8
+
9
+ gem install disqus
10
+
11
+ Bleeding edge:
12
+
13
+ gem install norman-disqus --source http://gems.github.com
14
+
15
+ Use it:
16
+
17
+ Configure it:
18
+
19
+
20
+ Disqus::defaults[:account] = "my_account"
21
+
22
+ Show the comment threads on a post page:
23
+
24
+
25
+ # Loads the commenting system
26
+ Disqus::Widget::thread
27
+ # Or if you're using Rails:
28
+ disqus_thread
29
+
30
+ # Appends the comment count to a end of link text for a url that ends with
31
+ # #disqus_thread. For example:
32
+ # <a href="http://my.website/article-permalink#disqus_thread">View Comments</a>
33
+ Disqus::Widget::comment_counts
34
+ # Or if you're using Rails:
35
+ disqus_comment_counts
36
+
37
+ Show the combo widget on a post page:
38
+
39
+
40
+ Disqus::Widget::combo(:color => "blue", :hide_mods => false, :num_items => 25)
41
+ # Or if you're using Rails:
42
+ disqus_combo(:color => "blue", :hide_mods => false, :num_items => 25)
43
+
44
+ Show the comment count on a permalink:
45
+
46
+
47
+ link_to("Permalink", post_path(@post, :anchor => "disqus_thread"))
48
+ ...
49
+ Disqus::Widget::comment_counts
50
+ # Or for Rails:
51
+ disqus_comment_counts
52
+
53
+ Hack it:
54
+
55
+ Github repository: http://github.com/norman/disqus
56
+
57
+ Complain about it:
58
+
59
+ norman@randomba.org
60
+
61
+ Learn more about Disqus:
62
+
63
+ http://disqus.com
64
+
65
+ Copyright© 2008 Norman Clarke, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Run unit tests.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc "Build gem"
17
+ task :gem do
18
+ sh "gem build disqus.gemspec"
19
+ end
20
+
21
+ desc "Run rcov"
22
+ task :rcov do
23
+ rm_f "coverage"
24
+ rm_f "coverage.data"
25
+ if PLATFORM =~ /darwin/
26
+ exclude = '--exclude "gems"'
27
+ else
28
+ exclude = '--exclude "rubygems"'
29
+ end
30
+ rcov = "rcov --rails -Ilib:test --sort coverage --text-report #{exclude} --no-validator-links"
31
+ cmd = "#{rcov} #{Dir["test/**/*.rb"].join(" ")}"
32
+ sh cmd
33
+ end
34
+
35
+ desc 'Generate rdocs.'
36
+ Rake::RDocTask.new(:rdoc) do |rdoc|
37
+ rdoc.rdoc_dir = 'rdoc'
38
+ rdoc.title = 'Disqus'
39
+ rdoc.options << '--line-numbers' << '--inline-source' << '-c UTF-8'
40
+ rdoc.rdoc_files.include('lib/**/*.rb')
41
+ rdoc.rdoc_files.include('README.txt')
42
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'disqus'
data/lib/disqus.rb ADDED
@@ -0,0 +1,36 @@
1
+ require 'disqus/widget'
2
+
3
+
4
+ # Disqus is a javascript embed that enhances your blog's comments and
5
+ # integrates it with a fully moderated community forum. The Disqus gem helps
6
+ # you quickly and easily integrate Disqus's widgets into your Ruby-based
7
+ # website. To use it, please first create an account on Disqus.
8
+ module Disqus
9
+
10
+ @defaults = {
11
+ :account => "",
12
+ :avatar_size => 48,
13
+ :color => "grey",
14
+ :default_tab => "popular",
15
+ :hide_avatars => false,
16
+ :hide_mods => true,
17
+ :num_items => 15,
18
+ :show_powered_by => true,
19
+ :orientation => "horizontal"
20
+ }
21
+
22
+ def self.defaults
23
+ @defaults
24
+ end
25
+
26
+ def self.enable_rails
27
+ return if ActionView::Base.instance_methods.include? 'disqus_thread'
28
+ require 'disqus/rails_view_helpers'
29
+ ActionView::Base.class_eval { include Disqus::RailsViewHelpers }
30
+ end
31
+
32
+ end
33
+
34
+ if defined?(Rails) and defined?(ActionView)
35
+ Disqus::enable_rails
36
+ end
@@ -0,0 +1,31 @@
1
+ module Disqus
2
+
3
+ module RailsViewHelpers
4
+
5
+ def disqus_thread(options = {})
6
+ Disqus::Widget::thread(options)
7
+ end
8
+
9
+ def disqus_comment_counts(options = {})
10
+ Disqus::Widget::comment_counts(options)
11
+ end
12
+
13
+ def disqus_top_commenters(options = {})
14
+ Disqus::Widget::top_commenters(options)
15
+ end
16
+
17
+ def disqus_popular_threads(options = {})
18
+ Disqus::Widget::popular_threads(options)
19
+ end
20
+
21
+ def disqus_recent_comments(options = {})
22
+ Disqus::Widget::recent_comments(options)
23
+ end
24
+
25
+ def disqus_combo(options = {})
26
+ Disqus::Widget::combo(options)
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,161 @@
1
+ module Disqus
2
+
3
+ class Widget
4
+
5
+ class Error < StandardError ; end
6
+
7
+ VALID_COLORS = ['blue', 'grey', 'green', 'red', 'orange']
8
+ VALID_NUM_ITEMS = 5..20
9
+ VALID_DEFAULT_TABS = ['people', 'recent', 'popular']
10
+ VALID_AVATAR_SIZES = [24, 32, 48, 92, 128]
11
+ VALID_ORIENTATIONS = ['horizontal', 'vertical']
12
+
13
+ ROOT_PATH = 'http://disqus.com/forums/%s/'
14
+ THREAD = ROOT_PATH + 'embed.js'
15
+ COMBO = ROOT_PATH + 'combination_widget.js?num_items=%d&color=%s&default_tab=%s'
16
+ RECENT = ROOT_PATH + 'recent_comments_widget.js?num_items=%d&avatar_size=%d'
17
+ POPULAR = ROOT_PATH + 'popular_threads_widget.js?num_items=%d'
18
+ TOP = ROOT_PATH + 'top_commenters_widget.js?num_items=%d&avatar_size=%d&orientation=%s'
19
+ class << self
20
+
21
+ # Show the main Disqus thread widget. Options:
22
+ # * <tt>account:</tt> Your Discus account (required).
23
+ def thread(opts = {})
24
+ opts = Disqus::defaults.merge(opts)
25
+ opts[:view_thread_text] ||= "View the discussion thread"
26
+ validate_opts!(opts)
27
+ s = '<div id="disqus_thread"></div>'
28
+ s << '<script type="text/javascript" src="' + THREAD + '"></script>'
29
+ s << '<noscript><a href="http://%s.disqus.com/?url=ref">'
30
+ s << opts[:view_thread_text]
31
+ s << '</a></noscript>'
32
+ if opts[:show_powered_by]
33
+ s << '<a href="http://disqus.com" class="dsq-brlink">blog comments '
34
+ s << 'powered by <span class="logo-disqus">Disqus</span></a>'
35
+ end
36
+ s % [opts[:account], opts[:account]]
37
+ end
38
+
39
+ # Loads Javascript to show the number of comments for the page. Options:
40
+ # * <tt>account:</tt> Your Discus account (required).
41
+ def comment_counts(opts = {})
42
+ opts = Disqus::defaults.merge(opts)
43
+ validate_opts!(opts)
44
+ s = <<-WHIMPER
45
+ <script type="text/javascript">
46
+ //<[CDATA[
47
+ (function() {
48
+ var links = document.getElementsByTagName('a');
49
+ var query = '?';
50
+ for(var i = 0; i < links.length; i++) {
51
+ if(links[i].href.indexOf('#disqus_thread') >= 0) {
52
+ query += 'url' + i + '=' + encodeURIComponent(links[i].href) + '&';
53
+ }
54
+ }
55
+ document.write('<script type="text/javascript" src="#{ROOT_PATH}get_num_replies.js' + query + '"></' + 'script>');
56
+ })();
57
+ //]]>
58
+ </script>
59
+ WHIMPER
60
+ s % opts[:account]
61
+ end
62
+
63
+ # Show the main Disqus thread widget. Options:
64
+ # * <tt>account:</tt> Your Discus account (required).
65
+ # * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
66
+ # * <tt>show_powered_by:</tt> Show or hide the powered by Disqus text.
67
+ # * <tt>num_items:</tt>: How many items to show.
68
+ # * <tt>hide_mods:</tt> Don't show moderators.
69
+ # * <tt>hide_avatars:</tt> Don't show avatars.
70
+ # * <tt>avatar_size:</tt> Avatar size.
71
+ def top_commenters(opts = {})
72
+ opts = Disqus::defaults.merge(opts)
73
+ opts[:header] ||= '<h2 class="dsq-widget-title">Top Commenters</h2>'
74
+ validate_opts!(opts)
75
+ s = '<div id="dsq-topcommenters" class="dsq-widget">'
76
+ s << opts[:header]
77
+ s << '<script type="text/javascript" src="'
78
+ s << TOP
79
+ s << '&hide_avatars=1' if opts[:hide_avatars]
80
+ s << '&hide_mods=1' if opts[:hide_mods]
81
+ s << '"></script>'
82
+ s << '</div>'
83
+ if opts[:show_powered_by]
84
+ s << '<a href="http://disqus.com">Powered by Disqus</a>'
85
+ end
86
+ s % [opts[:account], opts[:num_items], opts[:avatar_size], opts[:orientation]]
87
+ end
88
+
89
+ # Show the main Disqus thread widget. Options:
90
+ # * <tt>account:</tt> Your Discus account (required).
91
+ # * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
92
+ # * <tt>num_items:</tt>: How many items to show.
93
+ # * <tt>hide_mods:</tt> Don't show moderators.
94
+ def popular_threads(opts = {})
95
+ opts = Disqus::defaults.merge(opts)
96
+ opts[:header] ||= '<h2 class="dsq-widget-title">Popular Threads</h2>'
97
+ validate_opts!(opts)
98
+ s = '<div id="dsq-popthreads" class="dsq-widget">'
99
+ s << opts[:header]
100
+ s << '<script type="text/javascript" src="'
101
+ s << POPULAR
102
+ s << '&hide_mods=1' if opts[:hide_mods]
103
+ s << '"></script>'
104
+ s << '</div>'
105
+ s << '<a href="http://disqus.com">Powered by Disqus</a>' if opts[:show_powered_by]
106
+ s % [opts[:account], opts[:num_items]]
107
+ end
108
+
109
+ # Show the main Disqus thread widget. Options:
110
+ # * <tt>account:</tt> Your Discus account (required).
111
+ # * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
112
+ # * <tt>num_items:</tt>: How many items to show.
113
+ # * <tt>hide_avatars:</tt> Don't show avatars.
114
+ # * <tt>avatar_size:</tt> Avatar size.
115
+ def recent_comments(opts = {})
116
+ opts = Disqus::defaults.merge(opts)
117
+ opts[:header] ||= '<h2 class="dsq-widget-title">Recent Comments</h2>'
118
+ validate_opts!(opts)
119
+ s = '<div id="dsq-recentcomments" class="dsq-widget">'
120
+ s << opts[:header]
121
+ s << '<script type="text/javascript" src="'
122
+ s << RECENT
123
+ s << '&hide_avatars=1' if opts[:hide_avatars]
124
+ s << '"></script>'
125
+ s << '</div>'
126
+ if opts[:show_powered_by]
127
+ s << '<a href="http://disqus.com">Powered by Disqus</a>'
128
+ end
129
+ s % [opts[:account], opts[:num_items], opts[:avatar_size]]
130
+ end
131
+
132
+ # Show the main Disqus thread widget. Options:
133
+ # * <tt>account:</tt> Your Discus account (required).
134
+ # * <tt>num_items:</tt>: How many items to show.
135
+ # * <tt>hide_mods:</tt> Don't show moderators.
136
+ def combo(opts = {})
137
+ opts = Disqus::defaults.merge(opts)
138
+ validate_opts!(opts)
139
+ s = '<script type="text/javascript" src="'
140
+ s << COMBO
141
+ s << '&hide_mods=1' if opts[:hide_mods]
142
+ s << '"></script>'
143
+ s % [opts[:account], opts[:num_items], opts[:color], opts[:default_tab]]
144
+ end
145
+
146
+ private
147
+
148
+ def validate_opts!(opts)
149
+ raise Error.new("You must specify an :account") if !opts[:account]
150
+ raise Error.new("Invalid color") if opts[:color] && !VALID_COLORS.include?(opts[:color])
151
+ raise Error.new("Invalid num_items") if opts[:num_items] && !VALID_NUM_ITEMS.include?(opts[:num_items])
152
+ raise Error.new("Invalid default_tab") if opts[:default_tab] && !VALID_DEFAULT_TABS.include?(opts[:default_tab])
153
+ raise Error.new("Invalid avatar size") if opts[:avatar_size] && !VALID_AVATAR_SIZES.include?(opts[:avatar_size])
154
+ raise Error.new("Invalid orientation") if opts[:orientation] && !VALID_ORIENTATIONS.include?(opts[:orientation])
155
+ end
156
+
157
+ end
158
+
159
+ end
160
+
161
+ end
@@ -0,0 +1,37 @@
1
+ require 'test/unit'
2
+ require 'disqus'
3
+ require 'disqus/rails_view_helpers'
4
+
5
+ class DisqusWidgetTest < Test::Unit::TestCase
6
+
7
+ include Disqus::RailsViewHelpers
8
+
9
+ def setup
10
+ Disqus::defaults[:account] = "tests"
11
+ end
12
+
13
+ def test_disqus_thread
14
+ assert disqus_thread
15
+ end
16
+
17
+ def test_disqus_comment_counts
18
+ assert disqus_comment_counts
19
+ end
20
+
21
+ def test_disqus_top_commenters
22
+ assert disqus_top_commenters
23
+ end
24
+
25
+ def test_disqus_popular_threads
26
+ assert disqus_popular_threads
27
+ end
28
+
29
+ def test_disqus_recent_comments
30
+ assert disqus_recent_comments
31
+ end
32
+
33
+ def test_disqus_combo
34
+ assert disqus_combo
35
+ end
36
+
37
+ end
@@ -0,0 +1,58 @@
1
+ require 'test/unit'
2
+ require 'disqus'
3
+
4
+ class DisqusWidgetTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ Disqus::defaults[:account] = "tests"
8
+ end
9
+
10
+ def test_thread
11
+ assert Disqus::Widget::thread
12
+ end
13
+
14
+ def test_comment_counts
15
+ assert Disqus::Widget::comment_counts
16
+ end
17
+
18
+ def test_combo
19
+ assert Disqus::Widget::combo
20
+ end
21
+
22
+ def test_recent_comments
23
+ assert Disqus::Widget::recent_comments
24
+ end
25
+
26
+ def test_popular_threads
27
+ assert Disqus::Widget::popular_threads
28
+ end
29
+
30
+ def test_top_commenters
31
+ assert Disqus::Widget::top_commenters
32
+ end
33
+
34
+ def test_invalid_default_tab
35
+ assert_raises Disqus::Widget::Error do
36
+ Disqus::Widget::combo(:default_tab => "test")
37
+ end
38
+ end
39
+
40
+ def test_invalid_color
41
+ assert_raises Disqus::Widget::Error do
42
+ Disqus::Widget::combo(:color => "test")
43
+ end
44
+ end
45
+
46
+ def test_invalid_num_items
47
+ assert_raises Disqus::Widget::Error do
48
+ Disqus::Widget::combo(:num_items => 100)
49
+ end
50
+ end
51
+
52
+ def test_invalid_avatar_size
53
+ assert_raises Disqus::Widget::Error do
54
+ Disqus::Widget::top_commenters(:avatar_size => 100)
55
+ end
56
+ end
57
+
58
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: disqus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Norman Clarke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-27 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Integrates Disqus into your Ruby-powered site. Works with any Ruby website, not just Rails.
17
+ email: norman@randomba.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.txt
24
+ files:
25
+ - MIT-LICENSE
26
+ - README.textile
27
+ - README.txt
28
+ - init.rb
29
+ - lib/disqus.rb
30
+ - lib/disqus/widget.rb
31
+ - lib/disqus/rails_view_helpers.rb
32
+ - Rakefile
33
+ has_rdoc: true
34
+ homepage: http://randomba.org
35
+ post_install_message:
36
+ rdoc_options:
37
+ - --main
38
+ - README.txt
39
+ - --inline-source
40
+ - --line-numbers
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project: disqus
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Integrates Disqus commenting system into your Ruby-powered site.
62
+ test_files:
63
+ - test/widget_test.rb
64
+ - test/rails_view_helpers_test.rb