Class: SimpleEmailPreview::EmailsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- SimpleEmailPreview::EmailsController
- Includes:
- ERB::Util
- Defined in:
- app/controllers/simple_email_preview/emails_controller.rb
Instance Method Summary collapse
- #add_breadcrumbs ⇒ Object
-
#index ⇒ Object
List of emails.
- #set_title ⇒ Object
-
#show ⇒ Object
Preview an email.
-
#show_attachment ⇒ Object
Download attachment.
-
#show_body ⇒ Object
Render email body iframe HTML.
-
#show_headers ⇒ Object
Render headers partial.
-
#test_deliver ⇒ Object
Really deliver an email.
Instance Method Details
#add_breadcrumbs ⇒ Object
13 14 15 |
# File 'app/controllers/simple_email_preview/emails_controller.rb', line 13 def super if defined?(super) end |
#index ⇒ Object
List of emails
26 27 28 29 30 31 32 33 |
# File 'app/controllers/simple_email_preview/emails_controller.rb', line 26 def index if defined?(super) super else @previews = Preview.all @list = PreviewListPresenter.new(@previews) end end |
#set_title ⇒ Object
17 18 19 20 21 22 23 |
# File 'app/controllers/simple_email_preview/emails_controller.rb', line 17 def set_title if defined?(super) super else @title = t('email_preview') end end |
#show ⇒ Object
Preview an email
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/simple_email_preview/emails_controller.rb', line 36 def show if defined?(super) super else prevent_browser_caching # with_email_locale do if @preview.respond_to?(:preview_mail) @mail, body = mail_and_body @mail_body_html = render_to_string(inline: body, layout: 'simple_email_preview/email') else raise ArgumentError, "#{@preview} is not a preview class, does not respond_to?(:preview_mail)" end end end |
#show_attachment ⇒ Object
Download attachment
71 72 73 74 75 76 77 |
# File 'app/controllers/simple_email_preview/emails_controller.rb', line 71 def with_email_locale do filename = "#{params[:filename]}.#{params[:format]}" = preview_mail(false)..find { |a| a.filename == filename } send_data .body.raw_source, filename: filename end end |
#show_body ⇒ Object
Render email body iframe HTML. Used by the CMS integration to provide a link back to Show from Edit.
86 87 88 89 90 91 92 93 |
# File 'app/controllers/simple_email_preview/emails_controller.rb', line 86 def show_body prevent_browser_caching cms_edit_links! with_email_locale do _, body = mail_and_body render inline: body, layout: 'simple_email_preview/email' end end |
#show_headers ⇒ Object
Render headers partial. Used by the CMS integration to refetch headers after editing.
80 81 82 83 |
# File 'app/controllers/simple_email_preview/emails_controller.rb', line 80 def show_headers mail = with_email_locale { mail_and_body.first } render partial: 'simple_email_preview/emails/headers', locals: { mail: mail } end |
#test_deliver ⇒ Object
Really deliver an email
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/simple_email_preview/emails_controller.rb', line 52 def test_deliver redirect_url = simple_email_preview.rep_email_url(preview_params.except(:recipient_email)) if (address = params[:recipient_email]).blank? || address !~ /@/ redirect_to redirect_url, alert: t('rep.test_deliver.provide_email') return end with_email_locale do delivery_handler = SimpleEmailPreview::DeliveryHandler.new(preview_mail, to: address, cc: nil, bcc: nil) deliver_email!(delivery_handler.mail) end delivery_method = Rails.application.config.action_mailer.delivery_method if delivery_method redirect_to redirect_url, notice: t('rep.test_deliver.sent_notice', address: address, delivery_method: delivery_method) else redirect_to redirect_url, alert: t('rep.test_deliver.no_delivery_method', environment: Rails.env) end end |