rails_email_preview 0.2.21 → 0.2.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -4
- data/README.md +71 -57
- data/Rakefile +15 -0
- data/app/assets/stylesheets/rails_email_preview/_layout.css.sass +0 -8
- data/app/controllers/rails_email_preview/application_controller.rb +14 -0
- data/app/controllers/rails_email_preview/emails_controller.rb +130 -92
- data/app/helpers/rails_email_preview/emails_helper.rb +26 -37
- data/app/models/rails_email_preview/preview.rb +16 -6
- data/app/presenters/rails_email_preview/preview_list_presenter.rb +36 -0
- data/app/views/integrations/cms/_customize_cms_for_rails_email_preview.html.slim +16 -6
- data/app/views/layouts/rails_email_preview/email.html.slim +3 -1
- data/app/views/rails_email_preview/emails/_email_iframe.html.slim +63 -24
- data/app/views/rails_email_preview/emails/_format_nav.html.slim +2 -2
- data/app/views/rails_email_preview/emails/_headers.html.slim +2 -2
- data/app/views/rails_email_preview/emails/_i18n_nav.html.slim +3 -4
- data/app/views/rails_email_preview/emails/_send_form.html.slim +3 -3
- data/app/views/rails_email_preview/emails/index.html.slim +10 -7
- data/app/views/rails_email_preview/emails/show.html.slim +11 -11
- data/config/i18n-tasks.yml +5 -4
- data/config/locales/de.yml +11 -7
- data/config/locales/en.yml +10 -4
- data/config/locales/ru.yml +49 -0
- data/config/routes.rb +19 -9
- data/lib/rails_email_preview.rb +1 -1
- data/lib/rails_email_preview/version.rb +1 -1
- metadata +7 -6
- data/app/views/rails_email_preview/emails/show_body.html.slim +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7ac94c83aae345e79cac0653512e28f82bcd17f
|
4
|
+
data.tar.gz: e296d3e2c055f126c854654b08c7a601f033f316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99d6e21a3414b6d3368cef021d8951500c4b9c71f4833a094aab5d52dd6298caae92c589de496af8e8868992beb648a900310688df284292cffb61dccb9a5394
|
7
|
+
data.tar.gz: 7d7a1eaae3a399ac69896a5d77b93ccac01ed40055c6692eae9c139c8221d8441637aea2d1e381ebcae57b784fcdf39986da848212ac599b70221c8be82c15d2
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
@@ -6,9 +6,13 @@ gem 'rails'
|
|
6
6
|
|
7
7
|
platform :rbx do
|
8
8
|
gem 'rubysl', '~> 2.0'
|
9
|
-
gem 'rubysl-test-unit', '~> 2.0'
|
10
9
|
gem 'racc'
|
11
10
|
end
|
12
11
|
|
13
|
-
|
14
|
-
gem 'byebug',
|
12
|
+
group :test, :development do
|
13
|
+
gem 'byebug', platform: :mri_21, require: false
|
14
|
+
end
|
15
|
+
|
16
|
+
group :development do
|
17
|
+
gem 'puma'
|
18
|
+
end
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Rails Email Preview [![Build Status][travis-badge]][travis] [![
|
1
|
+
# Rails Email Preview [![Build Status][travis-badge]][travis] [![Test Coverage][coverage-badge]][coverage] [![Code Climate][codeclimate-badge]][codeclimate]
|
2
2
|
|
3
|
-
|
3
|
+
Preview email in the browser with this Rails engine. Compatible with Rails 3 and 4.
|
4
4
|
|
5
5
|
Preview:
|
6
6
|
![screenshot][rep-show-screenshot]
|
@@ -8,48 +8,52 @@ Preview:
|
|
8
8
|
List:
|
9
9
|
![screenshot][rep-nav-screenshot]
|
10
10
|
|
11
|
-
REP can use
|
12
|
-
*These screenshots are
|
11
|
+
REP can use your application styles, markup is compatible with [bootstrap 3][rep-show-default-screenshot] by default.
|
12
|
+
*These screenshots are using a custom Bootstrap theme*
|
13
13
|
|
14
|
-
##
|
14
|
+
## Installation
|
15
15
|
|
16
|
-
Add to Gemfile
|
16
|
+
Add [![Gem Version][gem-badge]][gem] to Gemfile:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem 'rails_email_preview', '~> 0.2.
|
19
|
+
gem 'rails_email_preview', '~> 0.2.22'
|
20
20
|
```
|
21
21
|
|
22
|
-
|
22
|
+
Add an initializer and the routes:
|
23
23
|
|
24
|
-
```
|
25
|
-
|
26
|
-
|
24
|
+
```console
|
25
|
+
$ rails g rails_email_preview:install
|
26
|
+
```
|
27
|
+
|
28
|
+
Generate preview classes and method stubs in app/mailer_previews/
|
27
29
|
|
28
|
-
|
29
|
-
rails g rails_email_preview:update_previews
|
30
|
+
```console
|
31
|
+
$ rails g rails_email_preview:update_previews
|
30
32
|
```
|
31
33
|
|
32
|
-
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
The last generator above will add a stub for each of your emails, then you populate the stubs with mock data:
|
33
37
|
|
34
38
|
```ruby
|
35
39
|
# app/mailer_previews/user_mailer_preview.rb:
|
36
40
|
class UserMailerPreview
|
37
41
|
# preview methods should return Mail objects, e.g.:
|
38
|
-
def invitation
|
42
|
+
def invitation
|
39
43
|
UserMailer.invitation mock_user('Alice'), mock_user('Bob')
|
40
44
|
end
|
41
|
-
|
42
|
-
def welcome
|
43
|
-
UserMailer.welcome mock_user
|
45
|
+
|
46
|
+
def welcome
|
47
|
+
UserMailer.welcome mock_user
|
44
48
|
end
|
45
|
-
|
49
|
+
|
46
50
|
private
|
47
51
|
# You can put all your mock helpers in a module
|
48
52
|
# or you can use your factories / fabricators, just make sure you are not creating anythin
|
49
53
|
def mock_user(name = 'Bill Gates')
|
50
54
|
fake_id User.new(name: name, email: "user#{rand 100}@test.com")
|
51
55
|
end
|
52
|
-
|
56
|
+
|
53
57
|
def fake_id(obj)
|
54
58
|
# overrides the method on just this object
|
55
59
|
obj.define_singleton_method(:id) { 123 + rand(100) }
|
@@ -58,8 +62,27 @@ class UserMailerPreview
|
|
58
62
|
end
|
59
63
|
```
|
60
64
|
|
65
|
+
### Parameters as instance variables
|
66
|
+
|
67
|
+
All parameters in the search query will be available to the preview class as instance variables.
|
68
|
+
For example, if URL to mailer preview looks like:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
/emails/user_mailer_preview-welcome?user_id=1
|
72
|
+
```
|
73
|
+
|
74
|
+
The method `welcome` in `UserMailerPreview` have a `@user_id` instance variable defined:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
class UserMailerPreview
|
78
|
+
def welcome
|
79
|
+
user = @user_id ? User.find(@user_id) : mock_company
|
80
|
+
UserMailer.welcome(user)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
```
|
61
84
|
|
62
|
-
|
85
|
+
### Routing
|
63
86
|
|
64
87
|
You can access REP urls like this:
|
65
88
|
|
@@ -72,7 +95,7 @@ rails_email_preview.rep_emails_url
|
|
72
95
|
rails_email_preview.rep_email_url('user_mailer-welcome')
|
73
96
|
```
|
74
97
|
|
75
|
-
|
98
|
+
### Sending Emails
|
76
99
|
|
77
100
|
You can send emails via REP. This is especially useful when testing with limited clients (Blackberry, Outlook, etc.).
|
78
101
|
This will use the environment's mailer settings, but the handler will `perform_deliveries`.
|
@@ -82,32 +105,36 @@ Uncomment this line in the initializer to disable sending test emails:
|
|
82
105
|
config.enable_send_email = false
|
83
106
|
```
|
84
107
|
|
85
|
-
|
108
|
+
### Editing Emails
|
86
109
|
|
87
|
-
|
88
|
-
REP
|
110
|
+
Emails can be stored in the database and edited in the browser.
|
111
|
+
REP works with [Comfortable Mexican Sofa CMS](https://github.com/comfy/comfortable-mexican-sofa) to achieve this -- see the [CMS Guide](https://github.com/glebm/rails_email_preview/wiki/Edit-Emails-with-Comfortable-Mexican-Sofa) to learn more.
|
89
112
|
|
90
113
|
[![screenshot](https://raw.github.com/glebm/rails_email_preview/master/doc/img/rep-edit-sofa.png)](https://github.com/glebm/rails_email_preview/wiki/Edit-Emails-with-Comfortable-Mexican-Sofa)
|
91
114
|
|
92
|
-
|
93
|
-
## Premailer
|
115
|
+
### Premailer
|
94
116
|
|
95
117
|
[Premailer](https://github.com/alexdunae/premailer) automatically translates standard CSS rules into old-school inline styles. Integration can be done by using the <code>before_render</code> hook.
|
96
118
|
|
97
119
|
To integrate Premailer with your Rails app you can use either [actionmailer_inline_css](https://github.com/ndbroadbent/actionmailer_inline_css) or [premailer-rails](https://github.com/fphilipe/premailer-rails).
|
98
120
|
Simply uncomment the relevant options in [the initializer](https://github.com/glebm/rails_email_preview/blob/master/config/initializers/rails_email_preview.rb). *initializer is generated during `rails g rails_email_preview:install`*
|
99
121
|
|
100
|
-
|
122
|
+
### I18n
|
101
123
|
|
102
124
|
REP expects emails to use current `I18n.locale`:
|
103
125
|
|
104
126
|
```ruby
|
105
127
|
# current locale
|
106
|
-
AccountMailer.some_notification.deliver
|
128
|
+
AccountMailer.some_notification.deliver
|
107
129
|
# different locale
|
108
|
-
I18n.with_locale('es')
|
109
|
-
|
130
|
+
I18n.with_locale('es') do
|
131
|
+
InviteMailer.send_invites.deliver
|
132
|
+
end
|
110
133
|
```
|
134
|
+
|
135
|
+
If you are using `Resque::Mailer` or `Devise::Async`, you can automatically remember `I18n.locale` when the mail job is scheduled
|
136
|
+
[with this initializer](https://gist.github.com/glebm/5725347).
|
137
|
+
|
111
138
|
When linking to REP pages you can pass `email_locale` to set the locale for rendering:
|
112
139
|
|
113
140
|
```ruby
|
@@ -115,13 +142,9 @@ When linking to REP pages you can pass `email_locale` to set the locale for rend
|
|
115
142
|
rails_email_preview.root_url(email_locale: 'es')
|
116
143
|
```
|
117
144
|
|
118
|
-
|
119
|
-
If you are using `Resque::Mailer` or `Devise::Async`, you can automatically add I18n.locale information when the mail job is scheduled
|
120
|
-
[with this initializer](https://gist.github.com/glebm/5725347).
|
121
|
-
|
122
145
|
REP displays too many locales? Make sure to set `config.i18n.available_locales`, since it defaults to *all* locales in Rails.
|
123
146
|
|
124
|
-
User interface is available in English
|
147
|
+
User interface is available in English, German (Danke, @baschtl), and Russian.
|
125
148
|
You can set the language in `config.to_prepare` section of the initializer, default is English.
|
126
149
|
|
127
150
|
```ruby
|
@@ -129,7 +152,7 @@ You can set the language in `config.to_prepare` section of the initializer, defa
|
|
129
152
|
RailsEmailPreview.locale = :de
|
130
153
|
```
|
131
154
|
|
132
|
-
|
155
|
+
### Views
|
133
156
|
|
134
157
|
You can render all REP views inside your app layout (this will need styling to look nice if you don't use bootstrap):
|
135
158
|
|
@@ -140,10 +163,10 @@ Rails.application.config.to_prepare do
|
|
140
163
|
end
|
141
164
|
```
|
142
165
|
|
143
|
-
REP allows you to customize some of the element classes via `RailsEmailPreview.style`:
|
166
|
+
REP also allows you to customize some of the element classes via `RailsEmailPreview.style`:
|
144
167
|
|
145
168
|
```ruby
|
146
|
-
{
|
169
|
+
RailsEmailPreview.style = {
|
147
170
|
btn_default_class: 'btn btn-default',
|
148
171
|
btn_active_class: 'btn btn-primary active',
|
149
172
|
btn_group_class: 'btn-group',
|
@@ -155,18 +178,12 @@ REP allows you to customize some of the element classes via `RailsEmailPreview.s
|
|
155
178
|
}
|
156
179
|
```
|
157
180
|
|
158
|
-
E.g., to change column class from `col-` to `column-` everywhere where REP uses columns:
|
159
|
-
|
160
|
-
```ruby
|
161
|
-
RailsEmailPreview.style[:column_class] = 'column-%{n}'
|
162
|
-
```
|
163
|
-
|
164
181
|
You can `//= require 'rails_email_preview/layout'` REP-specific styles (`@import 'rails_email_preview/layout'` for SASS).
|
165
182
|
|
166
183
|
You can also override any individual view by placing a file with the same path in your project's `app/views`,
|
167
|
-
e.g. `app/views/rails_email_preview/emails/index.html.slim`. *PRs accepted* if you need hooks.
|
184
|
+
e.g. `app/views/rails_email_preview/emails/index.html.slim`. *PRs accepted* if you need hooks.
|
168
185
|
|
169
|
-
|
186
|
+
### Authentication & authorization
|
170
187
|
|
171
188
|
You can specify the parent controller for REP controller, and it will inherit all before filters.
|
172
189
|
Note that this must be placed before any other references to REP application controller in the initializer (and before `layout=` call):
|
@@ -181,28 +198,25 @@ Alternatively, to have custom rules just for REP you can:
|
|
181
198
|
Rails.application.config.to_prepare do
|
182
199
|
RailsEmailPreview::ApplicationController.module_eval do
|
183
200
|
before_filter :check_rep_permissions
|
184
|
-
|
201
|
+
|
185
202
|
private
|
186
203
|
def check_rep_permissions
|
187
204
|
render status: 403 unless current_user && can_manage_emails?(current_user)
|
188
205
|
end
|
189
206
|
end
|
190
|
-
end
|
207
|
+
end
|
191
208
|
```
|
192
209
|
|
193
|
-
|
194
210
|
This project rocks and uses MIT-LICENSE.
|
195
211
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
212
|
+
[rep-nav-screenshot]: https://raw.github.com/glebm/rails_email_preview/master/doc/img/rep-nav.png "Email List Screenshot"
|
213
|
+
[rep-show-screenshot]: https://raw.github.com/glebm/rails_email_preview/master/doc/img/rep-show.png "Show Email Screenshot"
|
214
|
+
[rep-show-default-screenshot]: https://raw.github.com/glebm/rails_email_preview/master/doc/img/rep-show-default.png "Show Email Screenshot (default styles)"
|
201
215
|
[travis]: http://travis-ci.org/glebm/rails_email_preview
|
202
216
|
[travis-badge]: http://img.shields.io/travis/glebm/rails_email_preview.svg
|
203
217
|
[gem]: https://rubygems.org/gems/rails_email_preview
|
204
218
|
[gem-badge]: http://img.shields.io/gem/v/rails_email_preview.svg
|
205
219
|
[codeclimate]: https://codeclimate.com/github/glebm/rails_email_preview
|
206
220
|
[codeclimate-badge]: http://img.shields.io/codeclimate/github/glebm/rails_email_preview.svg
|
207
|
-
[
|
208
|
-
[
|
221
|
+
[coverage]: https://codeclimate.com/github/glebm/rails_email_preview
|
222
|
+
[coverage-badge]: https://codeclimate.com/github/glebm/rails_email_preview/badges/coverage.svg
|
data/Rakefile
CHANGED
@@ -17,3 +17,18 @@ require 'rspec/core/rake_task'
|
|
17
17
|
RSpec::Core::RakeTask.new(:spec)
|
18
18
|
|
19
19
|
task default: :spec
|
20
|
+
|
21
|
+
desc 'Start development web server'
|
22
|
+
task :dev do
|
23
|
+
require 'puma'
|
24
|
+
require 'rails/commands/server'
|
25
|
+
ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'development'
|
26
|
+
Dir.chdir 'spec/dummy'
|
27
|
+
Rack::Server.start(
|
28
|
+
environment: 'development',
|
29
|
+
Host: 'localhost',
|
30
|
+
Port: 9292,
|
31
|
+
config: 'config.ru',
|
32
|
+
server: 'puma'
|
33
|
+
)
|
34
|
+
end
|
@@ -1,5 +1,19 @@
|
|
1
1
|
module RailsEmailPreview
|
2
2
|
class ApplicationController < ::RailsEmailPreview.parent_controller.constantize
|
3
3
|
layout 'rails_email_preview/application'
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
def prevent_browser_caching
|
8
|
+
# Prevent back-button browser caching:
|
9
|
+
# HTTP/1.1
|
10
|
+
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate'
|
11
|
+
# Date in the past
|
12
|
+
response.headers['Expires'] = 'Mon, 26 Jul 1997 05:00:00 GMT'
|
13
|
+
# Always modified
|
14
|
+
response.headers['Last-Modified'] = Time.now.httpdate
|
15
|
+
# HTTP/1.0
|
16
|
+
response.headers['Pragma'] = 'no-cache'
|
17
|
+
end
|
4
18
|
end
|
5
19
|
end
|
@@ -1,116 +1,154 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def index
|
9
|
-
@previews = ::RailsEmailPreview::Preview.all
|
10
|
-
@previews_by_class = ::RailsEmailPreview::Preview.all_by_preview_class
|
11
|
-
end
|
1
|
+
module RailsEmailPreview
|
2
|
+
class EmailsController < ::RailsEmailPreview::ApplicationController
|
3
|
+
include ERB::Util
|
4
|
+
before_filter :load_preview, except: :index
|
5
|
+
around_filter :set_locale
|
6
|
+
before_filter :set_email_preview_locale
|
7
|
+
helper_method :with_email_locale
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
# List of emails
|
10
|
+
def index
|
11
|
+
@previews = Preview.all
|
12
|
+
@list = PreviewListPresenter.new(@previews)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Preview an email
|
16
|
+
def show
|
17
|
+
prevent_browser_caching
|
18
|
+
cms_edit_links!
|
19
|
+
with_email_locale do
|
20
|
+
if @preview.respond_to?(:preview_mail)
|
21
|
+
@mail, body = mail_and_body
|
22
|
+
@mail_body_html = render_to_string inline: body, layout: 'rails_email_preview/email'
|
23
|
+
else
|
24
|
+
raise ArgumentError.new("#{@preview} is not a preview class, does not respond_to?(:preview_mail)")
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
23
|
-
end
|
24
28
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
# Download attachment
|
30
|
+
def show_attachment
|
31
|
+
filename = "#{params[:filename]}.#{request.format.symbol}"
|
32
|
+
attachment = preview_mail(false).attachments.find { |a| a.filename == filename }
|
33
|
+
send_data attachment.body.raw_source
|
30
34
|
end
|
31
|
-
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
# Really deliver an email
|
37
|
+
def test_deliver
|
38
|
+
redirect_url = rails_email_preview.rep_email_url(params.slice(:preview_id, :email_locale))
|
39
|
+
if (address = params[:recipient_email]).blank? || address !~ /@/
|
40
|
+
redirect_to redirect_url, alert: t('rep.test_deliver.provide_email')
|
41
|
+
return
|
42
|
+
end
|
43
|
+
with_email_locale do
|
44
|
+
delivery_handler = RailsEmailPreview::DeliveryHandler.new(preview_mail, to: address, cc: nil, bcc: nil)
|
45
|
+
deliver_email!(delivery_handler.mail)
|
46
|
+
end
|
47
|
+
delivery_method = Rails.application.config.action_mailer.delivery_method
|
48
|
+
if delivery_method
|
49
|
+
redirect_to redirect_url, notice: t('rep.test_deliver.sent_notice', address: address, delivery_method: delivery_method)
|
50
|
+
else
|
51
|
+
redirect_to redirect_url, alert: t('rep.test_deliver.no_delivery_method', environment: Rails.env)
|
52
|
+
end
|
53
|
+
end
|
38
54
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
redirect_to redirect_url, alert: t('rep.test_deliver.provide_email')
|
43
|
-
return
|
55
|
+
# Used by CMS integration to refetch header after editing
|
56
|
+
def headers
|
57
|
+
render partial: 'rails_email_preview/emails/headers', locals: {mail: mail_and_body.first}
|
44
58
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
59
|
+
|
60
|
+
# Used by the CMS integration to provide a link back to Show inside the edit iframe
|
61
|
+
def show_body
|
62
|
+
prevent_browser_caching
|
63
|
+
cms_edit_links!
|
64
|
+
with_email_locale do
|
65
|
+
_, body = mail_and_body
|
66
|
+
render inline: body, layout: 'rails_email_preview/email'
|
67
|
+
end
|
48
68
|
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def deliver_email!(mail)
|
73
|
+
# support deliver! if present
|
74
|
+
if mail.respond_to?(:deliver!)
|
75
|
+
mail.deliver!
|
76
|
+
else
|
77
|
+
mail.deliver
|
78
|
+
end
|
53
79
|
end
|
54
|
-
end
|
55
80
|
|
56
|
-
|
81
|
+
# Load mail and its body for preview
|
82
|
+
# @return [[Mail, String]] the mail object and its body
|
83
|
+
def mail_and_body
|
84
|
+
mail = preview_mail
|
85
|
+
body = mail_body_content(mail, @part_type)
|
86
|
+
[mail, body]
|
87
|
+
end
|
57
88
|
|
58
|
-
|
59
|
-
#
|
60
|
-
|
61
|
-
|
62
|
-
else
|
63
|
-
mail.deliver
|
89
|
+
# @param [Boolean] run_handlers whether to run the registered handlers for Mail object
|
90
|
+
# @return [Mail]
|
91
|
+
def preview_mail(run_handlers = true)
|
92
|
+
@preview.preview_mail(run_handlers, params.except(*request.path_parameters.keys))
|
64
93
|
end
|
65
|
-
end
|
66
94
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
95
|
+
# @param [Mail] mail
|
96
|
+
# @param ['html', 'plain', 'raw']
|
97
|
+
# @return [String] version of the email for HTML
|
98
|
+
def mail_body_content(mail, part_type)
|
99
|
+
return "<pre id='raw_message'>#{html_escape(mail.to_s)}</pre>".html_safe if part_type == 'raw'
|
100
|
+
|
101
|
+
body_part = if mail.multipart?
|
102
|
+
(part_type =~ /html/ ? mail.html_part : mail.text_part)
|
103
|
+
else
|
104
|
+
mail
|
105
|
+
end
|
106
|
+
|
107
|
+
if body_part.content_type =~ /plain/
|
108
|
+
"<pre id='message_body'>#{html_escape(body_part.body.to_s)}</pre>".html_safe
|
109
|
+
else
|
110
|
+
body_content = body_part.body.to_s
|
111
|
+
|
112
|
+
mail.attachments.each do |attachment|
|
113
|
+
web_url = rails_email_preview.rep_raw_email_attachment_url(params[:preview_id], attachment.filename)
|
114
|
+
body_content.gsub!(attachment.url, web_url)
|
115
|
+
end
|
116
|
+
|
117
|
+
body_content.html_safe
|
87
118
|
end
|
119
|
+
end
|
88
120
|
|
89
|
-
|
121
|
+
def with_email_locale(&block)
|
122
|
+
I18n.with_locale @email_locale, &block
|
90
123
|
end
|
91
|
-
end
|
92
124
|
|
93
|
-
|
94
|
-
|
95
|
-
|
125
|
+
def set_email_preview_locale
|
126
|
+
@email_locale = (params[:email_locale] || RailsEmailPreview.default_email_locale || I18n.default_locale).to_s
|
127
|
+
end
|
96
128
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
129
|
+
def set_locale
|
130
|
+
config_locale = RailsEmailPreview.locale
|
131
|
+
if !I18n.available_locales.map(&:to_s).include?(config_locale.to_s)
|
132
|
+
config_locale = :en
|
133
|
+
end
|
134
|
+
begin
|
135
|
+
locale_was = I18n.locale
|
136
|
+
I18n.locale = config_locale
|
137
|
+
yield if block_given?
|
138
|
+
ensure
|
139
|
+
I18n.locale = locale_was
|
140
|
+
end
|
101
141
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
I18n.locale = locale_was
|
142
|
+
|
143
|
+
# Let REP's `cms_email_snippet` know to render an Edit link
|
144
|
+
# Todo: Refactoring is especially welcome here
|
145
|
+
def cms_edit_links!
|
146
|
+
RequestStore.store[:rep_edit_links] = (@part_type == 'html')
|
108
147
|
end
|
109
|
-
end
|
110
|
-
private
|
111
148
|
|
112
|
-
|
113
|
-
|
114
|
-
|
149
|
+
def load_preview
|
150
|
+
@preview = ::RailsEmailPreview::Preview[params[:preview_id]] or raise ActionController::RoutingError.new('Not Found')
|
151
|
+
@part_type = params[:part_type] || 'html'
|
152
|
+
end
|
115
153
|
end
|
116
154
|
end
|