InlineAttachment 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +10 -1
  2. data/lib/inline_attachment.rb +51 -4
  3. metadata +3 -3
data/README CHANGED
@@ -21,6 +21,8 @@ config/environment.rb:
21
21
 
22
22
  == Usage
23
23
 
24
+ ==== Embed Images Manually
25
+
24
26
  The code to add inline attachments into your HTML emails is pretty simple:
25
27
 
26
28
  @cid = Time.now.to_f.to_s + "foobar.png@domain.com"
@@ -36,4 +38,11 @@ The instance variable @cid is the unique identifier your MIME email will be usin
36
38
  locate the attached image. All you have to do is then pass it over to your email
37
39
  template, and display it like so:
38
40
 
39
- <img src="cid:<%= @cid %>" alt="Foo Bar" />
41
+ <img src="cid:<%= @cid %>" alt="Foo Bar" />
42
+
43
+ ==== Embed Images Automatically
44
+
45
+ As of version 0.2.0, Inline Attachment automatically embeds any images found within
46
+ your ActionMailer templates. There is no longer any extra code required when adding images
47
+ into your mail templates. Though, you must use rails image_tag helper when displaying
48
+ images within your mailer views.
@@ -1,7 +1,5 @@
1
1
  module ActionMailer
2
-
3
2
  module PartContainer
4
-
5
3
  # Add an inline attachment to a multipart message.
6
4
  def inline_attachment(params, &block)
7
5
  params = { :content_type => params } if String === params
@@ -11,11 +9,9 @@ module ActionMailer
11
9
  params[:headers]['Content-ID'] = params[:cid]
12
10
  part(params, &block)
13
11
  end
14
-
15
12
  end
16
13
 
17
14
  class Part
18
-
19
15
  def to_mail(defaults)
20
16
  part = TMail::Mail.new
21
17
 
@@ -65,4 +61,55 @@ module ActionMailer
65
61
  part
66
62
  end
67
63
  end
64
+ end
65
+
66
+ module ActionView
67
+ module Helpers #:nodoc:
68
+ module AssetTagHelper
69
+ def image_tag(source, options = {})
70
+ options.symbolize_keys!
71
+
72
+ if @controller.is_a?(ActionMailer::Base)
73
+ file_path = "#{RAILS_ROOT}/public#{image_path(source).split('?').first}"
74
+ basename = File.basename(file_path, '.*')
75
+ ext = basename.split('.').last
76
+ cid = Time.now.to_f.to_s + "#{basename}@inline_attachment"
77
+ file = File.open(file_path, 'rb')
78
+
79
+ @controller.inline_attachment(:content_type => "image/#{ext}",
80
+ :body => file.read,
81
+ :filename => basename,
82
+ :cid => "<#{cid}>",
83
+ :disposition => "inline")
84
+
85
+ options[:src] = "cid:#{cid}"
86
+ options[:alt] = basename.split('.').first.capitalize
87
+ else
88
+ options[:src] = image_path(source)
89
+ options[:alt] ||= File.basename(options[:src], '.*').split('.').first.capitalize
90
+ end
91
+
92
+ if options[:size]
93
+ options[:width], options[:height] = options[:size].split("x") if options[:size] =~ %r{^\d+x\d+$}
94
+ options.delete(:size)
95
+ end
96
+
97
+ tag("img", options)
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ class DummyClass
104
+ def relative_url_root
105
+ ""
106
+ end
107
+ end
108
+
109
+ module ActionMailer #:nodoc:
110
+ class Base
111
+ def request
112
+ DummyClass.new
113
+ end
114
+ end
68
115
  end
metadata CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: InlineAttachment
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-06-01 00:00:00 +10:00
8
- summary: "A package created from a Rails patch (ticket #2179) that adds embedded images into ActionMailer."
6
+ version: 0.2.0
7
+ date: 2007-11-05 00:00:00 +11:00
8
+ summary: "A package created from a Rails patch (ticket #2179) that automatically embedded images found in your ActionMailer templates."
9
9
  require_paths:
10
10
  - lib
11
11
  email: edmond.leung@handle.it