Skip to content

Commit 888271b

Browse files
committed
Extract _attachment partial
1 parent 4694cf8 commit 888271b

File tree

2 files changed

+50
-51
lines changed

2 files changed

+50
-51
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<% if attachment.content_type&.start_with?('image/') %>
2+
<div class="space-y-2">
3+
<div class="flex items-center gap-3 text-sm">
4+
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
5+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
6+
</svg>
7+
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
8+
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %>)</span>
9+
</div>
10+
<%= image_tag rails_blob_path(attachment), class: "max-w-full h-auto rounded border border-gray-300 dark:border-gray-600", alt: attachment.filename.to_s %>
11+
</div>
12+
<% elsif attachment.content_type&.start_with?('text/') %>
13+
<div class="space-y-2">
14+
<div class="flex items-center gap-3 text-sm">
15+
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
16+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
17+
</svg>
18+
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
19+
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %>, <%= attachment.content_type %>)</span>
20+
</div>
21+
<% if attachment.byte_size < 100_000 %>
22+
<pre class="whitespace-pre-wrap font-mono text-sm text-gray-800 dark:text-gray-300 bg-gray-100 dark:bg-gray-800 p-4 rounded border border-gray-300 dark:border-gray-600 overflow-x-auto"><%= attachment.download %></pre>
23+
<% end %>
24+
</div>
25+
<% elsif attachment.content_type == 'application/pdf' %>
26+
<div class="flex items-center gap-3 text-sm">
27+
<svg class="w-4 h-4 text-red-500 dark:text-red-400 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
28+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path>
29+
</svg>
30+
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
31+
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %>, PDF)</span>
32+
</div>
33+
<% elsif attachment.content_type&.match?(/zip|tar|gzip|compress|bzip|lha/) %>
34+
<div class="flex items-center gap-3 text-sm">
35+
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
36+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 19a2 2 0 01-2-2V7a2 2 0 012-2h4l2 2h4a2 2 0 012 2v1M5 19h14a2 2 0 002-2v-5a2 2 0 00-2-2H9a2 2 0 00-2 2v5a2 2 0 01-2 2z"></path>
37+
</svg>
38+
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
39+
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %>, Archive)</span>
40+
</div>
41+
<% else %>
42+
<div class="flex items-center gap-3 text-sm">
43+
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
44+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path>
45+
</svg>
46+
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
47+
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %><% if attachment.content_type %>, <%= attachment.content_type %><% end %>)</span>
48+
</div>
49+
<% end %>

app/views/messages/_message.html.erb

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,57 +28,7 @@
2828
<div class="border-t border-gray-200 dark:border-gray-700 px-6 py-4 bg-gray-50 dark:bg-gray-900">
2929
<h3 class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-3">Attachments (<%= message.attachments.count %>)</h3>
3030
<div class="space-y-4">
31-
<% message.attachments.each do |attachment| %>
32-
<% if attachment.content_type&.start_with?('image/') %>
33-
<div class="space-y-2">
34-
<div class="flex items-center gap-3 text-sm">
35-
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
36-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
37-
</svg>
38-
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
39-
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %>)</span>
40-
</div>
41-
<%= image_tag rails_blob_path(attachment), class: "max-w-full h-auto rounded border border-gray-300 dark:border-gray-600", alt: attachment.filename.to_s %>
42-
</div>
43-
<% elsif attachment.content_type&.start_with?('text/') %>
44-
<div class="space-y-2">
45-
<div class="flex items-center gap-3 text-sm">
46-
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
47-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
48-
</svg>
49-
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
50-
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %>, <%= attachment.content_type %>)</span>
51-
</div>
52-
<% if attachment.byte_size < 100_000 %>
53-
<pre class="whitespace-pre-wrap font-mono text-sm text-gray-800 dark:text-gray-300 bg-gray-100 dark:bg-gray-800 p-4 rounded border border-gray-300 dark:border-gray-600 overflow-x-auto"><%= attachment.download %></pre>
54-
<% end %>
55-
</div>
56-
<% elsif attachment.content_type == 'application/pdf' %>
57-
<div class="flex items-center gap-3 text-sm">
58-
<svg class="w-4 h-4 text-red-500 dark:text-red-400 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
59-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z"></path>
60-
</svg>
61-
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
62-
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %>, PDF)</span>
63-
</div>
64-
<% elsif attachment.content_type&.match?(/zip|tar|gzip|compress|bzip|lha/) %>
65-
<div class="flex items-center gap-3 text-sm">
66-
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
67-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 19a2 2 0 01-2-2V7a2 2 0 012-2h4l2 2h4a2 2 0 012 2v1M5 19h14a2 2 0 002-2v-5a2 2 0 00-2-2H9a2 2 0 00-2 2v5a2 2 0 01-2 2z"></path>
68-
</svg>
69-
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
70-
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %>, Archive)</span>
71-
</div>
72-
<% else %>
73-
<div class="flex items-center gap-3 text-sm">
74-
<svg class="w-4 h-4 text-gray-400 dark:text-gray-500 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
75-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"></path>
76-
</svg>
77-
<%= link_to attachment.filename.to_s, rails_blob_path(attachment, disposition: "attachment"), class: "text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300 font-medium" %>
78-
<span class="text-gray-500 dark:text-gray-400">(<%= number_to_human_size(attachment.byte_size) %><% if attachment.content_type %>, <%= attachment.content_type %><% end %>)</span>
79-
</div>
80-
<% end %>
81-
<% end %>
31+
<%= render partial: 'messages/attachment', collection: message.attachments %>
8232
</div>
8333
</div>
8434
<% end %>

0 commit comments

Comments
 (0)