rails_email_preview 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "capybara", ">= 0.4.0"
6
+ gem "sqlite3"
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ RailsEmailPreview -- Visual email testing
2
+ ================================
3
+
4
+ Preview plain text and html mail templates in your browser without redelivering it every time you make a change.
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
12
+ -----
13
+
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.
15
+
16
+ class Notifier < ActionMailer::Base
17
+ def invitation(inviter, invitee)
18
+ # ...
19
+ end
20
+
21
+ def welcome(user)
22
+ # ...
23
+ end
24
+
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
40
+ end
41
+ end
42
+
43
+ The methods must return a Mail object.
44
+
45
+ Since this is a Rails engine, it can be configured in an initializer:
46
+
47
+ In config/initializers/rails_email_preview.rb
48
+
49
+ require 'rails_email_preview'
50
+ RailsEmailPreview.setup do |config|
51
+ config.preview_classes = [ Notifier::Preview ]
52
+ end
53
+
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
63
+
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
68
+ end
69
+
70
+ To get the url of RailsEmailPreview in your main app you can call rails_email_preview.root_url
71
+
72
+ Interface
73
+ ---------
74
+
75
+ ToDo: Add a screenshot
76
+
77
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new(:test) do |t|
15
+ t.libs << 'lib'
16
+ t.libs << 'test'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = false
19
+ end
20
+
21
+ task :default => :test
22
+
23
+ Rake::RDocTask.new(:rdoc) do |rdoc|
24
+ rdoc.rdoc_dir = 'rdoc'
25
+ rdoc.title = 'RailsEmailPreview'
26
+ rdoc.options << '--line-numbers' << '--inline-source'
27
+ rdoc.rdoc_files.include('README.rdoc')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
@@ -0,0 +1,38 @@
1
+ #message_headers
2
+ height: 85px
3
+ padding: 10px 0 0 0
4
+ margin: 0
5
+ background: #fff
6
+ font-size: 12px
7
+ font-family: "Lucida Grande"
8
+ border-bottom: 1px solid #dedede
9
+ overflow: hidden
10
+
11
+ dl
12
+ margin: 0
13
+ padding: 0
14
+
15
+
16
+ dt
17
+ width: 60px
18
+ padding: 1px
19
+ float: left
20
+ text-align: right
21
+ font-weight: bold
22
+ color: #7f7f7f
23
+
24
+
25
+ dd
26
+ margin-left: 70px
27
+ padding: 1px
28
+
29
+
30
+ p.alternate
31
+ position: absolute
32
+ top: 0
33
+ right: 15px
34
+
35
+
36
+ p.alternate a
37
+ color: #09c
38
+
@@ -0,0 +1,5 @@
1
+ module RailsEmailPreview
2
+ class ApplicationController < ::ApplicationController
3
+
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ class RailsEmailPreview::EmailsController < RailsEmailPreview::ApplicationController
2
+ before_filter :load_preview_class, :except => :index
3
+ def index
4
+ @preview_classes = (RailsEmailPreview.preview_classes || [])
5
+ end
6
+
7
+ def show
8
+ @mail = @preview_class.new.send(params[:mail_action])
9
+ end
10
+
11
+ def show_raw
12
+ @mail = @preview_class.new.send(params[:mail_action])
13
+ body_part = @mail
14
+ if @mail.multipart?
15
+ content_type = Rack::Mime.mime_type(params[:format])
16
+ body_part = @mail.parts.find { |part| part.content_type.match(content_type) } || @mail.parts.first
17
+ end
18
+ body = body_part.body
19
+ if body_part.content_type =~ /plain/
20
+ body = "<pre id='message_body'>#{body}</body>"
21
+ end
22
+ render :text => body, :layout => false
23
+ end
24
+
25
+ private
26
+ def load_preview_class
27
+ @preview_class = (RailsEmailPreview.preview_classes || []).find {|pc| pc.name.underscore == params[:mail_class]}
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ !!! HTML
2
+ %html
3
+ %head
4
+ %title Email Preview
5
+ = stylesheet_link_tag 'rails_email_preview/application'
6
+ = yield(:head)
7
+ %body
8
+ #content
9
+ = yield
@@ -0,0 +1,9 @@
1
+ %h1 Available Mailers
2
+ %ul
3
+ - @preview_classes.each do |m|
4
+ %li
5
+ %h2= m.name
6
+ %ul
7
+ - m.instance_methods(false).map(&:to_s).each do |method|
8
+ %li
9
+ %a{:href => rails_email_preview.email_url(:mail_class => m.name.underscore, :mail_action => method)}= method
@@ -0,0 +1,33 @@
1
+ %a#back-to-all{:href => rails_email_preview.root_url} &laquo; Back to list
2
+ #message_headers
3
+ %dl
4
+ %dt From:
5
+ %dd= @mail.from
6
+
7
+ %dt Subject:
8
+ %dd
9
+ %strong= @mail.subject
10
+
11
+ %dt Date:
12
+ %dd= Time.now.strftime("%b %e, %Y %I:%M:%S %p %Z")
13
+
14
+ %dt To:
15
+ %dd= @mail.to
16
+
17
+ - if @mail.multipart?
18
+ %p.alternate
19
+ - if body_part.content_type && body_part.content_type.match(/text\/html/)
20
+ %a{:href => rails_email_preview.email_url(params.merge(:format => 'txt'))}} View plain text version
21
+ - else
22
+ %a{:href => rails_email_preview.email_url(params.merge(:format => 'html'))}} View HTML version
23
+
24
+
25
+ %iframe#src-iframe{:src => rails_email_preview.raw_email_url(params),
26
+ :width => "100%", :height => "800", :onload => 'emailLoaded()', :style => "display:none"}
27
+ %pre#loading Loading...
28
+
29
+ :javascript
30
+ window.emailLoaded = function () {
31
+ document.getElementById('src-iframe').style.display = 'block';
32
+ document.getElementById('loading').style.display = 'none';
33
+ };
data/config/routes.rb ADDED
@@ -0,0 +1,13 @@
1
+ RailsEmailPreview::Engine.routes.draw do
2
+ root :to => 'emails#index'
3
+ match 'raw/:mail_class/:mail_action(.:format)',
4
+ :as => :raw_email,
5
+ :to => 'emails#show_raw',
6
+ :defaults => {:format => 'html'},
7
+ :mail_class => %r([\w/]+)
8
+ match ':mail_class/:mail_action(.:format)',
9
+ :as => :email,
10
+ :to => 'emails#show',
11
+ :defaults => {:format => 'html'},
12
+ :mail_class => %r([\w/]+)
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails_email_preview/engine'
2
+
3
+ module RailsEmailPreview
4
+ mattr_accessor :preview_classes
5
+
6
+ def self.setup
7
+ yield self
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module ::RailsEmailPreview
2
+ class Engine < Rails::Engine
3
+ isolate_namespace RailsEmailPreview
4
+
5
+ class << self
6
+ attr_accessor :root
7
+ def root
8
+ @root ||= Pathname.new(File.expand_path('../../', __FILE__))
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module RailsEmailPreview
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_email_preview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gleb Mazovetskiy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &22389360 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *22389360
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &22388840 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.2'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *22388840
36
+ - !ruby/object:Gem::Dependency
37
+ name: haml
38
+ requirement: &22388440 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *22388440
47
+ - !ruby/object:Gem::Dependency
48
+ name: sass
49
+ requirement: &22387980 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *22387980
58
+ description: Insert RailsEmailPreview description.
59
+ email: glex.spb@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - app/controllers/rails_email_preview/application_controller.rb
65
+ - app/controllers/rails_email_preview/emails_controller.rb
66
+ - app/assets/stylesheets/rails_email_preview/application.css.sass
67
+ - app/views/rails_email_preview/emails/index.html.haml
68
+ - app/views/rails_email_preview/emails/show.html.haml
69
+ - app/views/layouts/rails_email_preview/application.html.haml
70
+ - lib/rails_email_preview/engine.rb
71
+ - lib/rails_email_preview/version.rb
72
+ - lib/rails_email_preview.rb
73
+ - config/routes.rb
74
+ - MIT-LICENSE
75
+ - Rakefile
76
+ - Gemfile
77
+ - README.md
78
+ homepage:
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.11
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Visual Email Preview for Rails >= 3, implemented as a Rails Engine. v0.0.1
102
+ test_files: []