opinio 0.4.1 → 0.5
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.rdoc +7 -7
- data/app/controllers/opinio/comments_controller.rb +9 -5
- data/app/views/opinio/comments/_comment.html.erb +3 -3
- data/app/views/opinio/comments/_comment.html.haml +10 -0
- data/app/views/opinio/comments/_comments.html.erb +1 -1
- data/app/views/opinio/comments/_comments.html.haml +9 -0
- data/app/views/opinio/comments/_new.html.erb +5 -6
- data/app/views/opinio/comments/_new.html.haml +10 -0
- data/app/views/opinio/comments/create.js.erb +7 -6
- data/app/views/opinio/comments/index.html.erb +1 -1
- data/app/views/opinio/comments/index.html.haml +7 -0
- data/app/views/opinio/comments/reply.js.erb +4 -4
- data/config/locales/opinio.en.yml +16 -0
- data/lib/generators/opinio/install/templates/initializers/opinio.erb +11 -0
- data/lib/generators/opinio/views/views_generator.rb +16 -2
- data/lib/opinio.rb +13 -4
- data/lib/opinio/controllers/internal_helpers.rb +4 -0
- data/lib/opinio/opinio_model.rb +11 -7
- data/lib/opinio/opinio_subjectum.rb +1 -1
- data/lib/opinio/version.rb +1 -1
- metadata +13 -8
data/README.rdoc
CHANGED
@@ -30,15 +30,16 @@ The most common way to quickly get Opinio working is:
|
|
30
30
|
rails g opinio:install comment
|
31
31
|
|
32
32
|
This will generate the *Comment* model, migration and also generate the opinio initializer for customization of the engine.
|
33
|
-
A
|
33
|
+
A +opinio_model+ will be added on the +routes.rb+. This method adds the default urls for the model that will act as the comment
|
34
|
+
in your app.
|
34
35
|
|
35
|
-
In order to add the comments
|
36
|
+
In order to add the comments functionality to a model, you use the *opinio_subjectum* method
|
36
37
|
|
37
38
|
class Post < ActiveRecord::Base
|
38
39
|
opinio_subjectum
|
39
40
|
end
|
40
41
|
|
41
|
-
On the
|
42
|
+
On the +routes.rb+ you should simply add an +opinio+ for your resource that will have comments
|
42
43
|
|
43
44
|
resources :posts do
|
44
45
|
opinio
|
@@ -56,12 +57,12 @@ Alternatively you can render just the comments or just the form like this:
|
|
56
57
|
<%= render_comments_form @post %>
|
57
58
|
|
58
59
|
If you need to render the comments with a specific page or limit
|
59
|
-
you can use Kaminari's configurations like
|
60
|
+
you can use Kaminari's configurations like +paginates_per 10+ on your comment model
|
60
61
|
or you can customize it for specific views on the helpers
|
61
62
|
|
62
63
|
<%= render_comments @post, :page => params[:page], :limit => 5 %>
|
63
64
|
|
64
|
-
This can also be used on the
|
65
|
+
This can also be used on the +comments_for+ helper.
|
65
66
|
|
66
67
|
== Customization
|
67
68
|
|
@@ -142,8 +143,7 @@ For issues please use the github {issues tracker}[https://github.com/Draiken/opi
|
|
142
143
|
|
143
144
|
=== TODO
|
144
145
|
|
145
|
-
* Haml views
|
146
146
|
* Better controller overriding (coding and documentation)
|
147
147
|
* Support for deeper levels of replies
|
148
|
-
* Refactor the
|
148
|
+
* Refactor the +comments_for+ helper
|
149
149
|
* Extract documentation to wiki
|
@@ -10,14 +10,19 @@ class Opinio::CommentsController < ApplicationController
|
|
10
10
|
@comment = resource.comments.build(params[:comment])
|
11
11
|
@comment.owner = send(Opinio.current_user_method)
|
12
12
|
if @comment.save
|
13
|
-
|
13
|
+
flash_area = :notice
|
14
|
+
message = t('opinio.messages.comment_sent')
|
14
15
|
else
|
15
|
-
|
16
|
+
flash_area = :error
|
17
|
+
message = t('opinio.messages.comment_sending_error')
|
16
18
|
end
|
17
19
|
|
18
20
|
respond_to do |format|
|
19
21
|
format.js
|
20
|
-
format.html
|
22
|
+
format.html do
|
23
|
+
set_flash(flash_area, message)
|
24
|
+
redirect_to(resource.is_a?(Opinio.model_name.constantize) ? resource.commentable : resource)
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
@@ -26,7 +31,7 @@ class Opinio::CommentsController < ApplicationController
|
|
26
31
|
|
27
32
|
if can_destroy_opinio?(@comment)
|
28
33
|
@comment.destroy
|
29
|
-
|
34
|
+
set_flash(:notice, t('opinio.messages.comment_destroyed'))
|
30
35
|
else
|
31
36
|
#flash[:error] = I18n.translate('opinio.comment.not_permitted', :default => "Not permitted")
|
32
37
|
logger.warn "user #{send(Opinio.current_user_method)} tried to remove a comment from another user #{@comment.owner.id}"
|
@@ -38,6 +43,5 @@ class Opinio::CommentsController < ApplicationController
|
|
38
43
|
format.html { redirect_to( @comment.commentable ) }
|
39
44
|
end
|
40
45
|
end
|
41
|
-
|
42
46
|
|
43
47
|
end
|
@@ -2,12 +2,12 @@
|
|
2
2
|
<li id="comment_<%= comment.id %>">
|
3
3
|
<span>User: <%= comment.owner.id %></span>
|
4
4
|
<p>
|
5
|
-
<%= comment.body %>
|
5
|
+
<%= simple_format(comment.body) %>
|
6
6
|
</p>
|
7
|
-
<%= link_to '
|
7
|
+
<%= link_to t('opinio.actions.delete'), comment_path(comment), :method => :delete, :remote => true %>
|
8
8
|
<%# this enables only 1 level of replies %>
|
9
9
|
<% if Opinio.accept_replies && !reply %>
|
10
|
-
<span><%= link_to t(
|
10
|
+
<span><%= link_to t('opinio.actions.reply'), reply_comment_path(comment), :remote => true %></span>
|
11
11
|
<ul id="comment_<%= comment.id %>_replies" class="replies">
|
12
12
|
<%= render :partial => "opinio/comments/comment", :collection => comment.comments, :locals => {:reply => true} %>
|
13
13
|
</ul>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
- reply = defined?(reply) ? reply : false
|
2
|
+
%li{:id => "comment_#{comment.id}"}
|
3
|
+
%span User: #{comment.owner.id}
|
4
|
+
%p= simple_format(comment.body)
|
5
|
+
= link_to t('opinio.actions.delete'), comment_path(comment), :method => :delete, :remote => true
|
6
|
+
-# this enables only 1 level of replies
|
7
|
+
-if Opinio.accept_replies && !reply
|
8
|
+
%span= link_to t('opinio.actions.reply'), reply_comment_path(comment), :remote => true
|
9
|
+
%ul.replies{:id => "comment_#{comment.id}_replies"}
|
10
|
+
= render :partial => "opinio/comments/comment", :collection => comment.comments, :locals => {:reply => true}
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<% unless comments.empty? %>
|
7
7
|
<%= render :partial => 'opinio/comments/comment', :collection => comments %>
|
8
8
|
<% else %>
|
9
|
-
<li id="no_comments"><%= t
|
9
|
+
<li id="no_comments"><%= t('opinio.messages.no_comments_found') %></li>
|
10
10
|
<% end %>
|
11
11
|
</ul>
|
12
12
|
|
@@ -1,18 +1,17 @@
|
|
1
1
|
<div id="new_comment">
|
2
2
|
<% if send(Opinio.current_user_method) %>
|
3
|
-
<h3
|
4
|
-
<%= form_for Comment.new, :remote =>
|
3
|
+
<h3><%= t('opinio.messages.add_comment') %></h3>
|
4
|
+
<%= form_for Comment.new, :remote => false do |f| %>
|
5
5
|
<p>
|
6
|
-
<%= f.
|
7
|
-
<%= f.text_area :body, :id => "Comment" %>
|
6
|
+
<%= f.text_area :body %>
|
8
7
|
</p>
|
9
8
|
<%= hidden_field_tag :commentable_id, commentable.id %>
|
10
9
|
<%= hidden_field_tag :commentable_type, commentable.class.base_class.name.to_s %>
|
11
|
-
<%= f.submit
|
10
|
+
<%= f.submit t('opinio.actions.add') %>
|
12
11
|
<% end %>
|
13
12
|
<% else %>
|
14
13
|
<p>
|
15
|
-
|
14
|
+
<%= t('opinio.messages.must_be_logged_in_to_comment') %>
|
16
15
|
</p>
|
17
16
|
<% end %>
|
18
17
|
</div>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
#new_comment
|
2
|
+
- if send(Opinio.current_user_method)
|
3
|
+
%h3= t('opinio.messages.add_comment')
|
4
|
+
= form_for Comment.new, :remote => false do |f|
|
5
|
+
%p= f.text_area :body
|
6
|
+
= hidden_field_tag :commentable_id, commentable.id
|
7
|
+
= hidden_field_tag :commentable_type, commentable.class.base_class.name.to_s
|
8
|
+
= f.submit t('opinio.actions.add')
|
9
|
+
- else
|
10
|
+
%p= t('opinio.messages.must_be_logged_in_to_comment')
|
@@ -1,14 +1,15 @@
|
|
1
|
-
$('#no_comments').
|
1
|
+
$('#no_comments').hide();
|
2
2
|
<% if @comment.valid? %>
|
3
3
|
<% if @reply %>
|
4
4
|
if($('#comment_<%= @comment.commentable_id %> ul').length == 0)
|
5
|
-
$('#comment_<%= @comment.commentable_id %>').append('<ul id="comment_<%= @comment.commentable_id %>_replies" class="replies"></ul>')
|
6
|
-
$('#comment_<%= @comment.commentable_id %>_replies').append("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>")
|
7
|
-
$('#commentable_id').val('<%= @comment.commentable.commentable_id %>')
|
8
|
-
$('#commentable_type').val('<%= @comment.commentable.commentable_type %>')
|
5
|
+
$('#comment_<%= @comment.commentable_id %>').append('<ul id="comment_<%= @comment.commentable_id %>_replies" class="replies"></ul>');
|
6
|
+
$('#comment_<%= @comment.commentable_id %>_replies').append("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>");
|
7
|
+
$('#commentable_id').val('<%= @comment.commentable.commentable_id %>');
|
8
|
+
$('#commentable_type').val('<%= @comment.commentable.commentable_type %>');
|
9
9
|
<% else %>
|
10
|
-
$('#comments').prepend("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>")
|
10
|
+
$('#comments').<%= Opinio.sort_order == 'ASC' ? 'append' : 'prepend'%>("<%= escape_javascript( render @comment, :locals => {:reply => @reply} ) %>");
|
11
11
|
<% end %>
|
12
|
+
$('textarea#comment_body').val('');
|
12
13
|
<% else %>
|
13
14
|
$('#comments').prepend("<%= escape_javascript(flash[:notice]) %>");
|
14
15
|
$('#comments').prepend("<%= escape_javascript(flash[:error]) %>");
|
@@ -1,4 +1,4 @@
|
|
1
|
-
$("#commentable_id").val('<%= @commentable_id %>')
|
2
|
-
$("#commentable_type").val('<%= @commentable_type %>')
|
3
|
-
$("#new_comment textarea").val('')
|
4
|
-
$("#new_comment textarea").focus()
|
1
|
+
$("#commentable_id").val('<%= @commentable_id %>');
|
2
|
+
$("#commentable_type").val('<%= @commentable_type %>');
|
3
|
+
$("#new_comment textarea").val('');
|
4
|
+
$("#new_comment textarea").focus();
|
@@ -0,0 +1,16 @@
|
|
1
|
+
en:
|
2
|
+
opinio:
|
3
|
+
actions:
|
4
|
+
delete: 'Delete'
|
5
|
+
reply: 'Reply'
|
6
|
+
add: 'Add comment'
|
7
|
+
messages:
|
8
|
+
no_comments_found: 'No comments found'
|
9
|
+
must_be_logged_in_to_comment: 'Must be logged in to comment.'
|
10
|
+
add_comment: 'Add comment'
|
11
|
+
comments: 'Comments'
|
12
|
+
comment_sent: 'Comment sent successfully.'
|
13
|
+
comment_sending_error: 'Error while sending the comment.'
|
14
|
+
comment_destroyed: 'Comment removed successfully.'
|
15
|
+
comment_interval: 'You must wait %{time} seconds to comment again.'
|
16
|
+
cannot_be_comment_of_comment: "Cannot reply another comment's reply"
|
@@ -14,4 +14,15 @@ Opinio.setup do |config|
|
|
14
14
|
# Here you can change the method called to check who is the current user
|
15
15
|
# config.current_user_method = :current_user
|
16
16
|
|
17
|
+
# Strip html tags on save comment
|
18
|
+
config.strip_html_tags_on_save = true
|
19
|
+
|
20
|
+
# Comments sort order by created_at (DESC or ASC)
|
21
|
+
# Note: you can override that easily within each opinio subjectum
|
22
|
+
config.sort_order = 'DESC'
|
23
|
+
|
24
|
+
# Wether or not the default opinio controller should set the flash
|
25
|
+
# when creating/removing comments
|
26
|
+
config.set_flash = true
|
27
|
+
|
17
28
|
end
|
@@ -2,12 +2,26 @@ module Opinio
|
|
2
2
|
module Generators
|
3
3
|
class ViewsGenerator < Rails::Generators::Base
|
4
4
|
|
5
|
-
source_root File.expand_path('../../../../../app/views', __FILE__)
|
5
|
+
source_root File.expand_path('../../../../../app/views/opinio/comments', __FILE__)
|
6
|
+
|
7
|
+
class_option :haml, :desc => 'Generate HAML views instead of ERB.', :type => :boolean
|
6
8
|
|
7
9
|
def copy_views
|
8
|
-
|
10
|
+
html_names = ["_comment", "_comments", "_new", "index"]
|
11
|
+
js_names = ["create", "destroy", "reply"]
|
12
|
+
html_names.each do |name|
|
13
|
+
copy_file "#{name}.html.#{view_language}", "app/views/opinio/comments/#{name}.html.#{view_language}"
|
14
|
+
end
|
15
|
+
js_names.each do |name|
|
16
|
+
copy_file "#{name}.js.erb", "app/views/opinio/comments/#{name}.js.erb"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def view_language
|
21
|
+
options.haml? ? 'haml' : 'erb'
|
9
22
|
end
|
10
23
|
|
24
|
+
|
11
25
|
end
|
12
26
|
end
|
13
27
|
end
|
data/lib/opinio.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Opinio
|
2
|
-
|
2
|
+
require 'opinio/schema'
|
3
3
|
|
4
4
|
module Controllers
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
require 'opinio/controllers/helpers'
|
6
|
+
require 'opinio/controllers/internal_helpers'
|
7
|
+
require 'opinio/controllers/replies'
|
8
8
|
end
|
9
9
|
|
10
10
|
mattr_accessor :model_name
|
@@ -31,6 +31,15 @@ module Opinio
|
|
31
31
|
mattr_accessor :current_user_method
|
32
32
|
@@current_user_method = :current_user
|
33
33
|
|
34
|
+
mattr_accessor :strip_html_tags_on_save
|
35
|
+
@@strip_html_tags_on_save = true
|
36
|
+
|
37
|
+
mattr_accessor :sort_order
|
38
|
+
@@sort_order = 'DESC'
|
39
|
+
|
40
|
+
mattr_accessor :set_flash
|
41
|
+
@@set_flash = true
|
42
|
+
|
34
43
|
def self.setup
|
35
44
|
yield self
|
36
45
|
end
|
data/lib/opinio/opinio_model.rb
CHANGED
@@ -71,6 +71,11 @@ module Opinio
|
|
71
71
|
send :include, RepliesSupport
|
72
72
|
end
|
73
73
|
|
74
|
+
if Opinio.strip_html_tags_on_save
|
75
|
+
send :include, ActionView::Helpers::SanitizeHelper
|
76
|
+
before_save :strip_html_tags
|
77
|
+
end
|
78
|
+
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
@@ -93,12 +98,7 @@ module Opinio
|
|
93
98
|
if (Time.now - last_comment.created_at).round >= self.comments_interval
|
94
99
|
true
|
95
100
|
else
|
96
|
-
errors.add(
|
97
|
-
:created_at,
|
98
|
-
I18n.t('opinio.comment_interval',
|
99
|
-
:time => self.comments_interval,
|
100
|
-
:default => "You must wait %{time} seconds to comment again.")
|
101
|
-
)
|
101
|
+
errors.add(:created_at, I18n.translate('opinio.messages.comment_interval', :time => self.comments_interval))
|
102
102
|
false
|
103
103
|
end
|
104
104
|
else
|
@@ -110,11 +110,15 @@ module Opinio
|
|
110
110
|
def cannot_be_comment_of_a_comments_comment
|
111
111
|
if new_record? && self.commentable_type == Opinio.model_name
|
112
112
|
if commentable.commentable_type == Opinio.model_name
|
113
|
-
errors.add :base, I18n.
|
113
|
+
errors.add :base, I18n.t('opinio.messages,cannot_be_comment_of_comment')
|
114
114
|
end
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
|
+
def strip_html_tags
|
119
|
+
self.body = strip_tags(self.body)
|
120
|
+
end
|
121
|
+
|
118
122
|
end
|
119
123
|
end
|
120
124
|
end
|
@@ -12,7 +12,7 @@ module Opinio
|
|
12
12
|
has_many :comments,
|
13
13
|
:class_name => Opinio.model_name,
|
14
14
|
:as => :commentable,
|
15
|
-
:order => options.reverse_merge(:order => "created_at
|
15
|
+
:order => options.reverse_merge(:order => "created_at #{Opinio.sort_order}")[:order],
|
16
16
|
:dependent => :destroy
|
17
17
|
|
18
18
|
|
data/lib/opinio/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opinio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.5'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-04-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164731680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164731680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: kaminari
|
27
|
-
requirement: &
|
27
|
+
requirement: &2164881320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2164881320
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jquery-rails
|
38
|
-
requirement: &
|
38
|
+
requirement: &2165159760 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2165159760
|
47
47
|
description: Opinio is an engine used to add comments functionallity to rails 3 applications.
|
48
48
|
email:
|
49
49
|
- luiz.felipe.gp@gmail.com
|
@@ -53,11 +53,15 @@ extra_rdoc_files: []
|
|
53
53
|
files:
|
54
54
|
- app/controllers/opinio/comments_controller.rb
|
55
55
|
- app/views/opinio/comments/_comment.html.erb
|
56
|
+
- app/views/opinio/comments/_comment.html.haml
|
56
57
|
- app/views/opinio/comments/_comments.html.erb
|
58
|
+
- app/views/opinio/comments/_comments.html.haml
|
57
59
|
- app/views/opinio/comments/_new.html.erb
|
60
|
+
- app/views/opinio/comments/_new.html.haml
|
58
61
|
- app/views/opinio/comments/create.js.erb
|
59
62
|
- app/views/opinio/comments/destroy.js.erb
|
60
63
|
- app/views/opinio/comments/index.html.erb
|
64
|
+
- app/views/opinio/comments/index.html.haml
|
61
65
|
- app/views/opinio/comments/reply.js.erb
|
62
66
|
- lib/generators/opinio/install/install_generator.rb
|
63
67
|
- lib/generators/opinio/install/templates/initializers/opinio.erb
|
@@ -78,6 +82,7 @@ files:
|
|
78
82
|
- lib/opinio/shared_examples.rb
|
79
83
|
- lib/opinio/version.rb
|
80
84
|
- lib/opinio.rb
|
85
|
+
- config/locales/opinio.en.yml
|
81
86
|
- MIT-LICENSE
|
82
87
|
- Rakefile
|
83
88
|
- Gemfile-rails-3.0.x
|