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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6a3a68dcd424b8bad4c8835e9a43cfb388ccadd
4
- data.tar.gz: 0c878a6582eee10408bf7bc522b60fb49961b77e
3
+ metadata.gz: d7ac94c83aae345e79cac0653512e28f82bcd17f
4
+ data.tar.gz: e296d3e2c055f126c854654b08c7a601f033f316
5
5
  SHA512:
6
- metadata.gz: cc4d460e598e8daaaa8b81ee000c51ae6fecd382be0a705ceff5bd36895f54e47f91b69cfb056f396012b0ace6fc29baf85f7038f559c76e914d77bdcba802a2
7
- data.tar.gz: eee63446fb36c5e0c5675de0ed9d7a24f8bcedf4c1bd504ca2a1ac6f3a44ebdacd07593a3eed7e1b0c5aebd5671b50db0afb3764b68437fe307923489a48f41a
6
+ metadata.gz: 99d6e21a3414b6d3368cef021d8951500c4b9c71f4833a094aab5d52dd6298caae92c589de496af8e8868992beb648a900310688df284292cffb61dccb9a5394
7
+ data.tar.gz: 7d7a1eaae3a399ac69896a5d77b93ccac01ed40055c6692eae9c139c8221d8441637aea2d1e381ebcae57b784fcdf39986da848212ac599b70221c8be82c15d2
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
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
- # a debugger that works with MRI 2.0.0
14
- gem 'byebug', platforms: :ruby_21, groups: [:development, :test]
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] [![Gem Version][gem-badge]][gem] [![Code Climate][codeclimate-badge]][codeclimate]
1
+ # Rails Email Preview [![Build Status][travis-badge]][travis] [![Test Coverage][coverage-badge]][coverage] [![Code Climate][codeclimate-badge]][codeclimate]
2
2
 
