Skip to content

Commit fd6af99

Browse files
committed
Inline all plain text attachments
Not only patches.
1 parent ece11e3 commit fd6af99

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

app/models/attachment.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ class Attachment < ApplicationRecord
55
after_create :mark_topic_has_attachments
66
after_destroy :update_topic_has_attachments
77

8+
# This list is in no way comprehensive. It can be extended as needed.
9+
TEXT_APPLICATION_TYPES = %w[
10+
application/json
11+
application/sql
12+
application/x-perl
13+
application/x-python
14+
application/x-ruby
15+
application/x-sh
16+
application/x-shellscript
17+
application/xml
18+
application/yaml
19+
].freeze
20+
21+
def text?
22+
return true if content_type&.start_with?('text/')
23+
return true if content_type&.end_with?('+xml', '+json')
24+
TEXT_APPLICATION_TYPES.include?(content_type)
25+
end
26+
827
def patch?
928
patch_extension? || patch_content?
1029
end

app/views/topics/_message.html.slim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@
8080
pre.attachment-content
8181
code.language-diff data-controller="diff-highlight"
8282
= attachment.decoded_body_utf8
83+
- elsif attachment.text?
84+
details.attachment
85+
summary.attachment-info
86+
span.attachment-summary-row
87+
span.filename = attachment.file_name
88+
span.content-type = attachment.content_type if attachment.content_type
89+
= link_to "Download", attachment_path(attachment), class: "attachment-download", download: attachment.file_name, data: { turbo: false }
90+
pre.attachment-content
91+
code
92+
= attachment.decoded_body_utf8
8393
- else
8494
.attachment
8595
.attachment-info

0 commit comments

Comments
 (0)