rails_email_preview 0.2.14 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +7 -0
- data/Rakefile +7 -3
- data/app/controllers/rails_email_preview/emails_controller.rb +29 -34
- data/app/helpers/rails_email_preview/emails_helper.rb +4 -13
- data/app/models/rails_email_preview/preview.rb +71 -0
- data/app/views/layouts/rails_email_preview/email.html.slim +15 -0
- data/app/views/rails_email_preview/emails/_format_nav.html.slim +3 -3
- data/app/views/rails_email_preview/emails/_i18n_nav.html.slim +1 -1
- data/app/views/rails_email_preview/emails/index.html.slim +9 -16
- data/app/views/rails_email_preview/emails/show.html.slim +1 -1
- data/app/views/rails_email_preview/emails/show_body.html.slim +1 -0
- data/config/i18n-tasks.yml +6 -0
- data/config/routes.rb +3 -3
- data/lib/rails_email_preview.rb +10 -2
- data/lib/rails_email_preview/integrations/comfortable_mexica_sofa.rb +3 -5
- data/lib/rails_email_preview/version.rb +1 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c104f566ecd1afcf4b0cd18f5c3b381bf5e6b5bf
|
4
|
+
data.tar.gz: 0920be3ca35eece7accba7a99bb8c3fba89dbe70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6371877837cc223fb9d7caf8974e2b4f2e640faea4625f4edf081936c4cafab8a323bf7cec516def9b3b93399808288a1a5d828f01f0251d8af0d8eb58bd0a23
|
7
|
+
data.tar.gz: 61d62058d0313dcd163800b3f4209b97118a8fdaaa7fa15722d4cc6c7b2c38b0887e03f53d212c8502ceca09153efff92bc13d00ba93411aa803cb57049b489c
|
data/Gemfile
CHANGED
@@ -2,7 +2,14 @@ source "http://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
platform :rbx do
|
6
|
+
gem 'rubysl', '~> 2.0'
|
7
|
+
gem 'rubysl-test-unit', '~> 2.0'
|
8
|
+
gem 'racc'
|
9
|
+
end
|
10
|
+
|
5
11
|
group :development, :test do
|
12
|
+
gem 'i18n-tasks'
|
6
13
|
gem 'capybara', '>= 0.4.0'
|
7
14
|
gem 'rspec', '2.12.0' #, git: 'https://github.com/rspec/rspec'
|
8
15
|
gem 'rspec-rails' #, git: 'https://github.com/rspec/rspec-rails'
|
data/Rakefile
CHANGED
@@ -6,12 +6,16 @@ rescue LoadError
|
|
6
6
|
end
|
7
7
|
|
8
8
|
# Load dummy app tasks
|
9
|
-
|
10
|
-
|
9
|
+
if ENV['DUMMY']
|
10
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
11
|
+
load 'rails/tasks/engine.rake'
|
12
|
+
end
|
11
13
|
|
12
14
|
Bundler::GemHelper.install_tasks
|
13
15
|
|
14
16
|
require 'rspec/core/rake_task'
|
15
17
|
RSpec::Core::RakeTask.new(:spec)
|
16
18
|
|
17
|
-
|
19
|
+
load 'tasks/i18n-tasks.rake'
|
20
|
+
|
21
|
+
task default: :spec
|
@@ -1,49 +1,36 @@
|
|
1
1
|
class RailsEmailPreview::EmailsController < ::RailsEmailPreview::ApplicationController
|
2
2
|
include ERB::Util
|
3
|
-
before_filter :
|
3
|
+
before_filter :load_preview, except: :index
|
4
4
|
before_filter :set_email_preview_locale
|
5
5
|
|
6
6
|
# list screen
|
7
7
|
def index
|
8
|
-
@
|
8
|
+
@previews = ::RailsEmailPreview::Preview.all
|
9
|
+
@previews_by_class = ::RailsEmailPreview::Preview.all_by_preview_class
|
9
10
|
end
|
10
11
|
|
11
12
|
# preview screen
|
12
13
|
def show
|
13
14
|
I18n.with_locale @email_locale do
|
14
15
|
@part_type = params[:part_type] || 'text/html'
|
15
|
-
if @
|
16
|
-
@mail = preview_mail
|
16
|
+
if @preview.respond_to?(:preview_mail)
|
17
|
+
@mail = @preview.preview_mail
|
17
18
|
else
|
18
|
-
raise ArgumentError.new("#{@
|
19
|
+
raise ArgumentError.new("#{@preview} is not a preview class, does not respond_to?(:preview_mail)")
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
24
|
# render actual email content
|
24
|
-
def
|
25
|
+
def show_body
|
25
26
|
I18n.with_locale @email_locale do
|
26
|
-
@
|
27
|
-
|
28
|
-
if @part_type == 'raw'
|
29
|
-
body = "<pre id='raw_message'>#{html_escape(@mail.to_s)}</pre>"
|
30
|
-
else
|
31
|
-
if @mail.multipart?
|
32
|
-
body_part = (@part_type =~ /html/ ? @mail.html_part : @mail.text_part)
|
33
|
-
else
|
34
|
-
body_part = @mail
|
35
|
-
end
|
36
|
-
body = body_part.body
|
37
|
-
if body_part.content_type =~ /plain/
|
38
|
-
body = "<pre id='message_body'>#{body}</body>"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
render text: body, layout: false
|
27
|
+
@mail_body = mail_body(@preview, @part_type)
|
28
|
+
render :show_body, layout: 'rails_email_preview/email'
|
42
29
|
end
|
43
30
|
end
|
44
31
|
|
45
32
|
def test_deliver
|
46
|
-
redirect_url = rep_email_url(params.slice(:mail_class, :mail_action, :email_locale))
|
33
|
+
redirect_url = rails_email_preview.rep_email_url(params.slice(:mail_class, :mail_action, :email_locale))
|
47
34
|
if (address = params[:recipient_email]).blank? || address !~ /@/
|
48
35
|
redirect_to redirect_url, alert: t('rep.test_deliver.provide_email')
|
49
36
|
return
|
@@ -70,24 +57,32 @@ class RailsEmailPreview::EmailsController < ::RailsEmailPreview::ApplicationCont
|
|
70
57
|
end
|
71
58
|
end
|
72
59
|
|
73
|
-
def
|
74
|
-
RequestStore.store[:rep_edit_links] = true if
|
75
|
-
mail =
|
76
|
-
mail
|
60
|
+
def mail_body(preview, part_type, edit_links = (part_type == 'text/html'))
|
61
|
+
RequestStore.store[:rep_edit_links] = true if edit_links
|
62
|
+
mail = preview.preview_mail
|
63
|
+
RailsEmailPreview.run_before_render(mail, preview)
|
64
|
+
return "<pre id='raw_message'>#{html_escape(mail.to_s)}</pre>".html_safe if part_type == 'raw'
|
65
|
+
|
66
|
+
body_part = if mail.multipart?
|
67
|
+
(part_type =~ /html/ ? mail.html_part : mail.text_part)
|
68
|
+
else
|
69
|
+
mail
|
70
|
+
end
|
71
|
+
if body_part.content_type =~ /plain/
|
72
|
+
"<pre id='message_body'>#{html_escape(body_part.body.to_s)}</pre>".html_safe
|
73
|
+
else
|
74
|
+
body_part.body.to_s.html_safe
|
75
|
+
end
|
77
76
|
end
|
78
77
|
|
79
78
|
def set_email_preview_locale
|
80
|
-
@email_locale = (params[:email_locale] || I18n.default_locale).to_s
|
79
|
+
@email_locale = (params[:email_locale] || RailsEmailPreview.default_email_locale || I18n.default_locale).to_s
|
81
80
|
end
|
82
81
|
|
83
82
|
private
|
84
83
|
|
85
|
-
def
|
86
|
-
@
|
87
|
-
(pc.is_a?(String) ? pc : pc.name).underscore == params[:mail_class]
|
88
|
-
}
|
89
|
-
@preview_class = @preview_class.constantize if @preview_class.is_a?(String)
|
90
|
-
@mail_action = params[:mail_action]
|
84
|
+
def load_preview
|
85
|
+
@preview = ::RailsEmailPreview::Preview[params[:preview_id]] or raise ActionController::RoutingError.new('Not Found')
|
91
86
|
@part_type = params[:part_type] || 'text/html'
|
92
87
|
end
|
93
88
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module RailsEmailPreview::EmailsHelper
|
2
|
-
def current_email_name
|
3
|
-
"#{preview_class_human_name}: #{@mail_action.to_s.humanize}"
|
4
|
-
end
|
5
2
|
|
6
|
-
|
7
|
-
|
3
|
+
MIME_LABELS = { 'text/html' => 'HTML', 'text/plain' => 'Text', 'raw' => 'Raw'}
|
4
|
+
|
5
|
+
def format_label(mime_type)
|
6
|
+
MIME_LABELS[mime_type]
|
8
7
|
end
|
9
8
|
|
10
9
|
def change_locale_attr(locale)
|
@@ -46,14 +45,6 @@ module RailsEmailPreview::EmailsHelper
|
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
49
|
-
def email_methods(m)
|
50
|
-
m.constantize.instance_methods(false).map(&:to_s).sort
|
51
|
-
end
|
52
|
-
|
53
|
-
def total_emails
|
54
|
-
@total_emails ||= @preview_class_names.sum { |p| email_methods(p).length }
|
55
|
-
end
|
56
|
-
|
57
48
|
def split_in_halves(elements, &weight)
|
58
49
|
tot_w = elements.map(&weight).sum
|
59
50
|
cols = [elements.dup, []]
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module RailsEmailPreview
|
2
|
+
# This class represents an email preview
|
3
|
+
class Preview
|
4
|
+
attr_accessor :id, :preview_class_name, :preview_method
|
5
|
+
|
6
|
+
def initialize(attr = {})
|
7
|
+
attr.each { |k, v| self.send "#{k}=", v }
|
8
|
+
end
|
9
|
+
|
10
|
+
def locales
|
11
|
+
I18n.available_locales
|
12
|
+
end
|
13
|
+
|
14
|
+
def formats
|
15
|
+
%w(text/html text/plain raw)
|
16
|
+
end
|
17
|
+
|
18
|
+
def preview_mail
|
19
|
+
preview_class_name.constantize.new.send(preview_method)
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
@name ||= "#{group_name}: #{method_name}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def method_name
|
27
|
+
@action_name ||= preview_method.to_s.humanize
|
28
|
+
end
|
29
|
+
|
30
|
+
def group_name
|
31
|
+
@group_name ||= preview_class_name.to_s.underscore.sub(/(_mailer)?_preview$/, '').humanize
|
32
|
+
end
|
33
|
+
|
34
|
+
class << self
|
35
|
+
def find(email_id)
|
36
|
+
@by_id[email_id]
|
37
|
+
end
|
38
|
+
|
39
|
+
alias_method :[], :find
|
40
|
+
|
41
|
+
attr_reader :all, :all_by_preview_class
|
42
|
+
|
43
|
+
def mail_methods(mailer)
|
44
|
+
mailer.public_instance_methods(false).map(&:to_s)
|
45
|
+
end
|
46
|
+
|
47
|
+
def load_all(class_names)
|
48
|
+
@all = []
|
49
|
+
@by_id = {}
|
50
|
+
class_names.each do |preview_class_name|
|
51
|
+
preview_class = preview_class_name.constantize
|
52
|
+
|
53
|
+
mail_methods(preview_class).sort.each do |preview_method|
|
54
|
+
mailer_method = preview_method
|
55
|
+
id = "#{preview_class_name.underscore}-#{mailer_method}"
|
56
|
+
|
57
|
+
email = new(
|
58
|
+
id: id,
|
59
|
+
preview_class_name: preview_class_name,
|
60
|
+
preview_method: preview_method
|
61
|
+
)
|
62
|
+
@all << email
|
63
|
+
@by_id[id] = email
|
64
|
+
end
|
65
|
+
end
|
66
|
+
@all.sort_by!(&:name)
|
67
|
+
@all_by_preview_class = @all.group_by(&:preview_class_name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
doctype html
|
2
|
+
= "\n"
|
3
|
+
html
|
4
|
+
head
|
5
|
+
css:
|
6
|
+
#message_body, #raw_message {
|
7
|
+
font-family: Monaco, Menlo, Consolas, "Courier New", monospace;
|
8
|
+
word-break: break-word;
|
9
|
+
}
|
10
|
+
|
11
|
+
= yield(:head)
|
12
|
+
body
|
13
|
+
#content.container
|
14
|
+
= render 'layouts/rails_email_preview/flash_notices'
|
15
|
+
= yield
|
@@ -1,5 +1,5 @@
|
|
1
1
|
div class=rep_btn_group_class
|
2
|
-
-
|
3
|
-
a.btn-xs *change_format_attr(
|
4
|
-
=
|
2
|
+
- @preview.formats.each do |format|
|
3
|
+
a.btn-xs *change_format_attr(format)
|
4
|
+
= format_label format
|
5
5
|
|
@@ -1,24 +1,17 @@
|
|
1
|
-
h1
|
2
|
-
| #{t '.list_title'}
|
3
|
-
|
4
|
-
- previews_group = proc do |m|
|
5
|
-
- capture do
|
6
|
-
h2 = preview_class_human_name(m)
|
7
|
-
ul class=rep_style[:list_group_class]
|
8
|
-
- email_methods(m).each do |method|
|
9
|
-
li class=rep_style[:list_group_item_class]
|
10
|
-
a href=rails_email_preview.rep_email_url(mail_class: m.to_s.underscore, mail_action: method.to_s, email_locale: @email_locale)
|
11
|
-
= method.to_s.humanize
|
1
|
+
h1 = t '.list_title'
|
12
2
|
|
13
3
|
div class=rep_row_class
|
14
|
-
- split_in_halves(@
|
4
|
+
- split_in_halves(@previews_by_class.keys) { |c| @previews_by_class[c].length }.each do |classes|
|
15
5
|
div class=rep_col_class(6)
|
16
|
-
- classes.each do |
|
17
|
-
=
|
6
|
+
- classes.map { |c| @previews_by_class[c] }.each do |previews|
|
7
|
+
h2 = previews[0].group_name
|
8
|
+
div class=rep_style[:list_group_class]
|
9
|
+
- previews.each do |p|
|
10
|
+
a class=rep_style[:list_group_item_class] href=rails_email_preview.rep_email_url(preview_id: p.id, email_locale: @email_locale)
|
11
|
+
= p.method_name
|
18
12
|
|
19
13
|
hr
|
20
|
-
|
21
14
|
p.text-center.text-small.text-info
|
22
|
-
| #{t 'rep.base.email', count:
|
15
|
+
| #{t 'rep.base.email', count: @previews.length} #{t 'rep.base.in'} #{t 'rep.base.mailer', count: @previews_by_class.values.length }
|
23
16
|
br
|
24
17
|
a href="https://github.com/glebm/rails_email_preview" target='_blank' REP #{RailsEmailPreview::VERSION}
|
@@ -3,7 +3,7 @@
|
|
3
3
|
.pull-left
|
4
4
|
ul.breadcrumb
|
5
5
|
li: a href=rails_email_preview.rep_emails_url(email_locale: @email_locale) #{t '.breadcrumb_list'}
|
6
|
-
li.active: a href=(request.url) =
|
6
|
+
li.active: a href=(request.url) = @preview.name
|
7
7
|
|
8
8
|
div class=rep_style[:panel_class]
|
9
9
|
div class=rep_style[:panel_body_class]
|
@@ -0,0 +1 @@
|
|
1
|
+
= @mail_body
|
data/config/routes.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
RailsEmailPreview::Engine.routes.draw do
|
2
2
|
get '/' => 'emails#index', as: :rep_emails
|
3
3
|
|
4
|
-
get 'raw/:
|
5
|
-
get ':
|
6
|
-
post 'test_deliver/:
|
4
|
+
get 'raw/:preview_id' => 'emails#show_body', as: :rep_raw_email
|
5
|
+
get ':preview_id' => 'emails#show', as: :rep_email
|
6
|
+
post 'test_deliver/:preview_id' => 'emails#test_deliver', as: :rep_test_deliver
|
7
7
|
|
8
8
|
# define alias for the root url as part of stable api
|
9
9
|
get '/' => 'emails#index', as: :rep_root
|
data/lib/rails_email_preview.rb
CHANGED
@@ -19,6 +19,9 @@ module RailsEmailPreview
|
|
19
19
|
# auto-loading configured in initializer
|
20
20
|
mattr_accessor :preview_classes
|
21
21
|
|
22
|
+
# default email locale
|
23
|
+
mattr_accessor :default_email_locale
|
24
|
+
|
22
25
|
# send email button
|
23
26
|
mattr_accessor :enable_send_email
|
24
27
|
self.enable_send_email = true
|
@@ -38,6 +41,11 @@ module RailsEmailPreview
|
|
38
41
|
}
|
39
42
|
|
40
43
|
class << self
|
44
|
+
def preview_classes=(classes)
|
45
|
+
@preview_classes = classes
|
46
|
+
RailsEmailPreview::Preview.load_all(classes)
|
47
|
+
end
|
48
|
+
|
41
49
|
def layout=(layout)
|
42
50
|
[::RailsEmailPreview::ApplicationController, ::RailsEmailPreview::EmailsController].each { |ctrl| ctrl.layout layout }
|
43
51
|
if layout && layout !~ %r(^rails_email_preview/)
|
@@ -46,9 +54,9 @@ module RailsEmailPreview
|
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
49
|
-
def run_before_render(mail,
|
57
|
+
def run_before_render(mail, preview)
|
50
58
|
(defined?(@hooks) && @hooks[:before_render] || []).each do |block|
|
51
|
-
block.call(mail,
|
59
|
+
block.call(mail, preview)
|
52
60
|
end
|
53
61
|
end
|
54
62
|
|
@@ -93,10 +93,8 @@ module RailsEmailPreview
|
|
93
93
|
id_prefix = 'email-'
|
94
94
|
return unless snippet && snippet.identifier && snippet.identifier.starts_with?(id_prefix)
|
95
95
|
mailer_cl, act = snippet.identifier[id_prefix.length..-1].split('-')
|
96
|
-
|
97
|
-
|
98
|
-
mail_action: act,
|
99
|
-
email_locale: snippet.site.locale}
|
96
|
+
{ preview_id: "#{mailer_cl}_preview-#{act}",
|
97
|
+
email_locale: snippet.site.locale }
|
100
98
|
end
|
101
99
|
end
|
102
100
|
end
|
@@ -108,4 +106,4 @@ ActionMailer::Base.module_eval do
|
|
108
106
|
end
|
109
107
|
|
110
108
|
require 'comfortable_mexican_sofa'
|
111
|
-
ComfortableMexicanSofa::ViewHooks.add :navigation, 'integrations/cms/customize_cms_for_rails_email_preview'
|
109
|
+
ComfortableMexicanSofa::ViewHooks.add :navigation, 'integrations/cms/customize_cms_for_rails_email_preview'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_email_preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gleb Mazovetskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -95,9 +95,11 @@ files:
|
|
95
95
|
- app/controllers/rails_email_preview/application_controller.rb
|
96
96
|
- app/controllers/rails_email_preview/emails_controller.rb
|
97
97
|
- app/helpers/rails_email_preview/emails_helper.rb
|
98
|
+
- app/models/rails_email_preview/preview.rb
|
98
99
|
- app/views/integrations/cms/_customize_cms_for_rails_email_preview.html.slim
|
99
100
|
- app/views/layouts/rails_email_preview/_flash_notices.html.slim
|
100
101
|
- app/views/layouts/rails_email_preview/application.html.slim
|
102
|
+
- app/views/layouts/rails_email_preview/email.html.slim
|
101
103
|
- app/views/rails_email_preview/emails/_email_iframe.html.slim
|
102
104
|
- app/views/rails_email_preview/emails/_format_nav.html.slim
|
103
105
|
- app/views/rails_email_preview/emails/_headers.html.slim
|
@@ -105,6 +107,7 @@ files:
|
|
105
107
|
- app/views/rails_email_preview/emails/_send_form.html.slim
|
106
108
|
- app/views/rails_email_preview/emails/index.html.slim
|
107
109
|
- app/views/rails_email_preview/emails/show.html.slim
|
110
|
+
- app/views/rails_email_preview/emails/show_body.html.slim
|
108
111
|
- lib/generators/rails_email_preview/install_generator.rb
|
109
112
|
- lib/generators/rails_email_preview/update_previews_generator.rb
|
110
113
|
- lib/rails_email_preview/delivery_handler.rb
|
@@ -113,6 +116,7 @@ files:
|
|
113
116
|
- lib/rails_email_preview/main_app_route_delegator.rb
|
114
117
|
- lib/rails_email_preview/version.rb
|
115
118
|
- lib/rails_email_preview.rb
|
119
|
+
- config/i18n-tasks.yml
|
116
120
|
- config/initializers/rails_email_preview.rb
|
117
121
|
- config/locales/de.yml
|
118
122
|
- config/locales/en.yml
|
@@ -141,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
145
|
version: '0'
|
142
146
|
requirements: []
|
143
147
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.0.14
|
145
149
|
signing_key:
|
146
150
|
specification_version: 4
|
147
151
|
summary: Preview emails in browser (rails engine)
|