3
- A Rails Engine to preview plain text and html email in your browser. Compatible with Rails 3 and 4.
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 the application styles and comes with [a bootstrap 3 theme][rep-show-default-screenshot] by default (default markup for [twbs/bootstrap](twbs/bootstrap) 3).
12
- *These screenshots are from [Zuigo](http://zuigo.com/), a platform to organize & discover events; using REP default markup and app styles*
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
- ## How to
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.21'
19
+ gem 'rails_email_preview', '~> 0.2.22'
20
20
  ```
21
21
 
22
- REP handles setup for you:
22
+ Add an initializer and the routes:
23
23
 
24
- ```ruby
25
- # adds initializer and route:
26
- rails g rails_email_preview:install
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
- # generates preview classes and method stubs in app/mailer_previews/:
29
- rails g rails_email_preview:update_previews
30
+ ```console
31
+ $ rails g rails_email_preview:update_previews
30
32
  ```
31
33
 
32
- This last generator will add a stub for each of your emails, then you populate the stubs with mock data:
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
- ## Routing
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
- ## Send Emails
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
- ## Email editing
108
+ ### Editing Emails
86
109
 
87
- You can use [comfortable_mexican_sofa](https://github.com/comfy/comfortable-mexican-sofa) for storing and editing emails.
88
- REP comes with an integration for it -- see [CMS Guide](https://github.com/glebm/rails_email_preview/wiki/Edit-Emails-with-Comfortable-Mexican-Sofa).
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
- ## I18n
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') { InviteMailer.send_invites.deliver }
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 and German (Danke, @baschtl).
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
- ## Views
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
- ## Authentication & authorization
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
- [rep-nav-screenshot]: https://raw.github.com/glebm/rails_email_preview/master/doc/img/rep-nav.png "Email List Screenshot"
197
- [rep-show-screenshot]: https://raw.github.com/glebm/rails_email_preview/master/doc/img/rep-show.png "Show Email Screenshot"
198
- [rep-show-default-screenshot]: https://raw.github.com/glebm/rails_email_preview/master/doc/img/rep-show-default.png "Show Email Screenshot (default styles)"
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
- [coveralls]: https://coveralls.io/r/glebm/rails_email_preview
208
- [coveralls-badge]: http://img.shields.io/coveralls/glebm/rails_email_preview.svg
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
@@ -11,11 +11,3 @@
11
11
  dd
12
12
  width: auto
13
13
  margin-left: 0
14
-
15
- .rep-email-options
16
- margin-bottom: 0
17
- padding: 8px
18
- li
19
- padding-top: 0.7em
20
- &:first-child
21
- padding-top: 0
@@ -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
- class RailsEmailPreview::EmailsController < ::RailsEmailPreview::ApplicationController
2
- include ERB::Util
3
- before_filter :load_preview, except: :index
4
- around_filter :set_locale
5
- before_filter :set_email_preview_locale
6
-
7
- # list screen
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
- # preview screen
14
- def show
15
- I18n.with_locale @email_locale do
16
- @part_type = params[:part_type] || 'text/html'
17
- if @preview.respond_to?(:preview_mail)
18
- @mail = @preview.preview_mail
19
- else
20
- raise ArgumentError.new("#{@preview} is not a preview class, does not respond_to?(:preview_mail)")
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
- # render actual email content
26
- def show_body
27
- I18n.with_locale @email_locale do
28
- @mail_body = mail_body(@preview, @part_type)
29
- render :show_body, layout: 'rails_email_preview/email'
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
- def show_attachment
34
- @mail = @preview.preview_mail
35
- attachment = @mail.attachments.find { |a| a.filename == "#{params[:filename]}.#{request.format.symbol}" }
36
- send_data attachment.body.raw_source
37
- end
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
- def test_deliver
40
- redirect_url = rails_email_preview.rep_email_url(params.slice(:preview_id, :email_locale))
41
- if (address = params[:recipient_email]).blank? || address !~ /@/
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
- I18n.with_locale @email_locale do
46
- delivery_handler = RailsEmailPreview::DeliveryHandler.new(@preview.preview_mail(true), to: address, cc: nil, bcc: nil)
47
- deliver_email!(delivery_handler.mail)
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
- if !(delivery_method = Rails.application.config.action_mailer.delivery_method)
50
- redirect_to redirect_url, alert: t('rep.test_deliver.no_delivery_method', environment: Rails.env)
51
- else
52
- redirect_to redirect_url, notice: t('rep.test_deliver.sent_notice', address: address, delivery_method: delivery_method)
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
- protected
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
- def deliver_email!(mail)
59
- # support deliver! if present
60
- if mail.respond_to?(:deliver!)
61
- mail.deliver!
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
- def mail_body(preview, part_type, edit_links = (part_type == 'text/html'))
68
- RequestStore.store[:rep_edit_links] = true if edit_links
69
- mail = preview.preview_mail(true)
70
-
71
- return "<pre id='raw_message'>#{html_escape(mail.to_s)}</pre>".html_safe if part_type == 'raw'
72
-
73
- body_part = if mail.multipart?
74
- (part_type =~ /html/ ? mail.html_part : mail.text_part)
75
- else
76
- mail
77
- end
78
-
79
- if body_part.content_type =~ /plain/
80
- "<pre id='message_body'>#{html_escape(body_part.body.to_s)}</pre>".html_safe
81
- else
82
- body_content = body_part.body.to_s
83
-
84
- mail.attachments.each do |attachment|
85
- web_url = rails_email_preview.rep_raw_email_attachment_url(params[:preview_id], attachment.filename)
86
- body_content.gsub!(attachment.url, web_url)
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
- body_content.html_safe
121
+ def with_email_locale(&block)
122
+ I18n.with_locale @email_locale, &block
90
123
  end
91
- end
92
124
 
93
- def set_email_preview_locale
94
- @email_locale = (params[:email_locale] || RailsEmailPreview.default_email_locale || I18n.default_locale).to_s
95
- end
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
- def set_locale
98
- config_locale = RailsEmailPreview.locale
99
- if !I18n.available_locales.map(&:to_s).include?(config_locale.to_s)
100
- config_locale = :en
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
- begin
103
- locale_was = I18n.locale
104
- I18n.locale = config_locale
105
- yield if block_given?
106
- ensure
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
- def load_preview
113
- @preview = ::RailsEmailPreview::Preview[params[:preview_id]] or raise ActionController::RoutingError.new('Not Found')
114
- @part_type = params[:part_type] || 'text/html'
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