letter_opener_web 1.0.0.rc3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +30 -2
- data/app/models/letter_opener_web/letter.rb +10 -0
- data/app/views/letter_opener_web/letters/index.html.erb +3 -3
- data/{test-app → demo}/.gitignore +0 -0
- data/{test-app → demo}/Gemfile +5 -0
- data/demo/application_controller.rb +25 -0
- data/{test-app → demo}/boot.rb +5 -2
- data/{test-app → demo}/config.ru +0 -0
- data/demo/index.html.erb +72 -0
- data/demo/initializers.rb +9 -0
- data/demo/new_message.html.erb +21 -0
- data/lib/letter_opener_web/version.rb +1 -1
- data/spec/models/letter_opener_web/letter_spec.rb +14 -0
- metadata +17 -10
data/README.md
CHANGED
@@ -21,8 +21,8 @@ Your::Application.routes.draw do
|
|
21
21
|
end
|
22
22
|
```
|
23
23
|
|
24
|
-
If you are
|
25
|
-
`letter_opener`'s `launchy` calls and avoid messages like these:
|
24
|
+
If you are running the app from a [Vagrant](http://vagrantup.com) box, you
|
25
|
+
might want to skip `letter_opener`'s `launchy` calls and avoid messages like these:
|
26
26
|
|
27
27
|
```terminal
|
28
28
|
12:33:42 web.1 | Failure in opening /vagrant/tmp/letter_opener/1358825621_ba83a22/rich.html
|
@@ -42,6 +42,34 @@ can set `:letter_opener_web` as your delivery method on your
|
|
42
42
|
config.action_mailer.delivery_method = ENV['USER'] == 'vagrant' ? :letter_opener_web : :letter_opener
|
43
43
|
```
|
44
44
|
|
45
|
+
## Usage with [rails-footnotes](https://github.com/josevalim/rails-footnotes)
|
46
|
+
|
47
|
+
To prevent `rails-footnotes` from outputing debug information to your mails add
|
48
|
+
the following to your `config/initializers/footnotes.rb`:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
Footnotes.setup do |config|
|
52
|
+
config.before do |controller, filter|
|
53
|
+
controller.class.name =~ /LetterOpenerWeb/ ?
|
54
|
+
filter.notes.clear :
|
55
|
+
filter.notes
|
56
|
+
end
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
## Try it out
|
61
|
+
|
62
|
+
There is a demo app built with [tiny-rails](https://github.com/fgrehm/tiny-rails)
|
63
|
+
available for you to check out how the interface looks like. If you want to give
|
64
|
+
a shot at it:
|
65
|
+
|
66
|
+
```terminal
|
67
|
+
git clone https://github.com/fgrehm/letter_opener_web
|
68
|
+
cd letter_opener_web/demo
|
69
|
+
bundle
|
70
|
+
unicorn
|
71
|
+
```
|
72
|
+
|
45
73
|
## Acknowledgements
|
46
74
|
|
47
75
|
Special thanks to [@alexrothenberg](https://github.com/alexrothenberg) for some
|
@@ -38,12 +38,22 @@ module LetterOpenerWeb
|
|
38
38
|
id
|
39
39
|
end
|
40
40
|
|
41
|
+
def default_style
|
42
|
+
style_exists?('rich') ?
|
43
|
+
'rich' :
|
44
|
+
'plain'
|
45
|
+
end
|
46
|
+
|
41
47
|
private
|
42
48
|
|
43
49
|
def read_file(style)
|
44
50
|
File.read("#{letters_location}/#{id}/#{style}.html")
|
45
51
|
end
|
46
52
|
|
53
|
+
def style_exists?(style)
|
54
|
+
File.exists?("#{letters_location}/#{id}/#{style}.html")
|
55
|
+
end
|
56
|
+
|
47
57
|
def adjust_link_targets(contents)
|
48
58
|
# We cannot feed the whole file to an XML parser as some mails are
|
49
59
|
# "complete" (as in they have the whole <html> structure) and letter_opener
|
@@ -23,7 +23,7 @@
|
|
23
23
|
<% if first_letter = @letters.shift %>
|
24
24
|
<tr class="active">
|
25
25
|
<td>
|
26
|
-
<%= link_to(first_letter.id, letter_path(first_letter, style:
|
26
|
+
<%= link_to(first_letter.id, letter_path(first_letter, style: first_letter.default_style), target: 'mail') %>
|
27
27
|
</td>
|
28
28
|
<td><%= first_letter.sent_at %></td>
|
29
29
|
</tr>
|
@@ -31,7 +31,7 @@
|
|
31
31
|
<% @letters.each do |letter| %>
|
32
32
|
<tr>
|
33
33
|
<td>
|
34
|
-
<%= link_to(letter.id, letter_path(letter, style:
|
34
|
+
<%= link_to(letter.id, letter_path(letter, style: letter.default_style), target: 'mail') %>
|
35
35
|
</td>
|
36
36
|
<td><%= letter.sent_at %></td>
|
37
37
|
</tr>
|
@@ -40,5 +40,5 @@
|
|
40
40
|
</table>
|
41
41
|
</div>
|
42
42
|
<div class="col right">
|
43
|
-
<iframe name="mail" id="mail" src="<%= first_letter.present? ? letter_path(first_letter, style:
|
43
|
+
<iframe name="mail" id="mail" src="<%= first_letter.present? ? letter_path(first_letter, style: first_letter.default_style) : 'about:blank' %>"></iframe>
|
44
44
|
</div>
|
File without changes
|
data/{test-app → demo}/Gemfile
RENAMED
@@ -0,0 +1,25 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
append_view_path '.'
|
3
|
+
|
4
|
+
def index
|
5
|
+
render :template => 'index'
|
6
|
+
end
|
7
|
+
|
8
|
+
def send_mail
|
9
|
+
ContactMailer.new_message(params[:email], params[:message]).deliver
|
10
|
+
redirect_to '/', :notice => 'Email sent successfully, please check letter_opener_web inbox.'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ContactMailer < ActionMailer::Base
|
15
|
+
append_view_path File.dirname(__FILE__)
|
16
|
+
|
17
|
+
default :to => 'admin@letter_opener_web.com',
|
18
|
+
:from => 'no-reply@letter_opener_web.com',
|
19
|
+
:template_path => '.'
|
20
|
+
|
21
|
+
def new_message(from, message)
|
22
|
+
@from, @message = from, message
|
23
|
+
mail(:subject => 'Testing letter_opener_web', :template_name => 'new_message')
|
24
|
+
end
|
25
|
+
end
|
data/{test-app → demo}/boot.rb
RENAMED
@@ -20,7 +20,6 @@ class TinyRailsApp < Rails::Application
|
|
20
20
|
config.autoload_paths << config.root
|
21
21
|
|
22
22
|
config.middleware.delete "Rack::Lock"
|
23
|
-
config.middleware.delete "ActionDispatch::Flash"
|
24
23
|
config.middleware.delete "ActionDispatch::BestStandardsSupport"
|
25
24
|
config.middleware.use Rails::Rack::LogTailer, "log/#{Rails.env}.log"
|
26
25
|
|
@@ -30,6 +29,8 @@ class TinyRailsApp < Rails::Application
|
|
30
29
|
# Enable asset pipeline
|
31
30
|
config.assets.enabled = true
|
32
31
|
config.assets.debug = true
|
32
|
+
|
33
|
+
config.action_mailer.delivery_method = :letter_opener_web
|
33
34
|
end
|
34
35
|
|
35
36
|
require 'initializers' if File.exists?('initializers.rb')
|
@@ -37,6 +38,8 @@ require 'initializers' if File.exists?('initializers.rb')
|
|
37
38
|
TinyRailsApp.initialize!
|
38
39
|
|
39
40
|
TinyRailsApp.routes.draw do
|
40
|
-
|
41
|
+
get "/" => 'application#index'
|
42
|
+
post "/" => 'application#send_mail'
|
43
|
+
mount LetterOpenerWeb::Engine, at: "/letter_opener"
|
41
44
|
match "/favicon.ico", :to => proc {|env| [200, {}, [""]] }
|
42
45
|
end
|
data/{test-app → demo}/config.ru
RENAMED
File without changes
|
data/demo/index.html.erb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>LetterOpenerWeb Test APP</title>
|
5
|
+
<%= stylesheet_link_tag "bootstrap.min" %>
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
padding-top: 20px;
|
9
|
+
}
|
10
|
+
|
11
|
+
.alert {
|
12
|
+
margin-top: 20px;
|
13
|
+
}
|
14
|
+
|
15
|
+
h1, .footer {
|
16
|
+
text-align: center;
|
17
|
+
}
|
18
|
+
|
19
|
+
.icon-white {
|
20
|
+
background-image: url(<%=asset_path "glyphicons-halflings-white.png"%>);
|
21
|
+
}
|
22
|
+
</style>
|
23
|
+
</head>
|
24
|
+
<body>
|
25
|
+
<div class="container">
|
26
|
+
<h1>LetterOpenerWeb Test App</h1>
|
27
|
+
|
28
|
+
<div class="row">
|
29
|
+
<div class="span6 offset3">
|
30
|
+
|
31
|
+
<div class="well">
|
32
|
+
<form method="post" action="/">
|
33
|
+
<legend>Contact form</legend>
|
34
|
+
<div class="control-group">
|
35
|
+
<label class="control-label" for="email">Email</label>
|
36
|
+
<div class="controls">
|
37
|
+
<input type="text" class="input-block-level" name="email">
|
38
|
+
</div>
|
39
|
+
</div>
|
40
|
+
<div class="control-group">
|
41
|
+
<label class="control-label" for="message">Message</label>
|
42
|
+
<div class="controls">
|
43
|
+
<textarea class="input-block-level" name="message" rows="6"></textarea>
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
<div class="control-group">
|
47
|
+
<div class="controls">
|
48
|
+
<button type="submit" class="btn btn-primary pull-right">
|
49
|
+
<i class="icon-envelope icon-white"></i>
|
50
|
+
Send mail
|
51
|
+
</button>
|
52
|
+
<div class="clearfix"></div>
|
53
|
+
</div>
|
54
|
+
</div>
|
55
|
+
</form>
|
56
|
+
|
57
|
+
<p class="footer">
|
58
|
+
<a href="/letter_opener" target="_blank">Click here</a>
|
59
|
+
to see sent mails
|
60
|
+
</p>
|
61
|
+
</div>
|
62
|
+
|
63
|
+
<% if flash.key?(:notice) %>
|
64
|
+
<div class="alert alert-success">
|
65
|
+
<%= flash[:notice] %>
|
66
|
+
</div>
|
67
|
+
<% end %>
|
68
|
+
</div>
|
69
|
+
</div>
|
70
|
+
</div>
|
71
|
+
</body>
|
72
|
+
</html>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<style type="text/css">
|
2
|
+
label { font-weight: bold; }
|
3
|
+
.from { color: #888; font-style: italic }
|
4
|
+
.message { padding-left: 10px; }
|
5
|
+
.message p:first-child { margin-top: 0; }
|
6
|
+
</style>
|
7
|
+
|
8
|
+
<h1>New message!</h1>
|
9
|
+
|
10
|
+
<p>
|
11
|
+
<label>From:</label>
|
12
|
+
<span class="from"><%= @from %></span>
|
13
|
+
</p>
|
14
|
+
|
15
|
+
<p>
|
16
|
+
<label>Message:</label>
|
17
|
+
</p>
|
18
|
+
|
19
|
+
<div class="message">
|
20
|
+
<%= simple_format @message %>
|
21
|
+
</div>
|
@@ -50,6 +50,20 @@ MAIL
|
|
50
50
|
it { should =~ /Plain text for 2222_2222/ }
|
51
51
|
end
|
52
52
|
|
53
|
+
describe 'default style' do
|
54
|
+
let(:id) { '2222_2222' }
|
55
|
+
subject { described_class.new(id: id) }
|
56
|
+
|
57
|
+
it 'returns rich if rich text version is present' do
|
58
|
+
subject.default_style.should == 'rich'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns plain if rich text version is not present' do
|
62
|
+
File.stub(:exists? => false)
|
63
|
+
subject.default_style.should == 'plain'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
53
67
|
describe '.search' do
|
54
68
|
let(:search_results) { described_class.search }
|
55
69
|
let(:first_letter) { search_results.first }
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: letter_opener_web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Fabio Rehm
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
prerelease: false
|
@@ -114,6 +114,14 @@ files:
|
|
114
114
|
- app/views/layouts/letter_opener_web/application.html.erb
|
115
115
|
- app/views/letter_opener_web/letters/index.html.erb
|
116
116
|
- config/routes.rb
|
117
|
+
- demo/.gitignore
|
118
|
+
- demo/Gemfile
|
119
|
+
- demo/application_controller.rb
|
120
|
+
- demo/boot.rb
|
121
|
+
- demo/config.ru
|
122
|
+
- demo/index.html.erb
|
123
|
+
- demo/initializers.rb
|
124
|
+
- demo/new_message.html.erb
|
117
125
|
- letter_opener_web.gemspec
|
118
126
|
- lib/letter_opener_web.rb
|
119
127
|
- lib/letter_opener_web/delivery_method.rb
|
@@ -129,10 +137,6 @@ files:
|
|
129
137
|
- spec/internal/public/favicon.ico
|
130
138
|
- spec/models/letter_opener_web/letter_spec.rb
|
131
139
|
- spec/spec_helper.rb
|
132
|
-
- test-app/.gitignore
|
133
|
-
- test-app/Gemfile
|
134
|
-
- test-app/boot.rb
|
135
|
-
- test-app/config.ru
|
136
140
|
- vendor/assets/images/glyphicons-halflings-white.png
|
137
141
|
- vendor/assets/images/glyphicons-halflings.png
|
138
142
|
- vendor/assets/javascripts/bootstrap.min.js
|
@@ -151,13 +155,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
155
|
version: '0'
|
152
156
|
segments:
|
153
157
|
- 0
|
154
|
-
hash:
|
158
|
+
hash: 497055164717147357
|
155
159
|
none: false
|
156
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
161
|
requirements:
|
158
|
-
- - ! '
|
162
|
+
- - ! '>='
|
159
163
|
- !ruby/object:Gem::Version
|
160
|
-
version:
|
164
|
+
version: '0'
|
165
|
+
segments:
|
166
|
+
- 0
|
167
|
+
hash: 497055164717147357
|
161
168
|
none: false
|
162
169
|
requirements: []
|
163
170
|
rubyforge_project:
|