loudmouth 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/controllers/loudmouth/comments_controller.rb +33 -1
- data/app/helpers/comments_helper.rb +0 -4
- data/app/views/loudmouth/comments/_comment.html.haml +1 -3
- data/lib/extensions/helper.rb +3 -2
- data/lib/generators/loudmouth/templates/comments_controller.rb +9 -0
- data/lib/generators/loudmouth/templates/loudmouth_initializer.rb +10 -0
- data/lib/loudmouth.rb +6 -0
- data/loudmouth.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class Loudmouth::CommentsController < ApplicationController
|
2
|
+
include ActionView::Helpers::SanitizeHelper
|
2
3
|
layout Loudmouth.use_layout if Loudmouth.use_layout.length > 0
|
3
4
|
before_filter :authenticate_user!, :except => [ :index ]
|
4
5
|
|
@@ -25,11 +26,20 @@ class Loudmouth::CommentsController < ApplicationController
|
|
25
26
|
def create
|
26
27
|
@topic = topic_c.find(params[topic_comment.to_sym][topic.foreign_key.to_sym])
|
27
28
|
|
28
|
-
|
29
|
+
# Run create validations
|
30
|
+
redirect_to :back and return unless validate_create(@topic)
|
31
|
+
|
32
|
+
# Sanitize comment content
|
33
|
+
params[topic_comment.to_sym][:content] = sanitize params[topic_comment.to_sym][:content]
|
29
34
|
|
30
35
|
@comment = topic_comment_c.new(params[topic_comment.to_sym])
|
36
|
+
|
37
|
+
# Run comment validations
|
38
|
+
redirect_to :back and return unless validate_comment(@comment)
|
39
|
+
|
31
40
|
@user = user_c.find(params[topic_comment.to_sym][('author_' + user.foreign_key).to_sym])
|
32
41
|
|
42
|
+
# Make sure the default comment text isn't being posted
|
33
43
|
if params[topic_comment.to_sym][:content] == new_comment_content()
|
34
44
|
flash[:error] = new_comment_content().
|
35
45
|
redirect_to :back
|
@@ -48,6 +58,11 @@ class Loudmouth::CommentsController < ApplicationController
|
|
48
58
|
def update
|
49
59
|
@comment = topic_comment_c.find(params[:id])
|
50
60
|
redirect_to :back unless validate_update(@comment)
|
61
|
+
|
62
|
+
@topic = topic_c.find(params[topic_comment.to_sym][topic.foreign_key.to_sym])
|
63
|
+
|
64
|
+
tmp_comment = topic_comment_c.new(params[topic_comment.to_sym])
|
65
|
+
redirect_to :back unless validate_comment(tmp_comment)
|
51
66
|
|
52
67
|
if @comment.update_attributes(params[topic_comment.to_sym])
|
53
68
|
flash[:success] = 'Comment successfully updated.'
|
@@ -60,6 +75,7 @@ class Loudmouth::CommentsController < ApplicationController
|
|
60
75
|
|
61
76
|
def destroy
|
62
77
|
@comment = topic_comment_c.find(params[:id])
|
78
|
+
@topic = topic_c.find(params[topic.foreign_key.to_sym])
|
63
79
|
|
64
80
|
if validate_destroy(@comment)
|
65
81
|
@comment.destroy
|
@@ -142,6 +158,22 @@ class Loudmouth::CommentsController < ApplicationController
|
|
142
158
|
######################
|
143
159
|
# Validation Routines
|
144
160
|
######################
|
161
|
+
|
162
|
+
# Used to validate comments
|
163
|
+
# Override to provide application specific comment validation
|
164
|
+
def validate_comment(comment)
|
165
|
+
if comment.content.length < Loudmouth.min_comment_length
|
166
|
+
flash[:error] = "Comments must be at least #{Loudmouth.min_comment_length} characters in length."
|
167
|
+
return false
|
168
|
+
end
|
169
|
+
|
170
|
+
if Loudmouth.max_comment_length > 0 and
|
171
|
+
comment.content.length > Loudmouth.max_comment_length
|
172
|
+
flash[:error] = "Comments cannot be more than #{Loudmouth.max_comment_length} characters in length."
|
173
|
+
return false
|
174
|
+
end
|
175
|
+
true
|
176
|
+
end
|
145
177
|
|
146
178
|
# Used to validate that the current user can comment on topic.
|
147
179
|
# Override to provide application specific commenting validation
|
@@ -1,9 +1,7 @@
|
|
1
1
|
%table{ :style => 'background: #fff; border: 1px solid #ccc;' }
|
2
2
|
%tr{ :style => 'border: 1px solid #ccc; padding: 5px;' }
|
3
3
|
%td{ :style => 'border: 1px solid #ccc; padding: 5px;' }
|
4
|
-
|
5
|
-
- cc = simple_format(comment.content)
|
6
|
-
= auto_link(cc).html_safe
|
4
|
+
= simple_format auto_link sanitize comment.content
|
7
5
|
%tr{ :style => 'border: 1px solid #ccc; padding: 5px;' }
|
8
6
|
%th{ :style => 'background: #eee; text-align: right; font-size: 80%;' }
|
9
7
|
== Posted #{time_ago_in_words(comment.created_at)} ago
|
data/lib/extensions/helper.rb
CHANGED
@@ -21,8 +21,9 @@ module Loudmouth
|
|
21
21
|
unless Loudmouth.treasure_map.has_key?(topic.class.name.underscore.to_sym)
|
22
22
|
raise "loudmouth not setup for #{topic.class.name.underscore.downcase.to_sym}"
|
23
23
|
end
|
24
|
-
|
25
|
-
render :partial => 'loudmouth/comments/comment', :collection => topic.comments,
|
24
|
+
|
25
|
+
render :partial => 'loudmouth/comments/comment', :collection => topic.comments,
|
26
|
+
:locals => { :topic => topic }
|
26
27
|
end
|
27
28
|
|
28
29
|
def topic_comment_path(topic)
|
@@ -53,6 +53,15 @@ class CommentsController < Loudmouth::CommentsController
|
|
53
53
|
# Validation Routines
|
54
54
|
######################
|
55
55
|
|
56
|
+
# Used to validate comments
|
57
|
+
# Override to provide application specific comment validation
|
58
|
+
# def validate_comment(comment)
|
59
|
+
# [ code to determine if the comment is valid ]
|
60
|
+
# [ set a flash message to diplay to the user in fail conditions ]
|
61
|
+
# flash[:error] = 'Comment cannot be...'
|
62
|
+
# return true/false
|
63
|
+
# end
|
64
|
+
|
56
65
|
# Used to validate that the current user can comment on topic.
|
57
66
|
# Override to provide application specific commenting validation
|
58
67
|
# def validate_create(topic)
|
@@ -11,5 +11,15 @@ Loudmouth.setup do |config|
|
|
11
11
|
|
12
12
|
# Allow anonymous commenting?
|
13
13
|
config.allow_anonymous = false
|
14
|
+
|
15
|
+
# Smallest comment length allowed
|
16
|
+
# 0 for unlimited
|
17
|
+
config.min_comment_length = 2
|
18
|
+
|
19
|
+
# Largest comment length allowed
|
20
|
+
# 0 for unlimited
|
21
|
+
config.max_comment_length = 0
|
22
|
+
|
23
|
+
|
14
24
|
end
|
15
25
|
|
data/lib/loudmouth.rb
CHANGED
@@ -26,6 +26,12 @@ module Loudmouth
|
|
26
26
|
|
27
27
|
mattr_accessor :rate_limit_cooldown
|
28
28
|
@@rate_limit_cooldown = 1
|
29
|
+
|
30
|
+
mattr_accessor :min_comment_length
|
31
|
+
@@min_comment_length = 2
|
32
|
+
|
33
|
+
mattr_accessor :max_comment_length
|
34
|
+
@@max_comment_length = 0
|
29
35
|
|
30
36
|
def self.setup
|
31
37
|
yield self
|
data/loudmouth.gemspec
CHANGED
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 2
|
10
|
+
version: 0.2.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter Giacomo Lombardo
|