rails_email_preview 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84132ea530a47db404000e82a07251cd51706955
4
+ data.tar.gz: d0aef7d543f2138ddcf82f7a86e4cf538eb4f5b5
5
+ SHA512:
6
+ metadata.gz: ba0961461268dd1f986431b84799d185cfb4431c5d10e7881e2c682d4c5dd7447237ad2d090f3dd30289f1cb3b4d5b2da78839bdc677738368c8281011a04fe5
7
+ data.tar.gz: 014c0c7c244ff70acf5de3059ddcf39963948297409221cd12fed4ed258db7bef604f94f819223d1d42884580abd7f876945e0ff0c9953669e06ef5322705d04
data/README.md CHANGED
@@ -1,19 +1,15 @@
1
- RailsEmailPreview -- Visual email testing
1
+ Rails Email Preview
2
2
  ================================
3
3
 
4
- Preview plain text and html mail templates in your browser without redelivering it every time you make a change.
4
+ A Rails Engine to preview plain text and html email in your browser. Compatible with Rails 3 and 4.
5
5
 
6
- Inspired by MailView: https://github.com/37signals/mail_view/
7
- However, implemented as a Rails engine, with layouts and multiple mailers support.
8
-
9
- Compatible with Rails version >= 3 only.
10
-
11
- Usage
6
+ How to
12
7
  -----
13
8
 
14
- Since most emails do something interesting with database data, you'll need to write some scenarios to load messages with fake data. Its similar to writing mailer unit tests but you see a visual representation of the output instead.
9
+ You will need to provide data for preview of each email:
15
10
 
16
- class Notifier < ActionMailer::Base
11
+ # Say you have this mailer
12
+ class UserMailer < ActionMailer::Base
17
13
  def invitation(inviter, invitee)
18
14
  # ...
19
15
  end
@@ -21,75 +17,70 @@ Since most emails do something interesting with database data, you'll need to wr
21
17
  def welcome(user)
22
18
  # ...
23
19
  end
20
+ end
24
21
 
25
- class Preview
26
- # Pull data from existing fixtures
27
- def invitation
28
- account = Account.first
29
- inviter, invitee = account.users[0, 2]
30
- Notifier.invitation(inviter, invitee)
31
- end
32
-
33
- # Factory-like pattern
34
- def welcome
35
- user = User.create!
36
- mail = Notifier.welcome(user)
37
- user.destory
38
- mail
39
- end
22
+ # Define a Preview class with the same mail action names, but with no arguments
23
+ # mkdir -p app/mailer_previews/; touch app/mailer_previews/user_mailer_preview.rb
24
+ class UserMailerPreview
25
+ # preview methods should return Mail objects, e.g.:
26
+ def invitation
27
+ UserMailer.invitation mock_user('Alice'), mock_user('Bob')
28
+ end
29
+
30
+ def welcome
31
+ UserMailer.welcome mock_user
32
+ end
33
+
34
+ private
35
+ def mock_user(name = 'Bill Gates')
36
+ User.new(name: name, email: "user@test.com#{rand 100}").tap { |u| u.define_singleton_method(:id) { 123 + rand(100) } }
40
37
  end
41
38
  end
42
39
 
43
- The methods must return a Mail object.
44
40
 
45
- Since this is a Rails engine, it can be configured in an initializer:
41
+ Routing
42
+ -------
43
+
44
+ mount RailsEmailPreview::Engine, at: 'email_preview' # rails_email_preview.root_url #=> '/email_preview'
45
+
46
46
 
47
- In config/initializers/rails_email_preview.rb
47
+ Configuration
48
+ -------
49
+
50
+ # touch config/initializers/rails_email_preview.rb
48
51
 
49
52
  require 'rails_email_preview'
50
53
  RailsEmailPreview.setup do |config|
51
- config.preview_classes = [ Notifier::Preview ]
54
+ config.preview_classes = [ UserMailerPreview ]
52
55
  end
53
56
 
