snails 0.4.3 → 0.5.1
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.
- checksums.yaml +4 -4
- data/lib/snails/app.rb +5 -4
- data/lib/snails/mailer.rb +35 -7
- data/snails.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4dea5ffee5850e36c01a2eb6ea7816a7f9939c80b434f19d141914826a309de
|
|
4
|
+
data.tar.gz: 8515507cbd3caab1aa59f7eaf9e2cb18e45540eb1598f400a05c137369984022
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 014b50854e970f640543d67c0fcb061f1b319db1d248057b03f197a05de2adcc9fa06b9612cd01a74a0c2a780096a436d628941eaddafb9c05ed743fd38f9dfe
|
|
7
|
+
data.tar.gz: 7c32661693186daae08b75b47b643350623bdf2741ef8d2537da4dcb6178668e672a024c7040cb5d2bb0f0ce06f957dd23931c12338ba27992545689a46777fa
|
data/lib/snails/app.rb
CHANGED
|
@@ -222,7 +222,7 @@ module Snails
|
|
|
222
222
|
value = options[:value] ? "value=\"#{options[:value]}\"" : (type == :password ? '' : "value=\"#{object.send(field)}\"")
|
|
223
223
|
|
|
224
224
|
classes = object.errors[field].any? ? 'has-errors' : ''
|
|
225
|
-
label + raw_input(index, type, id, name, value, options[:placeholder], classes, options[:required])
|
|
225
|
+
label + raw_input(index, type, id, name, value, placeholder: options[:placeholder], classes: classes, required: options[:required], disabled: options[:disabled])
|
|
226
226
|
end
|
|
227
227
|
|
|
228
228
|
def form_password(object, field, options = {})
|
|
@@ -243,7 +243,7 @@ module Snails
|
|
|
243
243
|
value += checked ? " checked='true'" : ''
|
|
244
244
|
end
|
|
245
245
|
|
|
246
|
-
label + raw_input(index, type, id, name, options[:placeholder],
|
|
246
|
+
label + raw_input(index, type, id, name, value, options[:placeholder], classes: classes, disabled: options[:disabled])
|
|
247
247
|
end
|
|
248
248
|
|
|
249
249
|
def form_textarea(object, field, options = {})
|
|
@@ -316,9 +316,10 @@ module Snails
|
|
|
316
316
|
return id, name, @tabindex, label
|
|
317
317
|
end
|
|
318
318
|
|
|
319
|
-
def raw_input(index, type, id, name, value, placeholder
|
|
319
|
+
def raw_input(index, type, id, name, value, placeholder: '', classes: '', required: false, disabled: false)
|
|
320
320
|
req = required ? "required" : ''
|
|
321
|
-
|
|
321
|
+
dis = disabled ? "disabled" : ''
|
|
322
|
+
"<input #{req} #{dis} class='#{classes}' tabindex='#{index}' type='#{type}' id='#{id}' name='#{name}' placeholder='#{placeholder}' #{value} />"
|
|
322
323
|
end
|
|
323
324
|
|
|
324
325
|
def get_model_name(obj)
|
data/lib/snails/mailer.rb
CHANGED
|
@@ -16,14 +16,26 @@ module Snails
|
|
|
16
16
|
# class SoftBounce < Bounce; end
|
|
17
17
|
# class HardBounce < Bounce; end
|
|
18
18
|
|
|
19
|
+
def self.backends
|
|
20
|
+
{
|
|
21
|
+
'test_backend' => 'Snails::Mailer::TestBackend',
|
|
22
|
+
'smtp' => 'Snails::Mailer::TuktukBackend',
|
|
23
|
+
'mailgun' => 'Snails::Mailer::MailgunBackend'
|
|
24
|
+
}
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.init_backend(backend_name, opts = {})
|
|
28
|
+
backend_name = backend_name.presence || 'test_backend'
|
|
29
|
+
backends[backend_name].constantize.new(opts)
|
|
30
|
+
end
|
|
31
|
+
|
|
19
32
|
def initialize(opts)
|
|
20
33
|
@from_email = opts[:from] or raise ":from required"
|
|
21
34
|
@base_subject = opts[:base_subject] || ''
|
|
22
35
|
@views = opts[:views] || Snails.root.join('lib', 'views')
|
|
23
36
|
@logfile = opts[:logfile] # || Snails.root.join('log', 'mailer.log')
|
|
24
37
|
|
|
25
|
-
|
|
26
|
-
@backend = self.class.backends[backend_name].new(opts[:backend_options])
|
|
38
|
+
@backend = self.class.init_backend(opts[:backend_name], opts[:backend_options])
|
|
27
39
|
end
|
|
28
40
|
|
|
29
41
|
def email(name, &block)
|
|
@@ -77,7 +89,7 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
|
77
89
|
|
|
78
90
|
private
|
|
79
91
|
|
|
80
|
-
def render(view_path,
|
|
92
|
+
def render(view_path, layout_path = nil)
|
|
81
93
|
view = File.read(File.join(@views, "#{view_path}.erb"))
|
|
82
94
|
if layout_path
|
|
83
95
|
layout = File.read(File.join(@views, "#{layout_path}.erb"))
|
|
@@ -100,7 +112,7 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
|
100
112
|
@logger ||= @logfile ? Logger.new(@logfile) : Snails.logger
|
|
101
113
|
end
|
|
102
114
|
|
|
103
|
-
def send_email(from: @from_email, to:, subject:, body: nil, template: nil, layout: nil, html_body: nil, html_template: nil, html_layout: nil, message_id: nil, return_path: nil, list_unsubscribe: nil)
|
|
115
|
+
def send_email(from: @from_email, to:, subject:, body: nil, template: nil, layout: nil, html_body: nil, html_template: nil, html_layout: nil, message_id: nil, attachments: nil, return_path: nil, list_unsubscribe: nil)
|
|
104
116
|
raise "No recipient given for mail: #{subject}!" if to.blank?
|
|
105
117
|
|
|
106
118
|
message = {
|
|
@@ -120,6 +132,7 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
|
120
132
|
message[:html_body] = html_template ? render(html_template, html_layout) : html_body
|
|
121
133
|
end
|
|
122
134
|
|
|
135
|
+
message[:attachments] = attachments if attachments
|
|
123
136
|
message[:message_id] = message_id if message_id
|
|
124
137
|
message[:return_path] = return_path if return_path
|
|
125
138
|
message[:list_unsubscribe] = list_unsubscribe if list_unsubscribe
|
|
@@ -140,10 +153,25 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
|
140
153
|
end
|
|
141
154
|
end
|
|
142
155
|
|
|
143
|
-
class
|
|
156
|
+
class TestBackend < Backend
|
|
157
|
+
def initialize(opts = {})
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def deliver(email, options = {})
|
|
161
|
+
puts "Deliverying single: #{email[:to]}"
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def deliver_many(emails, options = {})
|
|
165
|
+
puts "Deliverying many: #{emails.count}"
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
class TuktukBackend < Backend
|
|
144
170
|
def initialize(config = {})
|
|
145
171
|
@debug = config[:debug]
|
|
146
172
|
|
|
173
|
+
puts "-- #{config.inspect}"
|
|
174
|
+
|
|
147
175
|
if key = config.dig(:dkim, :private_key) and File.exist?(key)
|
|
148
176
|
config[:dkim][:private_key] = IO.read(key)
|
|
149
177
|
elsif config[:dkim]
|
|
@@ -159,7 +187,7 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
|
159
187
|
resp, email = Tuktuk.deliver(email, debug: debug)
|
|
160
188
|
|
|
161
189
|
if resp.is_a?(Tuktuk::Bounce)
|
|
162
|
-
|
|
190
|
+
puts "[#{to}] Email bounced! [#{resp.code}] #{resp.message}"
|
|
163
191
|
end
|
|
164
192
|
|
|
165
193
|
return resp, email
|
|
@@ -170,7 +198,7 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
|
170
198
|
end
|
|
171
199
|
end
|
|
172
200
|
|
|
173
|
-
class
|
|
201
|
+
class MailgunBackend < Backend
|
|
174
202
|
|
|
175
203
|
def initialize(api_key:, domain_name:)
|
|
176
204
|
@key = api_key
|
data/snails.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: snails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomás Pollak
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-10-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|