diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 36952af7d..67c347ced 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -17,4 +17,4 @@ module CommentsHelper comments.select{|c| c.parent_id == parent.id} end -end \ No newline at end of file +end diff --git a/app/helpers/text_with_links_helper.rb b/app/helpers/text_with_links_helper.rb new file mode 100644 index 000000000..32ada7c72 --- /dev/null +++ b/app/helpers/text_with_links_helper.rb @@ -0,0 +1,9 @@ +module TextWithLinksHelper + + def text_with_links(text) + return unless text + sanitized = sanitize text, tags: %w(a), attributes: %w(href) + Rinku.auto_link(sanitized, :all, 'target="_blank" rel="nofollow"').html_safe + end + +end diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index a3db690a8..15a8eb54a 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -1,4 +1,5 @@ class Mailer < ApplicationMailer + helper :text_with_links def comment(comment) @comment = comment diff --git a/app/models/comment.rb b/app/models/comment.rb index 5836fa103..233736824 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -53,11 +53,6 @@ class Comment < ActiveRecord::Base self.user= author end - def body - unprocessed = super - unprocessed ? Rinku.auto_link(unprocessed, :all, 'target="_blank" rel="nofollow"').html_safe : unprocessed - end - def total_votes cached_votes_total end diff --git a/app/views/admin/comments/index.html.erb b/app/views/admin/comments/index.html.erb index ec0fddc1a..ce4bfa293 100644 --- a/app/views/admin/comments/index.html.erb +++ b/app/views/admin/comments/index.html.erb @@ -9,7 +9,7 @@
<%= comment.body %>
+<%= text_with_links comment.body %>
<% elsif comment.as_moderator? %> -<%= comment.body %>
+<%= text_with_links comment.body %>
<% elsif comment.user.official? && comment.user_id == @commentable.author_id %> - + <% elsif comment.user.official? %> -<%= comment.body %>
+<%= text_with_links comment.body %>
<% elsif comment.user_id == @commentable.author_id %> - + <% else %> -<%= comment.body %>
+<%= text_with_links comment.body %>
<% end %> <%= render 'comments/votes', comment: comment %> @@ -101,4 +101,4 @@- <%= @comment.body %> + <%= text_with_links @comment.body %>
diff --git a/app/views/mailer/reply.html.erb b/app/views/mailer/reply.html.erb index 924234f02..d006e205a 100644 --- a/app/views/mailer/reply.html.erb +++ b/app/views/mailer/reply.html.erb @@ -13,6 +13,6 @@- <%= @reply.body %> + <%= text_with_links @reply.body %>
diff --git a/app/views/moderation/comments/index.html.erb b/app/views/moderation/comments/index.html.erb index ec642077b..d18dca8e8 100644 --- a/app/views/moderation/comments/index.html.erb +++ b/app/views/moderation/comments/index.html.erb @@ -23,7 +23,7 @@ <%= comment.commentable_type.constantize.model_name.human %> <%= l comment.updated_at.to_date %> -