[Comments] Remove quoted response

This commit is contained in:
Earlopain 2023-04-03 00:10:28 +02:00
parent 2979c9623d
commit 580776ca81
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
4 changed files with 0 additions and 66 deletions

View File

@ -30,7 +30,6 @@ class CommentsController < ApplicationController
def new
@comment = Comment.new(comment_params(:create))
@comment.body = Comment.find(params[:id]).quoted_response if params[:id]
respond_with(@comment)
end

View File

@ -1,34 +0,0 @@
class DText
def self.quote(message, creator_name)
stripped_body = DText.strip_blocks(message, "quote")
"[quote]\n#{creator_name} said:\n\n#{stripped_body}\n[/quote]\n\n"
end
def self.strip_blocks(string, tag)
n = 0
stripped = ""
string = string.dup
string.gsub!(/\s*\[#{tag}\](?!\])\s*/mi, "\n\n[#{tag}]\n\n")
string.gsub!(/\s*\[\/#{tag}\]\s*/mi, "\n\n[/#{tag}]\n\n")
string.gsub!(/(?:\r?\n){3,}/, "\n\n")
string.strip!
string.split(/\n{2}/).each do |block|
case block
when "[#{tag}]"
n += 1
when "[/#{tag}]"
n -= 1
else
if n == 0
stripped << "#{block}\n\n"
end
end
end
stripped.strip
end
end

View File

@ -216,8 +216,4 @@ class Comment < ApplicationRecord
def unhide!
update(is_hidden: false)
end
def quoted_response
DText.quote(body, creator_name)
end
end

View File

@ -218,33 +218,6 @@ class CommentTest < ActiveSupport::TestCase
end
end
context "that is quoted" do
should "strip [quote] tags correctly" do
comment = create(:comment, body: <<-EOS.strip_heredoc)
paragraph one
[quote]
somebody said:
blah blah blah
[/QUOTE]
paragraph two
EOS
assert_equal(<<-EOS.strip_heredoc, comment.quoted_response)
[quote]
#{comment.creator_name} said:
paragraph one
paragraph two
[/quote]
EOS
end
end
context "on a comment locked post" do
setup do
@post = create(:post, is_comment_disabled: true)