better_opener 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ BetterOpener
2
+ =============
3
+
4
+ Preview mails and other notifications in your browser instead of actually
5
+ sending them out. Inspired by and similar in terms of functionality to the
6
+ [LetterOpener][1] and the [MailView][2] gem BetterOpener tries to be *better*
7
+ by:
8
+
9
+ - providing support for outgoing notifications in general (email, sms so far)
10
+ - supporting pre- and on-demand rendering
11
+ - allowing remote access to notifications (helpful on staging servers and remote development machines)
12
+ - displaying desktop notifications (with the accompanying chrome plugin)
13
+
14
+
15
+ Setup
16
+ -----
17
+
18
+ Add the gem to your development environment and run the `bundle install` command to install it.
19
+
20
+ gem "better_opener", :group => :development
21
+
22
+ Then in Rails3 mount the bundled Sinatra app inline in your `routes.rb`:
23
+
24
+ if Rails.env == "development"
25
+ mount BetterOpener::Server => "/notifications"
26
+ end
27
+
28
+ To prevent messages from actually being sent you need to set up email and/or sms interception.
29
+
30
+ ### Email
31
+
32
+ Set the delivery method in `config/environments/development.rb`
33
+
34
+ config.action_mailer.delivery_method = :better_opener
35
+
36
+ The design of the email interface is taken from the [mail_view][2] plugin.
37
+
38
+
39
+ ### SMS
40
+
41
+ SMS message support is provided for the [sms_gateway][3] gem.
42
+ Edit your `sms_gateway.yml` file:
43
+
44
+ development:
45
+ adapter: better_opener
46
+ from: your_app
47
+
48
+ SMS interface:
49
+
50
+ ![SMS as displayed by the sinatra app](https://github.com/learnjin/better-opener/raw/master/sms.jpg)
51
+
52
+
53
+ On-request Rendering
54
+ -------------------
55
+
56
+ The messages that are being sent with one of the above delivery methods are
57
+ static (pre-rendered at time of delivery). To preview your changes without
58
+ going through all the steps to redeliver the message use the
59
+ `add_delayed_notification` method like that:
60
+
61
+ class Emailer < ActionMailer::Base
62
+
63
+ # ....
64
+
65
+ def self.deliver_later(method, *params)
66
+ if Rails.env == "development"
67
+ BetterOpener.add_delayed_notification("email", Emailer, method, params)
68
+ else
69
+ Resque.enqueue(EmailJob, method, *params)
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+
76
+ Chrome Plugin
77
+ -------------
78
+
79
+ To get actual desktop notifications, you will want to install the accompanying
80
+ [chrome-plugin][4]. Point it to the (full) notification path that you mounted
81
+ this gem on.
82
+
83
+ ![Chrome Notifications](https://github.com/learnjin/better-opener/raw/master/notifications.png)
84
+
85
+ [1]: https://github.com/ryanb/letter_opener
86
+ [2]: https://github.com/37signals/mail_view
87
+ [3]: https://github.com/learnjin/sms-gateway
88
+ [4]: https://github.com/learnjin/better-opener-chrome
89
+
90
+
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = BetterOpener::VERSION
8
8
  s.authors = ["Kai Rubarth"]
9
9
  s.email = ["kai@doxter.de"]
10
- s.homepage = "http://github.com/learnjin/better_opener"
10
+ s.homepage = "https://github.com/learnjin/better-opener"
11
11
  s.summary = %q{A better way of Previewing mail in your browser instead of sending it.}
12
12
  s.description = %q{When mails or messages are sent from your application, Better Opener lets you preview the rendered messages in your browser instead of delivering them.}
13
13
 
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency "dm-sqlite-adapter"
26
26
  s.add_dependency "tilt"
27
27
  s.add_dependency "haml"
28
-
28
+ s.add_dependency "multi_json"
29
29
  end
30
30
 
31
31
 
data/lib/better_opener.rb CHANGED
@@ -10,12 +10,21 @@ module BetterOpener
10
10
  class Notification
11
11
  include DataMapper::Resource
12
12
  property :id, Serial
13
- property :subject, String
14
- property :body, Text
15
13
  property :created_at, DateTime
16
- property :category, String
14
+ property :subject, String, :length => 255
15
+ property :summary, String
16
+
17
+ property :category, String # influences rendering
18
+
19
+ property :klass, String
20
+ property :method, String
21
+ property :params, String
22
+
23
+ property :rendered, Boolean, :default => false
24
+ property :body, Text
17
25
  end
18
26
 
27
+
19
28
  extend self
20
29
 
21
30
  def db=(server)
@@ -40,7 +49,23 @@ module BetterOpener
40
49
 
41
50
  def add_notification(category, subject, body)
42
51
  db
43
- n = BetterOpener::Notification.new :category => category, :subject => subject, :body => body, :created_at => Time.now
52
+ n = BetterOpener::Notification.new(:category => category,
53
+ :subject => subject,
54
+ :body => body,
55
+ :created_at => Time.now,
56
+ :rendered => true)
57
+ n.save
58
+ end
59
+
60
+ def add_delayed_notification(category, klass, method, params)
61
+ db
62
+
63
+ n = BetterOpener::Notification.new(:category => category,
64
+ :subject => method,
65
+ :klass => klass.name,
66
+ :method => method,
67
+ :params => BetterOpener.encode(params),
68
+ :created_at => Time.now)
44
69
  n.save
45
70
  end
46
71
 
@@ -77,6 +102,27 @@ module BetterOpener
77
102
  end
78
103
 
79
104
 
105
+ def encode(params)
106
+ MultiJson.encode(params)
107
+ end
108
+
109
+ def decode(params)
110
+ MultiJson.decode(params)
111
+ end
112
+
113
+ def render_notification(n, format = nil)
114
+ return n.body if n.rendered
115
+ klass = Kernel.const_get(n.klass.classify)
116
+ if n.category == "email"
117
+ m = klass.send(n.method, *BetterOpener.decode(n.params))
118
+ BetterOpener.render_email(n.id, m, format)
119
+ elsif n.category == "sms"
120
+ m = klass.send(n.method, *BetterOpener.decode(n.params))
121
+ BetterOpener.render_sms(n.id, m)
122
+ end
123
+ end
124
+
125
+
80
126
  end
81
127
 
82
128
  require 'better_opener/delivery_method'
@@ -79,6 +79,7 @@
79
79
  <% end %>
80
80
  </p>
81
81
  <% end %>
82
+
82
83
  </div>
83
84
 
84
85
  <% if body_part.content_type && body_part.content_type.match(/text\/html/) %>
@@ -44,9 +44,13 @@ module BetterOpener
44
44
  redirect u('/')
45
45
  end
46
46
 
47
- get "/:id" do
48
- @message = BetterOpener.get_notification(params[:id])
49
- @message.body
47
+ get %r{/(\d+)(.*)} do
48
+ #@message = BetterOpener.get_notification(params[:id])
49
+ #@message.body
50
+ id = params[:captures].first
51
+ format = params[:captures].second
52
+ @message = BetterOpener.get_notification(id)
53
+ BetterOpener.render_notification(@message, format)
50
54
  end
51
55
 
52
56
  get "/feed/atom", :provides => [:atom] do
@@ -5,7 +5,7 @@
5
5
  %ul
6
6
  - for m in @messages
7
7
  %li
8
- = m.category + ": "
8
+ = (m.rendered ? "pre. ": "enq. ") + m.category + ": "
9
9
  %em
10
10
  %a{:href => u("/#{m.id}") }= m.subject
11
11
 
@@ -86,6 +86,9 @@ div.outcome {
86
86
  <dt>Date:</dt>
87
87
  <dd><%= Time.now.strftime("%b %e, %Y %I:%M:%S %p %Z") %></dd>
88
88
 
89
+ <dt>Length:</dt>
90
+ <dd><%= sms.text.length %></dd>
91
+
89
92
  </dl>
90
93
 
91
94
  </div>
@@ -1,3 +1,3 @@
1
1
  module BetterOpener
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
data/notifications.png ADDED
Binary file
data/sms.jpg ADDED
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_opener
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kai Rubarth
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-02 00:00:00 Z
18
+ date: 2012-03-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: sinatra-contrib
@@ -88,6 +88,20 @@ dependencies:
88
88
  version: "0"
89
89
  type: :runtime
90
90
  version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: multi_json
93
+ prerelease: false
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :runtime
104
+ version_requirements: *id006
91
105
  description: When mails or messages are sent from your application, Better Opener lets you preview the rendered messages in your browser instead of delivering them.
92
106
  email:
93
107
  - kai@doxter.de
@@ -100,7 +114,7 @@ extra_rdoc_files: []
100
114
  files:
101
115
  - .gitignore
102
116
  - Gemfile
103
- - README.rdoc
117
+ - README.md
104
118
  - Rakefile
105
119
  - better_opener.gemspec
106
120
  - config.ru
@@ -111,12 +125,13 @@ files:
111
125
  - lib/better_opener/server.rb
112
126
  - lib/better_opener/server/views/atom.haml
113
127
  - lib/better_opener/server/views/index.haml
114
- - lib/better_opener/server/views/show.haml
115
128
  - lib/better_opener/sms.html.erb
116
129
  - lib/better_opener/sms_gateway_adapter.rb
117
130
  - lib/better_opener/version.rb
118
131
  - lib/test.ru
119
- homepage: http://github.com/learnjin/better_opener
132
+ - notifications.png
133
+ - sms.jpg
134
+ homepage: https://github.com/learnjin/better-opener
120
135
  licenses: []
121
136
 
122
137
  post_install_message:
data/README.rdoc DELETED
@@ -1,34 +0,0 @@
1
- = Better Opener
2
-
3
- Preview mails and other notifications (sms for instance) in your browser
4
- instead of actually sending them out. Inspired and almost similar to the
5
- Letter Opener by Ryan Bates Better Opener this gem tries to be *better* by being
6
- more universal and displaying desktop notifications (with the chrome plugin).
7
-
8
- == Setup
9
-
10
- Add the gem to your development environment and run the <tt>bundle install</tt> command to install it.
11
-
12
- gem "better_opener", :group => :development
13
-
14
- Set the delivery method in <tt>config/environments/development.rb</tt>
15
-
16
- config.action_mailer.delivery_method = :letter_opener
17
-
18
- Finally install the bundled Sinatra app as a subdirectory of your app by editing your <tt>config.ru</tt>:
19
-
20
- map "/notification" do
21
- run BetterOpener::Server
22
- end
23
-
24
-
25
-
26
- == Chrome Plugin
27
-
28
- To take full advantage and get actual notifications, you will want to install
29
- the accompanying chrome plugin. Just point it to the notification address you
30
- set up above.
31
-
32
-
33
-
34
-
@@ -1,4 +0,0 @@
1
- %h1= @message.subject
2
- %h2= @message.category
3
- %p= @message.body
4
-