volt-mailer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/README.md +66 -0
- data/Rakefile +1 -0
- data/app/mailer/config/dependencies.rb +1 -0
- data/app/mailer/tasks/mailer_task.rb +44 -0
- data/lib/volt/mailer/version.rb +5 -0
- data/lib/volt/mailer.rb +7 -0
- data/volt-mailer.gemspec +24 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2416a1f3327d0efb536075d06882a43d9cbb3a4a
|
4
|
+
data.tar.gz: b5c410054e1151743f94a3f57e1a56c48c1c9e8b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c1e264470d919cc5ead6741e393740b2d1e804e7a1eb21138f498d5f49309f87fa9d9bdd81bcc44df4722261c150653034624c17bcc77ac004a2addb18ce7048
|
7
|
+
data.tar.gz: 1320fd84e0ad2cc0e470e694bed7c1c1f7669c3848dc93ebd48d700f3944578482046b221222c55bca084e1ea50917a2f4d0da0d89bd1700201a3292e7ca24de
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Volt::Mailer
|
2
|
+
|
3
|
+
An easy way to send e-mail from your Volt app.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'volt-mailer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
## Templates
|
18
|
+
|
19
|
+
When using volt-mailer, you create .email templates and deliver them based on their path. (Typically at app/main/views/mailers/*.email)
|
20
|
+
|
21
|
+
Email templates have three sections in a single file:
|
22
|
+
|
23
|
+
```html
|
24
|
+
<:Subject>
|
25
|
+
Welcome
|
26
|
+
|
27
|
+
<:Html>
|
28
|
+
<h1>Welcome {{ name }}</h1>
|
29
|
+
|
30
|
+
<p>...</p>
|
31
|
+
|
32
|
+
<:Text>
|
33
|
+
Welcome
|
34
|
+
|
35
|
+
...
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
## Delivery
|
40
|
+
|
41
|
+
On the client or the server you can send an e-mail with:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
Mailer.deliver('path/to/views', {to: 'someone@address.com'}).then do
|
45
|
+
# email sent
|
46
|
+
end.fail do |errors|
|
47
|
+
# failed to send, handle errors
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
Mailer.deliver takes two arguments, the path to your mailer and a hash of options. In a new volt project, there will be an "app/main/views/mailer" folder. Any view with .email (or .html) can be used. Normally you would use a .email view. Views with the .email extension will not be loaded on the client.
|
52
|
+
|
53
|
+
If you skip the :Html section, the :Text section will be used for the html e-mail.
|
54
|
+
|
55
|
+
The ```Mailer``` class is a Volt::Task, so the deliver method returns a promise. Be sure to handle the fail.
|
56
|
+
|
57
|
+
The second argument is a hash of options. volt-mailer uses the [pony gem](https://github.com/benprew/pony) under the hood to deliver the mail. Any supported pony options will be passed to pony during the sending. All options passed in will be exposed as methods inside of the email template. If a matching controller is provided, the options will be set as the controllers model.
|
58
|
+
|
59
|
+
## Attachments
|
60
|
+
|
61
|
+
Because Volt uses the [pony gem](https://github.com/benprew/pony), you can pass any pony options as the second argument to deliver to add attachments, reply_to, message_id's, etc..
|
62
|
+
|
63
|
+
|
64
|
+
## Mailer Config
|
65
|
+
|
66
|
+
Commonly when sending e-mails, you'll need to globally configure things like the :via and :via_options, and the :from address. This can be configured in Volt.configure block in your app. Volt provides default setup options out of the box.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
# Component dependencies
|
@@ -0,0 +1,44 @@
|
|
1
|
+
unless RUBY_PLATFORM == 'opal'
|
2
|
+
require 'pony'
|
3
|
+
require 'volt/page/path_string_renderer'
|
4
|
+
end
|
5
|
+
|
6
|
+
class Mailer < Volt::Task
|
7
|
+
def deliver(view_path, attrs)
|
8
|
+
raise ":to must be supplied when delivering e-mail" unless attrs[:to]
|
9
|
+
|
10
|
+
subject = Volt::PathStringRenderer.new("#{view_path}/subject", attrs).html
|
11
|
+
|
12
|
+
text = begin
|
13
|
+
Volt::PathStringRenderer.new("#{view_path}/text", attrs).html
|
14
|
+
rescue ViewLookupException => e
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
|
18
|
+
html = begin
|
19
|
+
Volt::PathStringRenderer.new("#{view_path}/html", attrs).html
|
20
|
+
rescue ViewLookupException => e
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
if !text && !body
|
25
|
+
raise "No text or html version of the e-mail supplied in #{view_path}"
|
26
|
+
end
|
27
|
+
|
28
|
+
# If no html version is supplied, use the text version.
|
29
|
+
html ||= "<pre>#{text}</pre>"
|
30
|
+
|
31
|
+
attrs[:subject] = subject
|
32
|
+
attrs[:html_body] = html
|
33
|
+
attrs[:body] = text
|
34
|
+
|
35
|
+
# Merge attrs into a copy of the mailer options
|
36
|
+
attrs = Volt.config.mailer.dup.merge(attrs) if Volt.config.mailer
|
37
|
+
|
38
|
+
allowed_opts = Pony.permissable_options
|
39
|
+
|
40
|
+
pony_options = attrs.select {|k,v| allowed_opts.include?(k.to_sym) }
|
41
|
+
# Send the e-mail
|
42
|
+
Pony.mail(pony_options)
|
43
|
+
end
|
44
|
+
end
|
data/lib/volt/mailer.rb
ADDED
data/volt-mailer.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'volt/mailer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "volt-mailer"
|
8
|
+
spec.version = Volt::Mailer::VERSION
|
9
|
+
spec.authors = ["Ryan Stout"]
|
10
|
+
spec.email = ['ryan@agileproductions.com']
|
11
|
+
spec.summary = %q{A simple way to send e-mail from within a Volt app.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "pony", "~> 1.11"
|
21
|
+
|
22
|
+
spec.add_development_dependency "volt", "~> 0.9.0"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: volt-mailer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Stout
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pony
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: volt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- ryan@agileproductions.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- app/mailer/config/dependencies.rb
|
67
|
+
- app/mailer/tasks/mailer_task.rb
|
68
|
+
- lib/volt/mailer.rb
|
69
|
+
- lib/volt/mailer/version.rb
|
70
|
+
- volt-mailer.gemspec
|
71
|
+
homepage: ''
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: A simple way to send e-mail from within a Volt app.
|
95
|
+
test_files: []
|