Project

General

Profile

Feature #41294 » 0006-Separate-the-implementation-for-building-a-quote-into-Redmine-QuoteReply.patch

Katsuya HIDAKA, 2024-09-22 13:01

View differences:

app/controllers/journals_controller.rb
31 31
  helper :queries
32 32
  helper :attachments
33 33
  include QueriesHelper
34
  include Redmine::QuoteReply::Builder
34 35

  
35 36
  def index
36 37
    retrieve_query
......
65 66

  
66 67
  def new
67 68
    @journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
68
    if @journal
69
      user = @journal.user
70
      text = @journal.notes
71
      @content = "#{ll(Setting.default_language, :text_user_wrote_in, {:value => user, :link => "#note-#{params[:journal_indice]}"})}\n> "
72
    else
73
      user = @issue.author
74
      text = @issue.description
75
      @content = "#{ll(Setting.default_language, :text_user_wrote, user)}\n> "
76
    end
77
    # Replaces pre blocks with [...]
78
    text = params[:quote].presence || text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
79
    @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
69
    @content = if @journal
70
                 quote_issue_journal(@journal, indice: params[:journal_indice], partial_quote: params[:quote])
71
               else
72
                 quote_issue(@issue, partial_quote: params[:quote])
73
               end
80 74
  rescue ActiveRecord::RecordNotFound
81 75
    render_404
82 76
  end
app/controllers/messages_controller.rb
29 29
  helper :watchers
30 30
  helper :attachments
31 31
  include AttachmentsHelper
32
  include Redmine::QuoteReply::Builder
32 33

  
33 34
  REPLIES_PER_PAGE = 25 unless const_defined?(:REPLIES_PER_PAGE)
34 35

  
......
119 120
    @subject = @message.subject
120 121
    @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
121 122

  
122
    if @message.root == @message
123
      @content = "#{ll(Setting.default_language, :text_user_wrote, @message.author)}\n> "
124
    else
125
      @content = "#{ll(Setting.default_language, :text_user_wrote_in, {:value => @message.author, :link => "message##{@message.id}"})}\n> "
126
    end
127

  
128
    quote_text = params[:quote].presence || @message.content.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
129
    @content << quote_text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
123
    @content = if @message.root == @message
124
                 quote_root_message(@message, partial_quote: params[:quote])
125
               else
126
                 quote_message(@message, partial_quote: params[:quote])
127
               end
130 128

  
131 129
    respond_to do |format|
132 130
      format.html { render_404 }
lib/redmine/quote_reply.rb
37 37
        )
38 38
      end
39 39
    end
40

  
41
    module Builder
42
      def quote_issue(issue, partial_quote: nil)
43
        user = issue.author
44

  
45
        build_quote(
46
          "#{ll(Setting.default_language, :text_user_wrote, user)}\n> ",
47
          issue.description,
48
          partial_quote
49
        )
50
      end
51

  
52
      def quote_issue_journal(journal, indice:, partial_quote: nil)
53
        user = journal.user
54

  
55
        build_quote(
56
          "#{ll(Setting.default_language, :text_user_wrote_in, {value: journal.user, link: "#note-#{indice}"})}\n> ",
57
          journal.notes,
58
          partial_quote
59
        )
60
      end
61

  
62
      def quote_root_message(message, partial_quote: nil)
63
        build_quote(
64
          "#{ll(Setting.default_language, :text_user_wrote, message.author)}\n> ",
65
          message.content,
66
          partial_quote
67
        )
68
      end
69

  
70
      def quote_message(message, partial_quote: nil)
71
        build_quote(
72
          "#{ll(Setting.default_language, :text_user_wrote_in, {value: message.author, link: "message##{message.id}"})}\n> ",
73
          message.content,
74
          partial_quote
75
        )
76
      end
77

  
78
      private
79

  
80
      def build_quote(quote_header, text, partial_quote = nil)
81
        quote_text = partial_quote.presence || text.to_s.strip.gsub(%r{<pre>(.*?)</pre>}m, '[...]')
82

  
83
        "#{quote_header}#{quote_text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"}"
84
      end
85
    end
40 86
  end
41 87
end
(12-12/17)