Feature #41294 » 0006-Separate-the-implementation-for-building-a-quote-into-Redmine-QuoteReply.patch
| app/controllers/journals_controller.rb | ||
|---|---|---|
|
helper :queries
|
||
|
helper :attachments
|
||
|
include QueriesHelper
|
||
|
include Redmine::QuoteReply::Builder
|
||
|
def index
|
||
|
retrieve_query
|
||
| ... | ... | |
|
def new
|
||
|
@journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
|
||
|
if @journal
|
||
|
user = @journal.user
|
||
|
text = @journal.notes
|
||
|
@content = "#{ll(Setting.default_language, :text_user_wrote_in, {:value => user, :link => "#note-#{params[:journal_indice]}"})}\n> "
|
||
|
else
|
||
|
user = @issue.author
|
||
|
text = @issue.description
|
||
|
@content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
||
|
end
|
||
|
# Replaces pre blocks with [...]
|
||
|
text = params[:quote].presence || text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
|
||
|
@content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||
|
@content = if @journal
|
||
|
quote_issue_journal(@journal, indice: params[:journal_indice], partial_quote: params[:quote])
|
||
|
else
|
||
|
quote_issue(@issue, partial_quote: params[:quote])
|
||
|
end
|
||
|
rescue ActiveRecord::RecordNotFound
|
||
|
render_404
|
||
|
end
|
||
| app/controllers/messages_controller.rb | ||
|---|---|---|
|
helper :watchers
|
||
|
helper :attachments
|
||
|
include AttachmentsHelper
|
||
|
include Redmine::QuoteReply::Builder
|
||
|
REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
|
||
| ... | ... | |
|
@subject = @message.subject
|
||
|
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||
|
if @message.root == @message
|
||
|
@content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> "
|
||
|
else
|
||
|
@content = "#{ll(Setting.default_language, :text_user_wrote_in, {:value => @message.author, :link => "message##{@message.id}"})}\n> "
|
||
|
end
|
||
|
quote_text = params[:quote].presence || @message.content.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
|
||
|
@content << quote_text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||
|
@content = if @message.root == @message
|
||
|
quote_root_message(@message, partial_quote: params[:quote])
|
||
|
else
|
||
|
quote_message(@message, partial_quote: params[:quote])
|
||
|
end
|
||
|
respond_to do |format|
|
||
|
format.html { render_404 }
|
||
| lib/redmine/quote_reply.rb | ||
|---|---|---|
|
)
|
||
|
end
|
||
|
end
|
||
|
module Builder
|
||
|
def quote_issue(issue, partial_quote: nil)
|
||
|
user = issue.author
|
||
|
build_quote(
|
||
|
"#{ll(Setting.default_language, :text_user_wrote, user)}\n> ",
|
||
|
issue.description,
|
||
|
partial_quote
|
||
|
)
|
||
|
end
|
||
|
def quote_issue_journal(journal, indice:, partial_quote: nil)
|
||
|
user = journal.user
|
||
|
build_quote(
|
||
|
"#{ll(Setting.default_language, :text_user_wrote_in, {value: journal.user, link: "#note-#{indice}"})}\n> ",
|
||
|
journal.notes,
|
||
|
partial_quote
|
||
|
)
|
||
|
end
|
||
|
def quote_root_message(message, partial_quote: nil)
|
||
|
build_quote(
|
||
|
"#{ll(Setting.default_language, :text_user_wrote, message.author)}\n> ",
|
||
|
message.content,
|
||
|
partial_quote
|
||
|
)
|
||
|
end
|
||
|
def quote_message(message, partial_quote: nil)
|
||
|
build_quote(
|
||
|
"#{ll(Setting.default_language, :text_user_wrote_in, {value: message.author, link: "message##{message.id}"})}\n> ",
|
||
|
message.content,
|
||
|
partial_quote
|
||
|
)
|
||
|
end
|
||
|
private
|
||
|
def build_quote(quote_header, text, partial_quote = nil)
|
||
|
quote_text = partial_quote.presence || text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
|
||
|
"#{quote_header}#{quote_text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"}"
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||