emailvision4rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +14 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +198 -0
- data/Rakefile +29 -0
- data/lib/emailvision4rails.rb +28 -0
- data/lib/emailvision4rails/configuration.rb +9 -0
- data/lib/emailvision4rails/emv_handler.rb +18 -0
- data/lib/emailvision4rails/models/base.rb +57 -0
- data/lib/emailvision4rails/models/campaign.rb +55 -0
- data/lib/emailvision4rails/models/message.rb +75 -0
- data/lib/emailvision4rails/newsletter.rb +43 -0
- data/lib/emailvision4rails/newsletters/abstract_newsletter.rb +72 -0
- data/lib/emailvision4rails/premailer.rb +19 -0
- data/lib/emailvision4rails/railtie.rb +23 -0
- data/lib/emailvision4rails/version.rb +3 -0
- data/lib/generators/emailvision4rails/setup_generator.rb +11 -0
- data/lib/generators/emailvision4rails/templates/emailvision.yml +15 -0
- data/lib/generators/newsletter_generator.rb +23 -0
- data/lib/generators/templates/action.html.emv +11 -0
- data/lib/generators/templates/action.text.emv +3 -0
- data/lib/generators/templates/newsletter.rb +15 -0
- metadata +129 -0
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "rails", "3.2.8"
|
4
|
+
gem "capybara", ">= 0.4.0"
|
5
|
+
gem "sqlite3"
|
6
|
+
gem "emailvision", "~> 2.1"
|
7
|
+
gem "premailer", "~> 1.7"
|
8
|
+
gem "hpricot", "~> 0.8"
|
9
|
+
|
10
|
+
gem "pry", :group => :development
|
11
|
+
|
12
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
13
|
+
# gem 'ruby-debug'
|
14
|
+
# gem 'ruby-debug19'
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 Bastien Gysler (www.bastiengysler.com)
|
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.markdown
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
Emailvision ruby on rails library
|
2
|
+
=================================
|
3
|
+
|
4
|
+
Emailvision4rails is a library used to manage messages and campaigns or more simply newsletters from your rails application.
|
5
|
+
|
6
|
+
/!\ Not released yet /!\
|
7
|
+
|
8
|
+
Install
|
9
|
+
-------
|
10
|
+
|
11
|
+
### Without bundler
|
12
|
+
|
13
|
+
```shell
|
14
|
+
$ gem install emailvision4rails
|
15
|
+
```
|
16
|
+
|
17
|
+
### With bundler
|
18
|
+
|
19
|
+
Past this line to your Gemfile
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'emailvision4rails'
|
23
|
+
```
|
24
|
+
|
25
|
+
Setup
|
26
|
+
-----
|
27
|
+
|
28
|
+
```shell
|
29
|
+
$ rails generate emailvision4rails:setup
|
30
|
+
```
|
31
|
+
|
32
|
+
Generator
|
33
|
+
---------
|
34
|
+
|
35
|
+
Emailvision4rails is bundled with a newsletter generator.
|
36
|
+
|
37
|
+
```shell
|
38
|
+
$ rails generate newsletter standard daily weekly
|
39
|
+
create app/newsletters/standard_newsletter.rb
|
40
|
+
create app/views/standard_newsletter/daily.html.emv
|
41
|
+
create app/views/standard_newsletter/daily.text.emv
|
42
|
+
create app/views/standard_newsletter/weekly.html.emv
|
43
|
+
create app/views/standard_newsletter/weekly.text.emv
|
44
|
+
```
|
45
|
+
|
46
|
+
Models
|
47
|
+
------
|
48
|
+
|
49
|
+
Models are ActiveModel compliant
|
50
|
+
|
51
|
+
**Campaign**
|
52
|
+
|
53
|
+
Attributes
|
54
|
+
|
55
|
+
* **name**
|
56
|
+
* **mailinglist_id**
|
57
|
+
* **message_id**
|
58
|
+
* **send_date**
|
59
|
+
* description
|
60
|
+
* emaildedupflg
|
61
|
+
* format
|
62
|
+
* delivery_speed
|
63
|
+
* notification
|
64
|
+
* post_click_tracking
|
65
|
+
* strategy
|
66
|
+
* target
|
67
|
+
* url_end_campaign
|
68
|
+
* url_host
|
69
|
+
* analytics
|
70
|
+
|
71
|
+
*Bold attributes must be present*
|
72
|
+
|
73
|
+
Example
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
campaign = Emailvision4rails::Campaign.new(
|
77
|
+
:name => 'Campaign',
|
78
|
+
:mailinglist_id => 123,
|
79
|
+
:message_id => 123,
|
80
|
+
:send_date => Time.now+30.minutes
|
81
|
+
)
|
82
|
+
|
83
|
+
if campaign.create
|
84
|
+
# Campaign created
|
85
|
+
else
|
86
|
+
campaign.errors
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
**Message**
|
91
|
+
|
92
|
+
Attributes
|
93
|
+
|
94
|
+
* **name**
|
95
|
+
* **subject**
|
96
|
+
* **from**
|
97
|
+
* **from_email**
|
98
|
+
* **body**
|
99
|
+
* **reply_to**
|
100
|
+
* **reply_to_email**
|
101
|
+
* id
|
102
|
+
* create_date
|
103
|
+
* to
|
104
|
+
* description
|
105
|
+
* encoding
|
106
|
+
* hotmail_unsub_url
|
107
|
+
* type
|
108
|
+
* hotmail_unsub_flg
|
109
|
+
* is_bounceback
|
110
|
+
|
111
|
+
*Bold attributes must be present*
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
message = Emailvision4rails::Message.new(
|
115
|
+
message_content,
|
116
|
+
:name => 'My message',
|
117
|
+
:subject => 'Hello',
|
118
|
+
:from => 'Bastien Gysler',
|
119
|
+
:from_email => 'basgys@gmail.com',
|
120
|
+
:reply_to => 'Bastien Gysler',
|
121
|
+
:reply_to_email => 'basgys@gmail.com'
|
122
|
+
)
|
123
|
+
|
124
|
+
if message.create
|
125
|
+
# Message created
|
126
|
+
else
|
127
|
+
message.errors
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
Newsletter (Controller)
|
132
|
+
-----------------------
|
133
|
+
|
134
|
+
Newsletters work like mailers. These are stored in the *newsletters* directory (/app/newsletters)
|
135
|
+
|
136
|
+
**Example**
|
137
|
+
|
138
|
+
```shell
|
139
|
+
$ rails generate newsletter standard
|
140
|
+
```
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
class StandardNewsletter < Emailvision4rails::AbstractNewsletter
|
144
|
+
|
145
|
+
def daily_fr(params = {})
|
146
|
+
newsletter(
|
147
|
+
:message => default_message_params,
|
148
|
+
:campaign => default_campaign_params.merge(:send_date => Time.now+1.day, :mailinglist_id => 123)
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
152
|
+
private
|
153
|
+
|
154
|
+
def default_message_params
|
155
|
+
{
|
156
|
+
:name => 'My message',
|
157
|
+
:subject => 'Hello',
|
158
|
+
:from => 'Bastien Gysler',
|
159
|
+
:from_email => 'basgys@gmail.com',
|
160
|
+
:body => my_body,
|
161
|
+
:reply_to => 'Bastien Gysler',
|
162
|
+
:reply_to_email => 'basgys@gmail.com'
|
163
|
+
}
|
164
|
+
end
|
165
|
+
|
166
|
+
def default_campaign_params
|
167
|
+
{
|
168
|
+
:name => 'Campaign campaign'
|
169
|
+
}
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
```
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
StandardNewsletter.daily_fr.publish
|
177
|
+
```
|
178
|
+
|
179
|
+
Views
|
180
|
+
-----
|
181
|
+
|
182
|
+
Views are stored in app/views and are suffixed by _newsletter.
|
183
|
+
|
184
|
+
Two formats are available which are html and text and both must be present. Otherwise and ActionView::MissingTemplate error will be raised.
|
185
|
+
|
186
|
+
Template engine that should be used is emv, but others work too.
|
187
|
+
|
188
|
+
EMV template engine
|
189
|
+
-------------------
|
190
|
+
|
191
|
+
EMV is an engine built on top of ERB, but it also adds CSS inlining for HTML files.
|
192
|
+
|
193
|
+
It means you can create your views just like others and EMV will do the dirty work to be "email ready".
|
194
|
+
|
195
|
+
Author
|
196
|
+
------
|
197
|
+
|
198
|
+
Bastien Gysler :: [bastiengysler.com](http://www.bastiengysler.com/) :: @basgys
|
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 = 'Emailvision'
|
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,28 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'action_view'
|
3
|
+
require 'premailer'
|
4
|
+
require 'emailvision'
|
5
|
+
|
6
|
+
module Emailvision4rails
|
7
|
+
# Base
|
8
|
+
autoload :EmvHandler, 'emailvision4rails/emv_handler'
|
9
|
+
autoload :Collector, 'emailvision4rails/collector'
|
10
|
+
autoload :Newsletter, 'emailvision4rails/newsletter'
|
11
|
+
autoload :Configuration, 'emailvision4rails/configuration'
|
12
|
+
autoload :Premailer, 'emailvision4rails/premailer'
|
13
|
+
autoload :Version, 'emailvision4rails/version'
|
14
|
+
|
15
|
+
# Models
|
16
|
+
autoload :Base, 'emailvision4rails/models/base'
|
17
|
+
autoload :Message, 'emailvision4rails/models/message'
|
18
|
+
autoload :Campaign, 'emailvision4rails/models/campaign'
|
19
|
+
|
20
|
+
# Newsletters (Controller)
|
21
|
+
autoload :AbstractNewsletter, 'emailvision4rails/newsletters/abstract_newsletter'
|
22
|
+
|
23
|
+
ActionView::Template.register_template_handler :emv, EmvHandler
|
24
|
+
|
25
|
+
if defined?(Rails)
|
26
|
+
require 'emailvision4rails/railtie'
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'action_view/template'
|
2
|
+
|
3
|
+
module Emailvision4rails
|
4
|
+
module EmvHandler
|
5
|
+
def self.erb_handler
|
6
|
+
@@erb_handler ||= ActionView::Template.registered_template_handler(:erb)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.call(template)
|
10
|
+
compiled_source = erb_handler.call(template)
|
11
|
+
if template.formats.include?(:html)
|
12
|
+
"Emailvision4rails::Premailer.new((begin;#{compiled_source};end)).to_inline_css"
|
13
|
+
else
|
14
|
+
compiled_source
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'active_model/conversion'
|
2
|
+
require 'active_model/attribute_methods'
|
3
|
+
require 'active_model/naming'
|
4
|
+
require 'active_model/translation'
|
5
|
+
require 'active_model/validator'
|
6
|
+
require 'active_model/validations'
|
7
|
+
require 'active_model/callbacks'
|
8
|
+
|
9
|
+
class Emailvision4rails::Base
|
10
|
+
include ActiveModel::Conversion
|
11
|
+
include ActiveModel::AttributeMethods
|
12
|
+
include ActiveModel::Validations
|
13
|
+
|
14
|
+
extend ActiveModel::Callbacks
|
15
|
+
extend ActiveModel::Naming
|
16
|
+
|
17
|
+
class_attribute :_attributes
|
18
|
+
self._attributes = []
|
19
|
+
|
20
|
+
attribute_method_suffix '?'
|
21
|
+
|
22
|
+
define_model_callbacks :create, :update
|
23
|
+
|
24
|
+
def self.attributes(*names)
|
25
|
+
attr_accessor *names
|
26
|
+
define_attribute_methods names
|
27
|
+
|
28
|
+
self._attributes += names
|
29
|
+
end
|
30
|
+
|
31
|
+
def attributes
|
32
|
+
self._attributes.inject({}) do |hash, attr|
|
33
|
+
hash[attr.to_s] = send(attr)
|
34
|
+
hash
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def persisted?
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_emv
|
43
|
+
attributes.reject {|k,v| v.nil?}
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def api
|
49
|
+
@api ||= Emailvision::Api.new :endpoint => "apiccmd"
|
50
|
+
@api.open_connection unless @api.connected?
|
51
|
+
@api
|
52
|
+
end
|
53
|
+
|
54
|
+
def attribute?(attribute)
|
55
|
+
send(attribute).present?
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Emailvision4rails::Campaign < Emailvision4rails::Base
|
2
|
+
|
3
|
+
attributes(
|
4
|
+
:name,
|
5
|
+
:mailinglist_id,
|
6
|
+
:message_id,
|
7
|
+
:send_date,
|
8
|
+
:description,
|
9
|
+
:emaildedupflg,
|
10
|
+
:format,
|
11
|
+
:delivery_speed,
|
12
|
+
:notification,
|
13
|
+
:post_click_tracking,
|
14
|
+
:strategy,
|
15
|
+
:target,
|
16
|
+
:url_end_campaign,
|
17
|
+
:url_host,
|
18
|
+
:analytics
|
19
|
+
)
|
20
|
+
|
21
|
+
validates_presence_of(
|
22
|
+
:name,
|
23
|
+
:mailinglist_id,
|
24
|
+
:message_id,
|
25
|
+
:send_date
|
26
|
+
)
|
27
|
+
|
28
|
+
validate :send_date_must_be_in_the_future, :message => "must be more than 5 minutes in the future"
|
29
|
+
|
30
|
+
# Validate format of email address
|
31
|
+
|
32
|
+
def initialize(payload = {})
|
33
|
+
payload.each do |attr, val|
|
34
|
+
send("#{attr}=", val) if attributes.has_key?(attr.to_s)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def create
|
39
|
+
if valid?
|
40
|
+
run_callbacks :create do
|
41
|
+
api.post.campaign.create(:body => {:campaign => self.to_emv}).call
|
42
|
+
end
|
43
|
+
true
|
44
|
+
else
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def send_date_must_be_in_the_future
|
52
|
+
# Adds 5 minutes to ensure futurness of send date between validation and publication
|
53
|
+
send_date.present? ? (send_date > Time.now+5.minutes) : false
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class Emailvision4rails::Message < Emailvision4rails::Base
|
2
|
+
|
3
|
+
attributes(
|
4
|
+
:name,
|
5
|
+
:subject,
|
6
|
+
:from,
|
7
|
+
:from_email,
|
8
|
+
:body,
|
9
|
+
:reply_to,
|
10
|
+
:reply_to_email,
|
11
|
+
:id,
|
12
|
+
:create_date,
|
13
|
+
:to,
|
14
|
+
:description,
|
15
|
+
:encoding,
|
16
|
+
:hotmail_unsub_url,
|
17
|
+
:type,
|
18
|
+
:hotmail_unsub_flg,
|
19
|
+
:is_bounceback
|
20
|
+
)
|
21
|
+
|
22
|
+
validates_presence_of(
|
23
|
+
:name,
|
24
|
+
:subject,
|
25
|
+
:from,
|
26
|
+
:from_email,
|
27
|
+
:body,
|
28
|
+
:reply_to,
|
29
|
+
:reply_to_email
|
30
|
+
)
|
31
|
+
|
32
|
+
# Validate format of email address
|
33
|
+
|
34
|
+
def initialize(body = "", payload = {})
|
35
|
+
self.body = body
|
36
|
+
payload.each do |attr, val|
|
37
|
+
send("#{attr}=", val) if attributes.has_key?(attr.to_s)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def create
|
42
|
+
if valid?
|
43
|
+
run_callbacks :create do
|
44
|
+
self.id = api.post.message.create(:body => {:message => self.to_emv}).call
|
45
|
+
end
|
46
|
+
true
|
47
|
+
else
|
48
|
+
false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def update
|
53
|
+
if valid? and persisted?
|
54
|
+
run_callbacks :update do
|
55
|
+
api.post.message.create(:body => self.to_emv).call
|
56
|
+
end
|
57
|
+
else
|
58
|
+
false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Maybe in a helper?
|
63
|
+
def mirror_url_id
|
64
|
+
@mirror_url_id ||= api.get.url.create_and_add_mirror_url(uri: [message_id, 'mirror_url']).call
|
65
|
+
end
|
66
|
+
|
67
|
+
def track_links
|
68
|
+
emv.get.message.track_all_links(id: message_id).call
|
69
|
+
end
|
70
|
+
|
71
|
+
def persisted?
|
72
|
+
message_id.present?
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Emailvision4rails
|
2
|
+
class Newsletter
|
3
|
+
|
4
|
+
attr_accessor :parts, :payload
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@parts = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def publish
|
11
|
+
message = Message.new(content, payload[:message])
|
12
|
+
campaign = Campaign.new(payload[:campaign])
|
13
|
+
|
14
|
+
# Message
|
15
|
+
message.create
|
16
|
+
|
17
|
+
# Campaign
|
18
|
+
campaign.message_id = message.id
|
19
|
+
campaign.create
|
20
|
+
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def content
|
25
|
+
parts.map do |format, content|
|
26
|
+
"[EMV #{format.upcase}PART]\n#{content}"
|
27
|
+
end.join("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_html
|
31
|
+
parts[:html]
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_text
|
35
|
+
parts[:text]
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s
|
39
|
+
content
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'abstract_controller'
|
2
|
+
require 'action_view'
|
3
|
+
require 'action_mailer/collector'
|
4
|
+
|
5
|
+
module Emailvision4rails
|
6
|
+
class AbstractNewsletter < ::AbstractController::Base
|
7
|
+
abstract!
|
8
|
+
|
9
|
+
include AbstractController::Logger
|
10
|
+
include AbstractController::Rendering
|
11
|
+
include AbstractController::Layouts
|
12
|
+
|
13
|
+
append_view_path "#{Rails.root}/app/views"
|
14
|
+
|
15
|
+
private_class_method :new
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def respond_to?(method, include_private = false)
|
19
|
+
super || action_methods.include?(method.to_s)
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def method_missing(method, *args)
|
25
|
+
return super unless respond_to?(method)
|
26
|
+
new(method, *args).message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_internal :message
|
31
|
+
|
32
|
+
def initialize(method_name=nil, *args)
|
33
|
+
super()
|
34
|
+
lookup_context.formats = [:text, :html] # Restrict rendering formats to html and text
|
35
|
+
@_message = Newsletter.new
|
36
|
+
process(method_name, *args) if method_name
|
37
|
+
end
|
38
|
+
|
39
|
+
def process(method_name, *args)
|
40
|
+
lookup_context.skip_default_locale!
|
41
|
+
super(method_name, *args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def newsletter(params = {})
|
45
|
+
message = @_message
|
46
|
+
|
47
|
+
lookup_context.locale = params.delete(:language) if params[:language]
|
48
|
+
|
49
|
+
responses = collect_responses(lookup_context.formats)
|
50
|
+
|
51
|
+
message.parts = responses
|
52
|
+
message.payload = params
|
53
|
+
|
54
|
+
message
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def collect_responses(formats)
|
60
|
+
collector = ActionMailer::Collector.new(lookup_context) do
|
61
|
+
render(action_name)
|
62
|
+
end
|
63
|
+
responses = {}
|
64
|
+
formats.each do |f|
|
65
|
+
collector.send(f)
|
66
|
+
responses[f] = collector.responses.last[:body]
|
67
|
+
end
|
68
|
+
responses
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Emailvision4rails
|
2
|
+
class Premailer < ::Premailer
|
3
|
+
def initialize(html)
|
4
|
+
::Premailer.send(:include, Adapter.find(Adapter.use))
|
5
|
+
|
6
|
+
encoding = Configuration.encoding.upcase
|
7
|
+
options = {
|
8
|
+
:adapter => :hpricot,
|
9
|
+
:warn_level => Premailer::Warnings::SAFE,
|
10
|
+
:with_html_string => true,
|
11
|
+
:encoding => encoding,
|
12
|
+
:input_encoding => encoding,
|
13
|
+
:inputencoding => encoding
|
14
|
+
}
|
15
|
+
|
16
|
+
super(html, options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Emailvision4rails
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
config.to_prepare do
|
7
|
+
file = "#{Rails.root}/config/emailvision.yml"
|
8
|
+
|
9
|
+
if File.exist?(file)
|
10
|
+
config = YAML.load_file(file)[Rails.env] || {}
|
11
|
+
|
12
|
+
Configuration.server_name = config['server_name']
|
13
|
+
Configuration.endpoint = config['endpoint']
|
14
|
+
Configuration.login = config['login']
|
15
|
+
Configuration.password = config['password']
|
16
|
+
Configuration.key = config['key']
|
17
|
+
Configuration.debug = config['debug']
|
18
|
+
Configuration.encoding = Rails.configuration.encoding || 'utf-8'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class NewsletterGenerator < Rails::Generators::NamedBase
|
2
|
+
argument :actions, :type => :array, :default => [], :banner => "action action"
|
3
|
+
check_class_collision :suffix => "Newsletter"
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
def create_newsletter_file
|
7
|
+
template 'newsletter.rb', File.join('app/newsletters', class_path, "#{file_name}_newsletter.rb")
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_view_files
|
11
|
+
actions.each do |action|
|
12
|
+
available_formats.each do |format|
|
13
|
+
template "action.#{format}.emv", File.join('app/views', class_path, "#{file_name}_newsletter", "#{action}.#{format}.emv")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def available_formats
|
21
|
+
%w(html text)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<% module_namespacing do -%>
|
2
|
+
class <%= class_name %>Newsletter < Emailvision4rails::AbstractNewsletter
|
3
|
+
<% actions.each do |action| -%>
|
4
|
+
|
5
|
+
def <%= action %>
|
6
|
+
@greeting = "Hi"
|
7
|
+
|
8
|
+
newsletter(
|
9
|
+
:message => {:name => "<%= action %>"},
|
10
|
+
:campaign => {:send_date => Time.now+10.minutes, :mailinglist_id => 123}
|
11
|
+
)
|
12
|
+
end
|
13
|
+
<% end -%>
|
14
|
+
end
|
15
|
+
<% end -%>
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: emailvision4rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bastien Gysler
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: emailvision
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.1'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.1'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: premailer
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.7'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: hpricot
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.8'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.8'
|
78
|
+
description: Manage Emailvision campaigns and messages from your rails application
|
79
|
+
email: basgys@gmail.com
|
80
|
+
executables: []
|
81
|
+
extensions: []
|
82
|
+
extra_rdoc_files: []
|
83
|
+
files:
|
84
|
+
- lib/emailvision4rails/configuration.rb
|
85
|
+
- lib/emailvision4rails/emv_handler.rb
|
86
|
+
- lib/emailvision4rails/models/base.rb
|
87
|
+
- lib/emailvision4rails/models/campaign.rb
|
88
|
+
- lib/emailvision4rails/models/message.rb
|
89
|
+
- lib/emailvision4rails/newsletter.rb
|
90
|
+
- lib/emailvision4rails/newsletters/abstract_newsletter.rb
|
91
|
+
- lib/emailvision4rails/premailer.rb
|
92
|
+
- lib/emailvision4rails/railtie.rb
|
93
|
+
- lib/emailvision4rails/version.rb
|
94
|
+
- lib/emailvision4rails.rb
|
95
|
+
- lib/generators/emailvision4rails/setup_generator.rb
|
96
|
+
- lib/generators/emailvision4rails/templates/emailvision.yml
|
97
|
+
- lib/generators/newsletter_generator.rb
|
98
|
+
- lib/generators/templates/action.html.emv
|
99
|
+
- lib/generators/templates/action.text.emv
|
100
|
+
- lib/generators/templates/newsletter.rb
|
101
|
+
- MIT-LICENSE
|
102
|
+
- Rakefile
|
103
|
+
- Gemfile
|
104
|
+
- README.markdown
|
105
|
+
homepage: https://github.com/basgys/emailvision4rails
|
106
|
+
licenses: []
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.8.23
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: Emailvision library for Ruby on Rails
|
129
|
+
test_files: []
|