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 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
- ToDo: Add a screenshot
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
- @preview_classes = (RailsEmailPreview.preview_classes || [])
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
- body_part = @mail
14
- if @mail.multipart?
15
- body_part = @mail.parts.find { |part| part.content_type.start_with?(@part_type) } || @mail.parts.first
16
- end
17
- body = body_part.body
18
- if body_part.content_type =~ /plain/
19
- body = "<pre id='message_body'>#{body}</body>"
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| pc.name.underscore == params[:mail_class]}
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 Available Mailers
1
+ %h1 Application Emails
2
2
  %ul
3
- - @preview_classes.each do |m|
3
+ - @preview_class_names.each do |m|
4
4
  %li
5
- %h2= m.name
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.name.underscore, :mail_action => method)}= method
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} &laquo; 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
- - if @mail.multipart?
4
- %p.alternate
5
- - if @part_type == 'text/html'
6
- %a{:href => rails_email_preview.email_url(params.merge(:part_type => 'text/plain'))} View plain text version
7
- - else
8
- %a{:href => rails_email_preview.email_url(params.merge(:part_type => 'text/html'))} View HTML version
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
@@ -3,7 +3,19 @@ require 'rails_email_preview/engine'
3
3
  module RailsEmailPreview
4
4
  mattr_accessor :preview_classes
5
5
 
6
- def self.setup
7
- yield self
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
@@ -1,3 +1,3 @@
1
1
  module RailsEmailPreview
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  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.2
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-30 00:00:00.000000000Z
12
+ date: 2012-02-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &20440480 !ruby/object:Gem::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: *20440480
24
+ version_requirements: *16757680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &20438980 !ruby/object:Gem::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: *20438980
35
+ version_requirements: *16756180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: haml
38
- requirement: &20438580 !ruby/object:Gem::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: *20438580
46
+ version_requirements: *16755720
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sass
49
- requirement: &20438120 !ruby/object:Gem::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: *20438120
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.2
101
+ summary: Visual Email Preview for Rails >= 3, implemented as a Rails Engine. v0.0.3
102
102
  test_files: []