Better loading of attached images
authorHerve Saint-Amand <git@saintamh.org>
Sun, 1 Jan 2017 22:11:56 +0000 (22:11 +0000)
committerHerve Saint-Amand <git@saintamh.org>
Sun, 1 Jan 2017 22:11:56 +0000 (22:11 +0000)
Got rid of that big ugly base64 blob which was only a temporary crutch anyway. Added a png file instead. Use File.read rather than File.open for a 66% reduction in verbosity.

app/assets/images/osm_logo_30.png [new file with mode: 0644]
app/models/notifier.rb
app/views/notifier/changeset_comment_notification.html.erb

diff --git a/app/assets/images/osm_logo_30.png b/app/assets/images/osm_logo_30.png
new file mode 100644 (file)
index 0000000..c963f4f
Binary files /dev/null and b/app/assets/images/osm_logo_30.png differ
index ea10eeb..bfcdc49 100644 (file)
@@ -173,15 +173,8 @@ class Notifier < ActionMailer::Base
                   I18n.t("notifier.changeset_comment_notification.commented.subject_other", :commenter => @commenter)
                 end
 
-      attachments.inline['osm_logo_30x30.png'] = {
-        mime_type: 'image/png',
-        encoding: 'base64',
-        content: @@osm_logo_png_bytes,
-      }
-
-      File.open(user_avatar_file_path(comment.author), 'rb') do |file|
-        attachments.inline['avatar.png'] = file.read()
-      end
+      attachments.inline['logo.png'] = File.read(Rails.root.join('app', 'assets', 'images', 'osm_logo_30.png'))
+      attachments.inline['avatar.png'] = File.read(user_avatar_file_path(comment.author))
 
       mail :to => recipient.email, :subject => subject
     end
@@ -216,59 +209,4 @@ class Notifier < ActionMailer::Base
     end
   end
 
-  # FIXME - 2016-12-28 - saintamh - someone please show me a better way to
-  # include this blob in here. If I save it under app/assets, how do I get a
-  # path to it in a portable way?
-  @@osm_logo_png_bytes = <<EOS
-iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAABGdBTUEAALGPC/xhBQAAAAFzUkdC
-AK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dE
-AP8A/wD/oL2nkwAAAAlwSFlzAAAbrwAAG68BXhqRHAAACchJREFUS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vO+S6QAPkjoPJrkt0LjzHe3km/txE7Zw5MjPiXo1BmH2yYRVQ/yvLsamert7ljctRdvnGf
-tLPM/yB5dPS/Qv7bx7WxacaGagz6fWlPTjaUYA6kFRi/Xpbl0tbmVr/VrOv9tXV6Kw/+t3r/Z33R
-anbsmSfPc2k0mwFgyqL0W5sbZRRFPLy/9P8G/EL/DvwpHPAlnJG4AAAAJXRFWHRkYXRlOmNyZWF0
-ZQAyMDE2LTA5LTI3VDE2OjM0OjA2KzAxOjAwiYFarwAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNi0w
-OS0yN1QxNjozMzo0MSswMTowMFvtyR4AAAAASUVORK5CYII=
-EOS
-
 end
index 8895f83..d7bedad 100644 (file)
@@ -11,7 +11,7 @@
             <tr>
               <td style="width: 30px; padding: 10px">
                 <a href="<%= @root_url %>" target="_blank">
-                  <%= image_tag attachments["osm_logo_30x30.png"].url, alt: "OpenStreetMap logo", title: "OpenStreetMap", height: "30", width: "30", border: "0" %>
+                  <%= image_tag attachments["logo.png"].url, alt: "OpenStreetMap logo", title: "OpenStreetMap", height: "30", width: "30", border: "0" %>
                 </a>
               </td>
               <td style="padding: 10px 0px">