postmortem 0.1.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +4 -46
- data/.ruby-version +1 -0
- data/Gemfile +0 -2
- data/README.md +20 -16
- data/doc/screenshot.png +0 -0
- data/layout/default.html.erb +68 -254
- data/layout/dependencies.css +11 -0
- data/layout/dependencies.js +14 -0
- data/layout/favicon.b64 +1 -0
- data/layout/headers_template.html +35 -0
- data/layout/layout.css +255 -0
- data/layout/layout.js +381 -0
- data/layout/postmortem_identity.html.erb +20 -0
- data/layout/postmortem_index.html.erb +25 -0
- data/lib/postmortem.rb +14 -2
- data/lib/postmortem/adapters.rb +1 -1
- data/lib/postmortem/adapters/action_mailer.rb +6 -41
- data/lib/postmortem/adapters/base.rb +60 -1
- data/lib/postmortem/adapters/mail.rb +3 -3
- data/lib/postmortem/adapters/pony.rb +3 -6
- data/lib/postmortem/configuration.rb +1 -5
- data/lib/postmortem/delivery.rb +20 -13
- data/lib/postmortem/identity.rb +20 -0
- data/lib/postmortem/index.rb +68 -0
- data/lib/postmortem/layout.rb +86 -3
- data/lib/postmortem/plugins/action_mailer.rb +7 -0
- data/lib/postmortem/version.rb +1 -1
- data/postmortem.gemspec +4 -2
- metadata +46 -6
data/lib/postmortem/layout.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
module Postmortem
|
4
4
|
# Wraps provided body in an enclosing layout for presentation purposes.
|
5
5
|
class Layout
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(mail)
|
7
|
+
@mail = mail
|
8
8
|
end
|
9
9
|
|
10
10
|
def format_email_array(array)
|
@@ -12,8 +12,91 @@ module Postmortem
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def content
|
15
|
-
mail = @
|
15
|
+
mail = @mail
|
16
|
+
mail.html_body = with_inlined_images(mail.html_body) if defined?(Nokogiri)
|
16
17
|
ERB.new(Postmortem.config.layout.read).result(binding)
|
17
18
|
end
|
19
|
+
|
20
|
+
def styles
|
21
|
+
default_layout_directory.join('layout.css').read
|
22
|
+
end
|
23
|
+
|
24
|
+
def javascript
|
25
|
+
default_layout_directory.join('layout.js').read
|
26
|
+
end
|
27
|
+
|
28
|
+
def css_dependencies
|
29
|
+
default_layout_directory.join('dependencies.css').read
|
30
|
+
end
|
31
|
+
|
32
|
+
def javascript_dependencies
|
33
|
+
default_layout_directory.join('dependencies.js').read
|
34
|
+
end
|
35
|
+
|
36
|
+
def headers_template
|
37
|
+
default_layout_directory.join('headers_template.html').read
|
38
|
+
end
|
39
|
+
|
40
|
+
def favicon_b64
|
41
|
+
default_layout_directory.join('favicon.b64').read
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def default_layout_directory
|
47
|
+
Postmortem.root.join('layout')
|
48
|
+
end
|
49
|
+
|
50
|
+
def with_inlined_images(body)
|
51
|
+
parsed = Nokogiri::HTML.parse(body)
|
52
|
+
parsed.css('img').each do |img|
|
53
|
+
uri = try_uri(img['src'])
|
54
|
+
next unless local_file?(uri)
|
55
|
+
|
56
|
+
path = located_image(uri)
|
57
|
+
img['src'] = encoded_image(path) unless path.nil?
|
58
|
+
end
|
59
|
+
parsed.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
def local_file?(uri)
|
63
|
+
return false if uri.nil?
|
64
|
+
return true if uri.host.nil?
|
65
|
+
return true if /^www\.example\.[a-z]+$/.match(uri.host)
|
66
|
+
return true if %w[127.0.0.1 localhost].include?(uri.host)
|
67
|
+
|
68
|
+
false
|
69
|
+
end
|
70
|
+
|
71
|
+
def try_uri(uri)
|
72
|
+
URI(uri)
|
73
|
+
rescue URI::InvalidURIError
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def located_image(uri)
|
78
|
+
path = uri.path.partition('/').last
|
79
|
+
common_locations.each do |location|
|
80
|
+
full_path = location.join(path)
|
81
|
+
next unless full_path.file?
|
82
|
+
|
83
|
+
return full_path
|
84
|
+
end
|
85
|
+
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def encoded_image(path)
|
90
|
+
"data:#{mime_type(path)};base64,#{Base64.encode64(path.read)}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def common_locations
|
94
|
+
['public/assets', 'app/assets/images'].map { |path| Pathname.new(path) }
|
95
|
+
end
|
96
|
+
|
97
|
+
def mime_type(path)
|
98
|
+
extension = path.extname.partition('.').last
|
99
|
+
extension == 'jpg' ? 'jpeg' : extension
|
100
|
+
end
|
18
101
|
end
|
19
102
|
end
|
@@ -1,5 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
ActiveSupport::Notifications.subscribe 'deliver.action_mailer' do |*args|
|
4
|
+
delivery_method = Rails.try(:application)
|
5
|
+
&.try(:config)
|
6
|
+
&.try(:action_mailer)
|
7
|
+
&.try(:delivery_method)
|
8
|
+
next if delivery_method.nil?
|
9
|
+
next if %i[sendmail smtp].include?(delivery_method&.to_sym) # Delegate to Mail plugin.
|
10
|
+
|
4
11
|
Postmortem.record_delivery(Postmortem::Adapters::ActionMailer.new(args.extract_options!))
|
5
12
|
end
|
data/lib/postmortem/version.rb
CHANGED
data/postmortem.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.description = 'Preview HTML emails in your browser during development'
|
13
13
|
spec.homepage = 'https://github.com/bobf/postmortem'
|
14
14
|
spec.license = 'MIT'
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
16
16
|
|
17
17
|
spec.metadata['homepage_uri'] = spec.homepage
|
18
18
|
spec.metadata['source_code_uri'] = spec.homepage
|
@@ -28,10 +28,12 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_runtime_dependency 'mail', '~> 2.7'
|
29
29
|
|
30
30
|
spec.add_development_dependency 'actionmailer', '~> 6.0'
|
31
|
+
spec.add_development_dependency 'devpack', '~> 0.3.2'
|
31
32
|
spec.add_development_dependency 'pony', '~> 1.13'
|
32
33
|
spec.add_development_dependency 'rspec', '~> 3.9'
|
33
34
|
spec.add_development_dependency 'rspec-its', '~> 1.3'
|
34
|
-
spec.add_development_dependency 'rubocop', '~>
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 1.10'
|
36
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.2'
|
35
37
|
spec.add_development_dependency 'strong_versions', '~> 0.4.5'
|
36
38
|
spec.add_development_dependency 'timecop', '~> 0.9.1'
|
37
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postmortem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Farrell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '6.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: devpack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.3.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.3.2
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: pony
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +100,28 @@ dependencies:
|
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: '1.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.2'
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
122
|
- - "~>"
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
124
|
+
version: '2.2'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
126
|
name: strong_versions
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -132,6 +160,7 @@ files:
|
|
132
160
|
- ".gitignore"
|
133
161
|
- ".rspec"
|
134
162
|
- ".rubocop.yml"
|
163
|
+
- ".ruby-version"
|
135
164
|
- Gemfile
|
136
165
|
- LICENSE.txt
|
137
166
|
- Makefile
|
@@ -141,6 +170,14 @@ files:
|
|
141
170
|
- bin/setup
|
142
171
|
- doc/screenshot.png
|
143
172
|
- layout/default.html.erb
|
173
|
+
- layout/dependencies.css
|
174
|
+
- layout/dependencies.js
|
175
|
+
- layout/favicon.b64
|
176
|
+
- layout/headers_template.html
|
177
|
+
- layout/layout.css
|
178
|
+
- layout/layout.js
|
179
|
+
- layout/postmortem_identity.html.erb
|
180
|
+
- layout/postmortem_index.html.erb
|
144
181
|
- lib/postmortem.rb
|
145
182
|
- lib/postmortem/adapters.rb
|
146
183
|
- lib/postmortem/adapters/action_mailer.rb
|
@@ -149,6 +186,8 @@ files:
|
|
149
186
|
- lib/postmortem/adapters/pony.rb
|
150
187
|
- lib/postmortem/configuration.rb
|
151
188
|
- lib/postmortem/delivery.rb
|
189
|
+
- lib/postmortem/identity.rb
|
190
|
+
- lib/postmortem/index.rb
|
152
191
|
- lib/postmortem/layout.rb
|
153
192
|
- lib/postmortem/plugins/action_mailer.rb
|
154
193
|
- lib/postmortem/plugins/mail.rb
|
@@ -170,14 +209,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
209
|
requirements:
|
171
210
|
- - ">="
|
172
211
|
- !ruby/object:Gem::Version
|
173
|
-
version: 2.
|
212
|
+
version: 2.5.0
|
174
213
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
214
|
requirements:
|
176
215
|
- - ">="
|
177
216
|
- !ruby/object:Gem::Version
|
178
217
|
version: '0'
|
179
218
|
requirements: []
|
180
|
-
|
219
|
+
rubyforge_project:
|
220
|
+
rubygems_version: 2.7.6.2
|
181
221
|
signing_key:
|
182
222
|
specification_version: 4
|
183
223
|
summary: Development HTML Email Inspection Tool
|