disqus 0.1.0 → 0.1.1
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.textile +21 -11
- data/Rakefile +2 -2
- data/lib/disqus.rb +24 -3
- data/lib/disqus/view_helpers.rb +45 -0
- data/lib/disqus/widget.rb +37 -17
- data/test/{rails_view_helpers_test.rb → view_helpers_test.rb} +3 -3
- data/test/widget_test.rb +4 -4
- metadata +7 -8
- data/README.txt +0 -65
- data/lib/disqus/rails_view_helpers.rb +0 -31
data/README.textile
CHANGED
@@ -2,7 +2,7 @@ h1. Disqus Ruby Gem
|
|
2
2
|
|
3
3
|
The Disqus Gem helps you easily integrate the "Disqus":http://disqus.com
|
4
4
|
commenting system into your website. It works for any site programmed in Ruby,
|
5
|
-
|
5
|
+
and has view helpers for Rails and Merb.
|
6
6
|
|
7
7
|
h2. Get it
|
8
8
|
|
@@ -33,16 +33,20 @@ h3. Show the comment threads on a post page:
|
|
33
33
|
<pre>
|
34
34
|
<code>
|
35
35
|
# Loads the commenting system
|
36
|
-
Disqus::Widget::thread
|
37
|
-
# Or if you're using Rails:
|
38
36
|
disqus_thread
|
39
37
|
|
40
|
-
#
|
41
|
-
|
38
|
+
# Or if you're not using Rails/Merb:
|
39
|
+
Disqus::Widget::thread
|
40
|
+
|
41
|
+
# Sets the inner html to the comment count for any links on the page that
|
42
|
+
# have the anchor "disqus_thread". For example, "View Comments" below would
|
43
|
+
# be replaced by "1 comment" or "23 comments" etc.
|
42
44
|
# <a href="http://my.website/article-permalink#disqus_thread">View Comments</a>
|
43
|
-
|
44
|
-
# Or if you're using Rails:
|
45
|
+
# <a href="http://my.website/different-permalink#disqus_thread">View Comments</a>
|
45
46
|
disqus_comment_counts
|
47
|
+
|
48
|
+
# Or if you're not using Rails/Merb:
|
49
|
+
Disqus::Widget::comment_counts
|
46
50
|
</code>
|
47
51
|
</pre>
|
48
52
|
|
@@ -50,9 +54,10 @@ h3. Show the combo widget on a post page:
|
|
50
54
|
|
51
55
|
<pre>
|
52
56
|
<code>
|
53
|
-
Disqus::Widget::combo(:color => "blue", :hide_mods => false, :num_items => 25)
|
54
|
-
# Or if you're using Rails:
|
55
57
|
disqus_combo(:color => "blue", :hide_mods => false, :num_items => 25)
|
58
|
+
|
59
|
+
# Or for non-Rails/Merb:
|
60
|
+
Disqus::Widget::combo(:color => "blue", :hide_mods => false, :num_items => 25)
|
56
61
|
</code>
|
57
62
|
</pre>
|
58
63
|
|
@@ -62,9 +67,10 @@ h3. Show the comment count on a permalink:
|
|
62
67
|
<code>
|
63
68
|
link_to("Permalink", post_path(@post, :anchor => "disqus_thread"))
|
64
69
|
...
|
65
|
-
Disqus::Widget::comment_counts
|
66
|
-
# Or for Rails:
|
67
70
|
disqus_comment_counts
|
71
|
+
|
72
|
+
# Or for non-Rails/Merb:
|
73
|
+
Disqus::Widget::comment_counts
|
68
74
|
</code>
|
69
75
|
</pre>
|
70
76
|
|
@@ -80,5 +86,9 @@ h2. Learn more about Disqus:
|
|
80
86
|
|
81
87
|
"http://disqus.com":http://disqus.com
|
82
88
|
|
89
|
+
h2. Thanks to the following contributors:
|
90
|
+
|
91
|
+
* "Quin Hoxie":http://github.com/qhoxie - Merb support
|
92
|
+
|
83
93
|
Copyright (c) 2008 "Norman Clarke":norman@randomba.org, released under
|
84
94
|
the MIT license
|
data/Rakefile
CHANGED
@@ -38,5 +38,5 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
38
38
|
rdoc.title = 'Disqus'
|
39
39
|
rdoc.options << '--line-numbers' << '--inline-source' << '-c UTF-8'
|
40
40
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
-
rdoc.rdoc_files.include('README.
|
42
|
-
end
|
41
|
+
rdoc.rdoc_files.include('README.textile')
|
42
|
+
end
|
data/lib/disqus.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'disqus/widget'
|
2
2
|
|
3
|
-
|
4
3
|
# Disqus is a javascript embed that enhances your blog's comments and
|
5
4
|
# integrates it with a fully moderated community forum. The Disqus gem helps
|
6
5
|
# you quickly and easily integrate Disqus's widgets into your Ruby-based
|
@@ -19,18 +18,40 @@ module Disqus
|
|
19
18
|
:orientation => "horizontal"
|
20
19
|
}
|
21
20
|
|
21
|
+
# Disqus defaults:
|
22
|
+
# :account => "",
|
23
|
+
# :avatar_size => 48,
|
24
|
+
# :color => "grey",
|
25
|
+
# :default_tab => "popular",
|
26
|
+
# :hide_avatars => false,
|
27
|
+
# :hide_mods => true,
|
28
|
+
# :num_items => 15,
|
29
|
+
# :show_powered_by => true,
|
30
|
+
# :orientation => "horizontal"
|
22
31
|
def self.defaults
|
23
32
|
@defaults
|
24
33
|
end
|
25
34
|
|
35
|
+
# Load the view helpers if the gem is included in a Rails app.
|
26
36
|
def self.enable_rails
|
27
37
|
return if ActionView::Base.instance_methods.include? 'disqus_thread'
|
28
|
-
require 'disqus/
|
29
|
-
ActionView::Base.class_eval { include Disqus::
|
38
|
+
require 'disqus/view_helpers'
|
39
|
+
ActionView::Base.class_eval { include Disqus::ViewHelpers }
|
40
|
+
end
|
41
|
+
|
42
|
+
# Load the view helpers if the gem is included in a Merb app.
|
43
|
+
def self.enable_merb
|
44
|
+
return if Merb::Controller.instance_methods.include? 'disqus_thread'
|
45
|
+
require 'disqus/view_helpers'
|
46
|
+
Merb::Controller.class_eval { include Disqus::ViewHelpers }
|
30
47
|
end
|
31
48
|
|
32
49
|
end
|
33
50
|
|
34
51
|
if defined?(Rails) and defined?(ActionView)
|
35
52
|
Disqus::enable_rails
|
53
|
+
end
|
54
|
+
|
55
|
+
if defined?(Merb)
|
56
|
+
Disqus::enable_merb
|
36
57
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Disqus
|
2
|
+
|
3
|
+
# Shortcuts to access the widgets as simple functions as opposed to using
|
4
|
+
# their full qualified names. These helpers are loaded automatically in
|
5
|
+
# Rails and Merb apps.
|
6
|
+
#
|
7
|
+
# For Sinatra, Camping, Nitro or other frameworks, you can include the
|
8
|
+
# helper if you wish, or use the fully-qualified names. Really this is just
|
9
|
+
# here for aesthetic purposes and to make it less likely to step on anyone's
|
10
|
+
# namespace.
|
11
|
+
module ViewHelpers
|
12
|
+
|
13
|
+
# See Disqus::Widget.thread
|
14
|
+
def disqus_thread(options = {})
|
15
|
+
Disqus::Widget::thread(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# See Disqus::Widget.comment_counts
|
19
|
+
def disqus_comment_counts(options = {})
|
20
|
+
Disqus::Widget::comment_counts(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
# See Disqus::Widget.top_commenters
|
24
|
+
def disqus_top_commenters(options = {})
|
25
|
+
Disqus::Widget::top_commenters(options)
|
26
|
+
end
|
27
|
+
|
28
|
+
# See Disqus::Widget.popular_threads
|
29
|
+
def disqus_popular_threads(options = {})
|
30
|
+
Disqus::Widget::popular_threads(options)
|
31
|
+
end
|
32
|
+
|
33
|
+
# See Disqus::Widget.recent_comments
|
34
|
+
def disqus_recent_comments(options = {})
|
35
|
+
Disqus::Widget::recent_comments(options)
|
36
|
+
end
|
37
|
+
|
38
|
+
# See Disqus::Widget.combo
|
39
|
+
def disqus_combo(options = {})
|
40
|
+
Disqus::Widget::combo(options)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/lib/disqus/widget.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
1
|
module Disqus
|
2
2
|
|
3
|
+
# Disqus Widget generator.
|
4
|
+
#
|
5
|
+
# All of the methods accept various options, and "account" is required for
|
6
|
+
# all of them. You can avoid having to pass in the account each time by
|
7
|
+
# setting it in the defaults like this:
|
8
|
+
#
|
9
|
+
# Disqus::defaults[:account] = "my_account"
|
3
10
|
class Widget
|
4
11
|
|
5
|
-
class Error < StandardError ; end
|
6
|
-
|
7
12
|
VALID_COLORS = ['blue', 'grey', 'green', 'red', 'orange']
|
8
13
|
VALID_NUM_ITEMS = 5..20
|
9
14
|
VALID_DEFAULT_TABS = ['people', 'recent', 'popular']
|
@@ -18,7 +23,8 @@ module Disqus
|
|
18
23
|
TOP = ROOT_PATH + 'top_commenters_widget.js?num_items=%d&avatar_size=%d&orientation=%s'
|
19
24
|
class << self
|
20
25
|
|
21
|
-
# Show the main Disqus thread widget.
|
26
|
+
# Show the main Disqus thread widget.
|
27
|
+
# Options:
|
22
28
|
# * <tt>account:</tt> Your Discus account (required).
|
23
29
|
def thread(opts = {})
|
24
30
|
opts = Disqus::defaults.merge(opts)
|
@@ -36,7 +42,15 @@ module Disqus
|
|
36
42
|
s % [opts[:account], opts[:account]]
|
37
43
|
end
|
38
44
|
|
39
|
-
# Loads Javascript to show the number of comments for the page.
|
45
|
+
# Loads Javascript to show the number of comments for the page.
|
46
|
+
#
|
47
|
+
# The Javascript sets the inner html to the comment count for any links
|
48
|
+
# on the page that have the anchor "disqus_thread". For example, "View
|
49
|
+
# Comments" below would be replaced by "1 comment" or "23 comments" etc.
|
50
|
+
#
|
51
|
+
# <a href="http://my.website/article-permalink#disqus_thread">View Comments</a>
|
52
|
+
# <a href="http://my.website/different-permalink#disqus_thread">View Comments</a>
|
53
|
+
# Options:
|
40
54
|
# * <tt>account:</tt> Your Discus account (required).
|
41
55
|
def comment_counts(opts = {})
|
42
56
|
opts = Disqus::defaults.merge(opts)
|
@@ -60,7 +74,8 @@ module Disqus
|
|
60
74
|
s % opts[:account]
|
61
75
|
end
|
62
76
|
|
63
|
-
# Show the
|
77
|
+
# Show the top commenters Disqus thread widget.
|
78
|
+
# Options:
|
64
79
|
# * <tt>account:</tt> Your Discus account (required).
|
65
80
|
# * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
|
66
81
|
# * <tt>show_powered_by:</tt> Show or hide the powered by Disqus text.
|
@@ -86,7 +101,8 @@ module Disqus
|
|
86
101
|
s % [opts[:account], opts[:num_items], opts[:avatar_size], opts[:orientation]]
|
87
102
|
end
|
88
103
|
|
89
|
-
# Show the
|
104
|
+
# Show the popular threads Disqus widget.
|
105
|
+
# Options:
|
90
106
|
# * <tt>account:</tt> Your Discus account (required).
|
91
107
|
# * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
|
92
108
|
# * <tt>num_items:</tt>: How many items to show.
|
@@ -106,7 +122,8 @@ module Disqus
|
|
106
122
|
s % [opts[:account], opts[:num_items]]
|
107
123
|
end
|
108
124
|
|
109
|
-
# Show the
|
125
|
+
# Show the recent comments Disqus widget.
|
126
|
+
# Options:
|
110
127
|
# * <tt>account:</tt> Your Discus account (required).
|
111
128
|
# * <tt>header:</tt> HTML snipper with header (default h2) tag and text.
|
112
129
|
# * <tt>num_items:</tt>: How many items to show.
|
@@ -129,10 +146,13 @@ module Disqus
|
|
129
146
|
s % [opts[:account], opts[:num_items], opts[:avatar_size]]
|
130
147
|
end
|
131
148
|
|
132
|
-
# Show the
|
133
|
-
#
|
134
|
-
#
|
135
|
-
# * <tt
|
149
|
+
# Show the Disqus combo widget. This is a three-tabbed box with links
|
150
|
+
# popular threads, top posters, and recent threads.
|
151
|
+
# Options:
|
152
|
+
# * <tt>:account:</tt> Your Discus account (required).
|
153
|
+
# * <tt>:num_items:</tt> How many items to show.
|
154
|
+
# * <tt>:hide_mods:</tt> Don't show moderators.
|
155
|
+
# * <tt>:default_tab:</tt> Should be 'people', 'recent', or 'popular'.
|
136
156
|
def combo(opts = {})
|
137
157
|
opts = Disqus::defaults.merge(opts)
|
138
158
|
validate_opts!(opts)
|
@@ -146,12 +166,12 @@ module Disqus
|
|
146
166
|
private
|
147
167
|
|
148
168
|
def validate_opts!(opts)
|
149
|
-
raise
|
150
|
-
raise
|
151
|
-
raise
|
152
|
-
raise
|
153
|
-
raise
|
154
|
-
raise
|
169
|
+
raise ArgumentError.new("You must specify an :account") if !opts[:account]
|
170
|
+
raise ArgumentError.new("Invalid color") if opts[:color] && !VALID_COLORS.include?(opts[:color])
|
171
|
+
raise ArgumentError.new("Invalid num_items") if opts[:num_items] && !VALID_NUM_ITEMS.include?(opts[:num_items])
|
172
|
+
raise ArgumentError.new("Invalid default_tab") if opts[:default_tab] && !VALID_DEFAULT_TABS.include?(opts[:default_tab])
|
173
|
+
raise ArgumentError.new("Invalid avatar size") if opts[:avatar_size] && !VALID_AVATAR_SIZES.include?(opts[:avatar_size])
|
174
|
+
raise ArgumentError.new("Invalid orientation") if opts[:orientation] && !VALID_ORIENTATIONS.include?(opts[:orientation])
|
155
175
|
end
|
156
176
|
|
157
177
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'disqus'
|
3
|
-
require 'disqus/
|
3
|
+
require 'disqus/view_helpers'
|
4
4
|
|
5
|
-
class
|
5
|
+
class ViewHelpersTest < Test::Unit::TestCase
|
6
6
|
|
7
|
-
include Disqus::
|
7
|
+
include Disqus::ViewHelpers
|
8
8
|
|
9
9
|
def setup
|
10
10
|
Disqus::defaults[:account] = "tests"
|
data/test/widget_test.rb
CHANGED
@@ -32,25 +32,25 @@ class DisqusWidgetTest < Test::Unit::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_invalid_default_tab
|
35
|
-
assert_raises
|
35
|
+
assert_raises ArgumentError do
|
36
36
|
Disqus::Widget::combo(:default_tab => "test")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_invalid_color
|
41
|
-
assert_raises
|
41
|
+
assert_raises ArgumentError do
|
42
42
|
Disqus::Widget::combo(:color => "test")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_invalid_num_items
|
47
|
-
assert_raises
|
47
|
+
assert_raises ArgumentError do
|
48
48
|
Disqus::Widget::combo(:num_items => 100)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_invalid_avatar_size
|
53
|
-
assert_raises
|
53
|
+
assert_raises ArgumentError do
|
54
54
|
Disqus::Widget::top_commenters(:avatar_size => 100)
|
55
55
|
end
|
56
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disqus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -9,33 +9,32 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-03 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description: Integrates Disqus into your Ruby-powered site. Works with any Ruby website,
|
16
|
+
description: Integrates Disqus into your Ruby-powered site. Works with any Ruby website, and has view helpers for Rails and Merb.
|
17
17
|
email: norman@randomba.org
|
18
18
|
executables: []
|
19
19
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
- README.
|
23
|
+
- README.textile
|
24
24
|
files:
|
25
25
|
- MIT-LICENSE
|
26
26
|
- README.textile
|
27
|
-
- README.txt
|
28
27
|
- init.rb
|
29
28
|
- lib/disqus.rb
|
30
29
|
- lib/disqus/widget.rb
|
31
|
-
- lib/disqus/
|
30
|
+
- lib/disqus/view_helpers.rb
|
32
31
|
- Rakefile
|
33
32
|
has_rdoc: true
|
34
33
|
homepage: http://randomba.org
|
35
34
|
post_install_message:
|
36
35
|
rdoc_options:
|
37
36
|
- --main
|
38
|
-
- README.
|
37
|
+
- README.textile
|
39
38
|
- --inline-source
|
40
39
|
- --line-numbers
|
41
40
|
require_paths:
|
@@ -61,4 +60,4 @@ specification_version: 2
|
|
61
60
|
summary: Integrates Disqus commenting system into your Ruby-powered site.
|
62
61
|
test_files:
|
63
62
|
- test/widget_test.rb
|
64
|
-
- test/
|
63
|
+
- test/view_helpers_test.rb
|
data/README.txt
DELETED
@@ -1,65 +0,0 @@
|
|
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
|
@@ -1,31 +0,0 @@
|
|
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
|