loudmouth 0.2.0 → 0.2.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.md +2 -2
- data/VERSION +1 -1
- data/app/controllers/loudmouth/comments_controller.rb +10 -3
- data/lib/extensions/active_record.rb +2 -1
- data/lib/generators/loudmouth/templates/comments_controller.rb +25 -11
- data/lib/generators/loudmouth/templates/comments_migration.rb +8 -2
- data/lib/generators/loudmouth/templates/loudmouth_initializer.rb +6 -0
- data/lib/loudmouth.rb +8 -2
- data/loudmouth.gemspec +2 -2
- metadata +4 -4
data/README.md
CHANGED
@@ -45,7 +45,7 @@ If you want to render comments in-line on Articles#show
|
|
45
45
|
|
46
46
|
or to render a new comment form
|
47
47
|
|
48
|
-
render_comment_form_for(@article)
|
48
|
+
render_comment_form_for(@article, @user)
|
49
49
|
|
50
50
|
## Advanced Usage
|
51
51
|
|
@@ -65,7 +65,7 @@ Any loudmouth method can be overridden. And hey...there's a generator for that!
|
|
65
65
|
|
66
66
|
rails g loudmouth:override_controller
|
67
67
|
|
68
|
-
This will install a loudmouth override controller into your application (
|
68
|
+
This will install a loudmouth override controller into your application (app/controllers/comments_controller.rb).
|
69
69
|
|
70
70
|
To activate the override controller, make sure to update all of your comments_on calls in your routes.rb file:
|
71
71
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -3,7 +3,7 @@ class Loudmouth::CommentsController < ApplicationController
|
|
3
3
|
before_filter :authenticate_user!, :except => [ :index ]
|
4
4
|
|
5
5
|
helper_method :topic, :topic_c, :topic_comment, :topic_comment_c, :user, :user_c
|
6
|
-
helper_method :new_comment_content, :validate_create, :validate_destroy
|
6
|
+
helper_method :new_comment_content, :validate_create, :validate_update, :validate_destroy
|
7
7
|
|
8
8
|
def index
|
9
9
|
@topic = topic_c.find(params[topic.foreign_key.to_sym])
|
@@ -19,6 +19,7 @@ class Loudmouth::CommentsController < ApplicationController
|
|
19
19
|
|
20
20
|
def edit
|
21
21
|
@comment = topic_c.find(params[:id])
|
22
|
+
redirect_to :back unless validate_update(@comment)
|
22
23
|
end
|
23
24
|
|
24
25
|
def create
|
@@ -46,6 +47,7 @@ class Loudmouth::CommentsController < ApplicationController
|
|
46
47
|
|
47
48
|
def update
|
48
49
|
@comment = topic_comment_c.find(params[:id])
|
50
|
+
redirect_to :back unless validate_update(@comment)
|
49
51
|
|
50
52
|
if @comment.update_attributes(params[topic_comment.to_sym])
|
51
53
|
flash[:success] = 'Comment successfully updated.'
|
@@ -129,7 +131,7 @@ class Loudmouth::CommentsController < ApplicationController
|
|
129
131
|
|
130
132
|
# The path the user is redirected to after a successful creation of a comment
|
131
133
|
def after_create_path
|
132
|
-
url_for(@
|
134
|
+
url_for(@topic)
|
133
135
|
end
|
134
136
|
|
135
137
|
# The path the user is redirected to after a successful destroy of a comment
|
@@ -146,11 +148,16 @@ class Loudmouth::CommentsController < ApplicationController
|
|
146
148
|
def validate_create(topic)
|
147
149
|
true
|
148
150
|
end
|
151
|
+
|
152
|
+
# Used to validate that the current user can update an existing comment
|
153
|
+
# Override to provide application specific commenting validation
|
154
|
+
def validate_update(comment)
|
155
|
+
true
|
156
|
+
end
|
149
157
|
|
150
158
|
# Used to validate that the current user can destroy the comment.
|
151
159
|
# Override to provide application specific validation
|
152
160
|
def validate_destroy(comment)
|
153
|
-
|
154
161
|
# Check if there are corresponding instance variables for
|
155
162
|
# topic and user. If so attempt to validate with those.
|
156
163
|
# Otherwise, this function can be overridden.
|
@@ -5,7 +5,8 @@ module LoudmouthExtension
|
|
5
5
|
|
6
6
|
module ClassMethods
|
7
7
|
def loudmouths_can_comment(options = {})
|
8
|
-
has_many :comments, :class_name => "#{self.name}Comment", :
|
8
|
+
has_many :comments, :class_name => "#{self.name}Comment", :include => [ :author ],
|
9
|
+
:dependent => :destroy, :order => 'created_at DESC'
|
9
10
|
send :include, InstanceMethods
|
10
11
|
end
|
11
12
|
end
|
@@ -6,8 +6,8 @@ class CommentsController < Loudmouth::CommentsController
|
|
6
6
|
|
7
7
|
#
|
8
8
|
# You can override any method in the Loudmouth::CommentsController.
|
9
|
-
#
|
10
|
-
# and then call super to pass control to the original index method.
|
9
|
+
# As an example, here we override index to locate and declare additional instance variables
|
10
|
+
# and then call super to pass control to the original loudmouth index method.
|
11
11
|
#
|
12
12
|
# def index
|
13
13
|
# if topic.to_sym == :game
|
@@ -34,14 +34,14 @@ class CommentsController < Loudmouth::CommentsController
|
|
34
34
|
# Paths
|
35
35
|
################
|
36
36
|
|
37
|
-
# The path the user is redirected to after a successful
|
38
|
-
# def
|
37
|
+
# The path the user is redirected to after a successful creation of a comment
|
38
|
+
# def after_create_path
|
39
39
|
# url_for(@topic)
|
40
40
|
# end
|
41
41
|
|
42
|
-
# The path the user is redirected to after a successful
|
43
|
-
# def
|
44
|
-
# url_for(@
|
42
|
+
# The path the user is redirected to after a successful update of a comment
|
43
|
+
# def after_update_path
|
44
|
+
# url_for(@topic)
|
45
45
|
# end
|
46
46
|
|
47
47
|
# The path the user is redirected to after a successful destroy of a comment
|
@@ -56,7 +56,19 @@ class CommentsController < Loudmouth::CommentsController
|
|
56
56
|
# Used to validate that the current user can comment on topic.
|
57
57
|
# Override to provide application specific commenting validation
|
58
58
|
# def validate_create(topic)
|
59
|
-
#
|
59
|
+
# [ code to determine if the current user is authorized to comment on 'topic' ]
|
60
|
+
# [ set a flash message to diplay to the user in fail conditions ]
|
61
|
+
# flash[:error] = 'You're not authorized to comment here.'
|
62
|
+
# return true/false
|
63
|
+
# end
|
64
|
+
|
65
|
+
# Used to validate that the current user can update an existing comment
|
66
|
+
# Override to provide application specific commenting validation
|
67
|
+
# def validate_update(comment)
|
68
|
+
# [ code to determine if the current user is authorized to update 'comment' ]
|
69
|
+
# [ set a flash message to diplay to the user in fail conditions ]
|
70
|
+
# flash[:error] = 'You're not authorized to edit this comment.'
|
71
|
+
# return true/false
|
60
72
|
# end
|
61
73
|
|
62
74
|
# Used to validate that the current user can destroy the comment.
|
@@ -64,15 +76,17 @@ class CommentsController < Loudmouth::CommentsController
|
|
64
76
|
# Return true or false to indicate whether the current user is authorized to do so.
|
65
77
|
#
|
66
78
|
# def validate_destroy(comment)
|
67
|
-
# [ code to determine if the current user is authorized to destroy comment ]
|
79
|
+
# [ code to determine if the current user is authorized to destroy 'comment' ]
|
80
|
+
# [ set a flash message to diplay to the user in fail conditions ]
|
81
|
+
# flash[:error] = 'You're not authorized to delete this comment.'
|
68
82
|
# return true/false
|
69
83
|
# end
|
70
84
|
|
71
85
|
######################
|
72
|
-
#
|
86
|
+
# Other Routines
|
73
87
|
######################
|
74
88
|
#
|
75
|
-
# You can have a dynamic layout specified under the conditions
|
89
|
+
# You can have a dynamic layout specified under the conditions you define below.
|
76
90
|
#
|
77
91
|
# def determine_layout
|
78
92
|
# if params.has_key?(:profile_id)
|
@@ -2,14 +2,20 @@ class Create<%= topic_model.camelize %>Comments < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table :<%= topic_model.downcase %>_comments do |t|
|
4
4
|
t.references :parent
|
5
|
-
t.integer :<%= topic_model.downcase %>
|
6
|
-
t.integer :author_<%= user_model.downcase %>
|
5
|
+
t.integer :<%= topic_model.downcase.foreign_key %>
|
6
|
+
t.integer :author_<%= user_model.downcase.foreign_key %>
|
7
7
|
t.text :content
|
8
8
|
t.timestamps
|
9
9
|
end
|
10
|
+
add_index :<%= topic_model.downcase %>_comments, :<%= topic_model.downcase.foreign_key %>
|
11
|
+
add_index :<%= topic_model.downcase %>_comments, :author_<%= user_model.downcase.foreign_key %>
|
12
|
+
add_index :<%= topic_model.downcase %>_comments, :parent_id
|
10
13
|
end
|
11
14
|
|
12
15
|
def self.down
|
16
|
+
remove_index :<%= topic_model.downcase %>_comments, :parent_id
|
17
|
+
remove_index :<%= topic_model.downcase %>_comments, :author_<%= user_model.downcase.foreign_key %>
|
18
|
+
remove_index :<%= topic_model.downcase %>_comments, :<%= topic_model.downcase.foreign_key %>
|
13
19
|
drop_table :<%= topic_model.downcase %>_comments
|
14
20
|
end
|
15
21
|
end
|
@@ -5,5 +5,11 @@ Loudmouth.setup do |config|
|
|
5
5
|
|
6
6
|
# Default comment text for the new comment form
|
7
7
|
config.new_comment_content = "Enter new Comment..."
|
8
|
+
|
9
|
+
# How many minutes before a user can post a subsequent comment (rate limiting)
|
10
|
+
config.rate_limit_cooldown = 1
|
11
|
+
|
12
|
+
# Allow anonymous commenting?
|
13
|
+
config.allow_anonymous = false
|
8
14
|
end
|
9
15
|
|
data/lib/loudmouth.rb
CHANGED
@@ -12,14 +12,20 @@ module Loudmouth
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
mattr_accessor :treasure_map
|
16
|
+
@@treasure_map = {}
|
17
|
+
|
15
18
|
mattr_accessor :use_layout
|
16
19
|
@@use_layout = ''
|
17
20
|
|
18
21
|
mattr_accessor :new_comment_content
|
19
22
|
@@new_comment_content = ''
|
23
|
+
|
24
|
+
mattr_accessor :allow_anonymous
|
25
|
+
@@allow_anonymous = false
|
20
26
|
|
21
|
-
mattr_accessor :
|
22
|
-
@@
|
27
|
+
mattr_accessor :rate_limit_cooldown
|
28
|
+
@@rate_limit_cooldown = 1
|
23
29
|
|
24
30
|
def self.setup
|
25
31
|
yield self
|
data/loudmouth.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{loudmouth}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Peter Giacomo Lombardo}]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-20}
|
13
13
|
s.description = %q{Loudmouth adds commenting to one or many of your models.}
|
14
14
|
s.email = %q{pglombardo@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loudmouth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter Giacomo Lombardo
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-20 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: acts_as_tree
|