rails_email_preview 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -1
- data/app/controllers/rails_email_preview/emails_controller.rb +20 -9
- data/app/views/rails_email_preview/emails/index.html.haml +5 -5
- data/app/views/rails_email_preview/emails/show.html.haml +18 -6
- data/lib/rails_email_preview.rb +14 -2
- data/lib/rails_email_preview/version.rb +1 -1
- metadata +11 -11
data/README.md
CHANGED
@@ -69,9 +69,27 @@ In config/routes.rb add:
|
|
69
69
|
|
70
70
|
To get the url of RailsEmailPreview in your main app you can call rails_email_preview.root_url
|
71
71
|
|
72
|
+
|
73
|
+
Premailer integration
|
74
|
+
---------------------
|
75
|
+
|
76
|
+
[Premailer](https://github.com/alexdunae/premailer) (CSS inlining) integration can be done by using the <code>before_render</code> hook:
|
77
|
+
|
78
|
+
For example, to process the previews with [ActionMailer Inline CSS](https://github.com/ndbroadbent/actionmailer_inline_css)
|
79
|
+
can be done like so:
|
80
|
+
|
81
|
+
RailsEmailPreview.setup do |config|
|
82
|
+
config.before_render do |message|
|
83
|
+
ActionMailer::InlineCssHook.delivering_email(message)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
72
87
|
Interface
|
73
88
|
---------
|
74
89
|
|
75
|
-
|
90
|
+
![List of application mails](http://4.bp.blogspot.com/-hkZlhO7ze8I/Tylinqxas2I/AAAAAAAABQo/17eEkwBkdnQ/s1600/email-preview-index.png)
|
91
|
+
![Viewing an email](http://3.bp.blogspot.com/-Y6aM_RVrZXE/TyliuI3P6AI/AAAAAAAABQ0/_YJkeC9D5xg/s1600/email-preview-show.png)
|
92
|
+
|
93
|
+
As this is a rails engine, you can ovveride any of the views, or make them use your layout.
|
76
94
|
|
77
95
|
This project rocks and uses MIT-LICENSE.
|
@@ -1,7 +1,9 @@
|
|
1
1
|
class RailsEmailPreview::EmailsController < RailsEmailPreview::ApplicationController
|
2
|
+
include ERB::Util
|
2
3
|
before_filter :load_preview_class, :except => :index
|
4
|
+
|
3
5
|
def index
|
4
|
-
@
|
6
|
+
@preview_class_names = (RailsEmailPreview.preview_classes || []).map { |klass| klass.is_a?(String) ? klass : klass.name }
|
5
7
|
end
|
6
8
|
|
7
9
|
def show
|
@@ -10,20 +12,29 @@ class RailsEmailPreview::EmailsController < RailsEmailPreview::ApplicationContro
|
|
10
12
|
|
11
13
|
def show_raw
|
12
14
|
@mail = @preview_class.new.send(params[:mail_action])
|
13
|
-
|
14
|
-
if @
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
RailsEmailPreview.run_before_render(@mail)
|
16
|
+
if @part_type == 'raw'
|
17
|
+
body = "<pre id='raw_message'>#{html_escape(@mail.to_s)}</pre>"
|
18
|
+
else
|
19
|
+
body_part = @mail
|
20
|
+
if @mail.multipart?
|
21
|
+
body_part = @mail.parts.find { |part| part.content_type.start_with?(@part_type) } || @mail.parts.first
|
22
|
+
end
|
23
|
+
body = body_part.body
|
24
|
+
if body_part.content_type =~ /plain/
|
25
|
+
body = "<pre id='message_body'>#{body}</body>"
|
26
|
+
end
|
20
27
|
end
|
28
|
+
|
21
29
|
render :text => body, :layout => false
|
22
30
|
end
|
23
31
|
|
24
32
|
private
|
25
33
|
def load_preview_class
|
26
|
-
@preview_class = (RailsEmailPreview.preview_classes || []).find {|pc|
|
34
|
+
@preview_class = (RailsEmailPreview.preview_classes || []).find { |pc|
|
35
|
+
(pc.is_a?(String) ? pc : pc.name).underscore == params[:mail_class]
|
36
|
+
}
|
37
|
+
@preview_class = @preview_class.constantize if @preview_class.is_a?(String)
|
27
38
|
@part_type = params[:part_type] || 'text/html'
|
28
39
|
end
|
29
40
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
%h1
|
1
|
+
%h1 Application Emails
|
2
2
|
%ul
|
3
|
-
- @
|
3
|
+
- @preview_class_names.each do |m|
|
4
4
|
%li
|
5
|
-
%h2= m.
|
5
|
+
%h2= m.underscore.humanize
|
6
6
|
%ul
|
7
|
-
- m.instance_methods(false).map(&:to_s).each do |method|
|
7
|
+
- m.constantize.instance_methods(false).map(&:to_s).each do |method|
|
8
8
|
%li
|
9
|
-
%a{:href => rails_email_preview.email_url(:mail_class => m.
|
9
|
+
%a{:href => rails_email_preview.email_url(:mail_class => m.underscore, :mail_action => method)}= method.humanize
|
@@ -1,11 +1,23 @@
|
|
1
1
|
%a#back-to-all{:href => rails_email_preview.root_url} « Back to list
|
2
|
+
:ruby
|
3
|
+
raw_url = rails_email_preview.email_url(params.merge(:part_type => 'raw'))
|
4
|
+
html_url = if @mail.multipart? || @mail.content_type =~ %r(text/html)
|
5
|
+
rails_email_preview.email_url(params.merge(:part_type => 'text/html'))
|
6
|
+
end
|
7
|
+
plain_url = if @mail.multipart? || @mail.content_type =~ %r(text/plain)
|
8
|
+
rails_email_preview.email_url(params.merge(:part_type => 'text/plain'))
|
9
|
+
end
|
10
|
+
|
2
11
|
#message_headers
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
12
|
+
%p.alternate
|
13
|
+
- if @part_type != 'raw'
|
14
|
+
%a{:href => raw_url} View Original Message (raw)
|
15
|
+
%br
|
16
|
+
- if @part_type != 'text/html' && html_url
|
17
|
+
%a{:href => html_url} View HTML version
|
18
|
+
%br
|
19
|
+
- if @part_type != 'text/plain' && plain_url
|
20
|
+
%a{:href => plain_url} View plain text version
|
9
21
|
%dl
|
10
22
|
%dt From:
|
11
23
|
%dd= @mail.from
|
data/lib/rails_email_preview.rb
CHANGED
@@ -3,7 +3,19 @@ require 'rails_email_preview/engine'
|
|
3
3
|
module RailsEmailPreview
|
4
4
|
mattr_accessor :preview_classes
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
class << self
|
7
|
+
def run_before_render(mail)
|
8
|
+
(defined?(@hooks) && @hooks[:before_render] || []).each do |block|
|
9
|
+
block.call(mail)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def before_render(&block)
|
14
|
+
((@hooks ||= {})[:before_render] ||= []) << block
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup
|
18
|
+
yield self
|
19
|
+
end
|
8
20
|
end
|
9
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_email_preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01
|
12
|
+
date: 2012-02-01 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &16757680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.2'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *16757680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &16756180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.2'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *16756180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: haml
|
38
|
-
requirement: &
|
38
|
+
requirement: &16755720 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *16755720
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sass
|
49
|
-
requirement: &
|
49
|
+
requirement: &16755260 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *16755260
|
58
58
|
description: Insert RailsEmailPreview description.
|
59
59
|
email: glex.spb@gmail.com
|
60
60
|
executables: []
|
@@ -98,5 +98,5 @@ rubyforge_project:
|
|
98
98
|
rubygems_version: 1.8.11
|
99
99
|
signing_key:
|
100
100
|
specification_version: 3
|
101
|
-
summary: Visual Email Preview for Rails >= 3, implemented as a Rails Engine. v0.0.
|
101
|
+
summary: Visual Email Preview for Rails >= 3, implemented as a Rails Engine. v0.0.3
|
102
102
|
test_files: []
|