54
- # If you want to render it within the application layout, uncomment the following lines:
55
- # Rails.application.config.to_prepare do
56
- # RailsEmailPreview::ApplicationController.layout "application"
57
- # end
58
- # Note that if you do use it with your main_app layout, all the main_app URLs must be generated explicitly
59
- # E.g. you would need to change links like login_url to main_app.login_url
60
-
61
-
62
- Routing is very simple
57
+ # To render previews within layout other than the default one. NB: that layout must reference application urls via `main_app`, e.g. `main_app.login_url` (due to how isolated engines are in rails):
63
58
 
64
- In config/routes.rb add:
65
-
66
- if Rails.env.development?
67
- mount RailsEmailPreview::Engine, :at => 'email_preview' # You can choose any URL here
59
+ Rails.application.config.to_prepare do
60
+ RailsEmailPreview::ApplicationController.layout 'admin'
68
61
  end
69
62
 
70
- To get the url of RailsEmailPreview in your main app you can call rails_email_preview.root_url
71
-
72
63
 
73
64
  Premailer integration
74
65
  ---------------------
75
66
 
76
- [Premailer](https://github.com/alexdunae/premailer) (CSS inlining) integration can be done by using the <code>before_render</code> hook:
67
+ [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.
77
68
 
78
- For example, to process the previews with [ActionMailer Inline CSS](https://github.com/ndbroadbent/actionmailer_inline_css)
79
- can be done like so:
69
+ To integrate Premailer with rails you can use either [actionmailer_inline_css](https://github.com/ndbroadbent/actionmailer_inline_css) or [premailer-rails](https://github.com/fphilipe/premailer-rails).
80
70
 
81
- RailsEmailPreview.setup do |config|
82
- config.before_render do |message|
83
- ActionMailer::InlineCssHook.delivering_email(message)
84
- end
85
- end
71
+ For [actionmailer_inline_css](https://github.com/ndbroadbent/actionmailer_inline_css), add to `RailsEmailPreview.setup`:
72
+
73
+ config.before_render { |message| ActionMailer::InlineCssHook.delivering_email(message) }
74
+
75
+ For [premailer-rails](https://github.com/fphilipe/premailer-rails), add to `RailsEmailPreview.setup`:
76
+
77
+ config.before_render { |message| Premailer::Rails::Hook.delivering_email(message) }
86
78
 
87
- Interface
88
- ---------
89
79
 
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)
80
+ Customizing views
81
+ ---------------------
92
82
 
93
- As this is a rails engine, you can ovveride any of the views, or make them use your layout.
83
+ You can ovveride any `rails_email_preview` view by placing a file with the same path as in the gem in your project's `app/views`.
84
+ You can also extend the `RailsEmailPreview::EmailsController` for further customization.
94
85
 
95
- This project rocks and uses MIT-LICENSE.
86
+ This project rocks and uses MIT-LICENSE.
@@ -4,7 +4,7 @@
4
4
  html_url = if @mail.multipart? || @mail.content_type =~ %r(text/html)
5
5
  rails_email_preview.email_url(params.merge(:part_type => 'text/html'))
6
6
  end
7
- plain_url = if @mail.multipart? || @mail.content_type =~ %r(text/plain)
7
+ plain_url = if @mail.multipart? || @mail.content_type =~ %r(text/plain) || Object.const_defined?('PremailerRails')
8
8
  rails_email_preview.email_url(params.merge(:part_type => 'text/plain'))
9
9
  end
10
10
 
@@ -33,11 +33,6 @@
33
33
  %dd= @mail.to
34
34
 
35
35
  %iframe#src-iframe{:src => rails_email_preview.raw_email_url(params.slice(:mail_class, :mail_action, :part_type)),
36
- :width => "100%", :height => "800", :onload => 'emailLoaded()', :style => "display:none"}
36
+ :width => "100%", :height => "800", :onload => "document.getElementById('src-iframe').style.display = 'block';document.getElementById('loading').style.display = 'none'", :style => "display:none"}
37
37
  %pre#loading Loading...
38
38
 
39
- :javascript
40
- window.emailLoaded = function () {
41
- document.getElementById('src-iframe').style.display = 'block';
42
- document.getElementById('loading').style.display = 'none';
43
- };
data/config/routes.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  RailsEmailPreview::Engine.routes.draw do
2
2
  root :to => 'emails#index'
3
- match 'raw/:mail_class/:mail_action',
3
+ get 'raw/:mail_class/:mail_action',
4
4
  :as => :raw_email,
5
5
  :to => 'emails#show_raw',
6
6
  :mail_class => %r([\w/]+)
7
- match ':mail_class/:mail_action',
7
+ get ':mail_class/:mail_action',
8
8
  :as => :email,
9
9
  :to => 'emails#show',
10
10
  :mail_class => %r([\w/]+)
11
- end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsEmailPreview
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,72 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_email_preview
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gleb Mazovetskiy
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-02-05 00:00:00.000000000Z
11
+ date: 2013-06-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
- requirement: &16274540 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ~>
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.2'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *16274540
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: rails
27
- requirement: &16273020 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - ~>
31
+ - - '>='
31
32
  - !ruby/object:Gem::Version
32
33
  version: '3.2'
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *16273020
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
36
41
  - !ruby/object:Gem::Dependency
37
42
  name: haml
38
- requirement: &16272560 !ruby/object:Gem::Requirement
39
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
40
44
  requirements:
41
- - - ! '>='
45
+ - - '>='
42
46
  - !ruby/object:Gem::Version
43
47
  version: '0'
44
48
  type: :runtime
45
49
  prerelease: false
46
- version_requirements: *16272560
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: sass
49
- requirement: &16272100 !ruby/object:Gem::Requirement
50
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
51
58
  requirements:
52
- - - ! '>='
59
+ - - '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  type: :runtime
56
63
  prerelease: false
57
- version_requirements: *16272100
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
58
69
  description: Insert RailsEmailPreview description.
59
70
  email: glex.spb@gmail.com
60
71
  executables: []
61
72
  extensions: []
62
73
  extra_rdoc_files: []
63
74
  files:
75
+ - app/assets/stylesheets/rails_email_preview/application.css.sass
64
76
  - app/controllers/rails_email_preview/application_controller.rb
65
77
  - app/controllers/rails_email_preview/emails_controller.rb
66
- - app/assets/stylesheets/rails_email_preview/application.css.sass
78
+ - app/views/layouts/rails_email_preview/application.html.haml
67
79
  - app/views/rails_email_preview/emails/index.html.haml
68
80
  - app/views/rails_email_preview/emails/show.html.haml
69
- - app/views/layouts/rails_email_preview/application.html.haml
70
81
  - lib/rails_email_preview/engine.rb
71
82
  - lib/rails_email_preview/version.rb
72
83
  - lib/rails_email_preview.rb
@@ -77,26 +88,25 @@ files:
77
88
  - README.md
78
89
  homepage:
79
90
  licenses: []
91
+ metadata: {}
80
92
  post_install_message:
81
93
  rdoc_options: []
82
94
  require_paths:
83
95
  - lib
84
96
  required_ruby_version: !ruby/object:Gem::Requirement
85
- none: false
86
97
  requirements:
87
- - - ! '>='
98
+ - - '>='
88
99
  - !ruby/object:Gem::Version
89
100
  version: '0'
90
101
  required_rubygems_version: !ruby/object:Gem::Requirement
91
- none: false
92
102
  requirements:
93
- - - ! '>='
103
+ - - '>='
94
104
  - !ruby/object:Gem::Version
95
105
  version: '0'
96
106
  requirements: []
97
107
  rubyforge_project:
98
- rubygems_version: 1.8.11
108
+ rubygems_version: 2.0.3
99
109
  signing_key:
100
- specification_version: 3
101
- summary: Visual Email Preview for Rails >= 3, implemented as a Rails Engine. v0.0.4
110
+ specification_version: 4
111
+ summary: Visual Email Preview for Rails >= 3, implemented as a Rails Engine. v0.0.5
102
112
  test_files: []