snails 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/snails/mailer.rb +18 -8
- data/lib/snails.rb +78 -74
- data/snails.gemspec +4 -3
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daf351c2597c83b274ecc9a36cd7bd8558b96e0e
|
4
|
+
data.tar.gz: eaa66e198d7d3b20cad52442d8999fff954ed060
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bb1cc458d7d5120ebc098ff6641013e7fba9ff18ce57ca12e86269189b1a2b741f9f94362298a518d9cd1b81841d9ea38548730c625ecb763ea98641a76b4f9
|
7
|
+
data.tar.gz: 6082675242f0a8295e3a10a7f234f18b6a5d29e6274533985ea1e8cf09be38dd7aef653b2fa0e273bb82b187455ae3b91f46b543524529d9447aa0f631cb7432
|
data/lib/snails/mailer.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'tilt/erb'
|
3
3
|
require 'tuktuk'
|
4
|
+
require 'snails'
|
4
5
|
|
5
6
|
module Snails
|
6
7
|
|
7
8
|
class Mailer
|
9
|
+
include Snails::SimpleFormat
|
10
|
+
Time.include(Snails::RelativeTime) unless Time.instance_methods.include?(:relative)
|
8
11
|
|
9
12
|
@queue = :emails
|
10
13
|
|
@@ -33,6 +36,10 @@ module Snails
|
|
33
36
|
end
|
34
37
|
end
|
35
38
|
|
39
|
+
def helpers(&block)
|
40
|
+
instance_eval(&block)
|
41
|
+
end
|
42
|
+
|
36
43
|
def perform(method, *args)
|
37
44
|
send(method, *args)
|
38
45
|
end
|
@@ -43,7 +50,7 @@ module Snails
|
|
43
50
|
Resque.enqueue(self, method, obj.id, *args)
|
44
51
|
end
|
45
52
|
|
46
|
-
def send_error(to: @from_email, err:, env:, params: {}
|
53
|
+
def send_error(to: @from_email, err:, env:, params: {})
|
47
54
|
@exception, @env, @params = err, env, params
|
48
55
|
@url = "#{env['REQUEST_METHOD']} #{env['REQUEST_URI']}"
|
49
56
|
|
@@ -88,22 +95,25 @@ A <%= @exception.class %> occurred in <%= @url %>:
|
|
88
95
|
@logger ||= Logger.new(@logfile)
|
89
96
|
end
|
90
97
|
|
91
|
-
def send_email(to:, subject:, body
|
98
|
+
def send_email(from: nil, to:, subject:, body: nil, template: nil, html_body: nil, html_template: nil)
|
92
99
|
raise "No recipient given for mail: #{subject}!" if to.blank?
|
93
100
|
|
94
101
|
message = {
|
95
102
|
to: to,
|
96
103
|
from: from || @from_email,
|
97
|
-
subject: @base_subject + subject
|
98
|
-
body: body.is_a?(Symbol) ? render(body) : body
|
104
|
+
subject: @base_subject + subject
|
99
105
|
}
|
100
106
|
|
101
|
-
if
|
102
|
-
message[:
|
107
|
+
if body or template
|
108
|
+
message[:body] = template ? render(template) : body
|
109
|
+
end
|
110
|
+
|
111
|
+
if html_body or html_template
|
112
|
+
message[:html_body] = html_template ? render(html_template) : html_body
|
103
113
|
end
|
104
114
|
|
105
|
-
logger.info "[#{to}] Delivering: #{subject}"
|
106
|
-
resp, email = Tuktuk.deliver(message
|
115
|
+
logger.info "[#{to}] Delivering: #{subject}" # debug
|
116
|
+
resp, email = Tuktuk.deliver(message, debug: !Snails.env.production?)
|
107
117
|
|
108
118
|
if resp.is_a?(Tuktuk::Bounce)
|
109
119
|
logger.info "[#{to}] Email bounced! [#{resp.code}] #{resp.message}"
|
data/lib/snails.rb
CHANGED
@@ -279,80 +279,7 @@ module Snails
|
|
279
279
|
|
280
280
|
end
|
281
281
|
|
282
|
-
module
|
283
|
-
|
284
|
-
def self.included(base)
|
285
|
-
Time.include(RelativeTime) unless Time.instance_methods.include?(:relative)
|
286
|
-
end
|
287
|
-
|
288
|
-
def action
|
289
|
-
request.path_info.gsub('/','').blank? ? 'home' : request.path_info.gsub('/',' ')
|
290
|
-
end
|
291
|
-
|
292
|
-
def partial(name, opts = {})
|
293
|
-
partial_name = name.to_s["/"] ? name.to_s.reverse.sub("/", "_/").reverse : "_#{name}"
|
294
|
-
erb(partial_name.to_sym, { layout: false }.merge(opts))
|
295
|
-
end
|
296
|
-
|
297
|
-
def view(view_name, opts = {})
|
298
|
-
layout = request.xhr? ? false : true
|
299
|
-
erb(view_name.to_sym, { layout: layout }.merge(opts))
|
300
|
-
end
|
301
|
-
|
302
|
-
#########################################
|
303
|
-
# pagination
|
304
|
-
|
305
|
-
def get_page(counter)
|
306
|
-
curr = params[:page].to_i
|
307
|
-
i = (curr == 0 && counter == 1) ? 2
|
308
|
-
: (curr == 2 && counter == -1) ? 0
|
309
|
-
: curr + counter
|
310
|
-
i == 0 ? "" : "/page/#{i}"
|
311
|
-
end
|
312
|
-
|
313
|
-
def show_pager(array, path)
|
314
|
-
# remove page from path
|
315
|
-
path = (env['SCRIPT_NAME'] + path.gsub(/[?|&|\/]page[=|\/]\d+/,''))
|
316
|
-
|
317
|
-
prevlink = '<li>' + link_to("#{path}#{get_page(-1)}", '← Prev').sub('//', '/') + '</li>'
|
318
|
-
nextlink = array.count != Routes::PER_PAGE ? ""
|
319
|
-
: '<li>' + link_to("#{path}#{get_page(1)}", 'Next →').sub('//', '/') + '</li>'
|
320
|
-
|
321
|
-
str = params[:page] ? prevlink + nextlink : nextlink
|
322
|
-
str != "" ? "<ul class='pager'>" + str + "</ul>" : ''
|
323
|
-
end
|
324
|
-
|
325
|
-
#########################################
|
326
|
-
# formatting
|
327
|
-
|
328
|
-
def tag(name, options = nil, open = false)
|
329
|
-
attributes = tag_attributes(options)
|
330
|
-
"<#{name}#{attributes}#{open ? '>' : ' />'}"
|
331
|
-
end
|
332
|
-
|
333
|
-
def tag_attributes(options)
|
334
|
-
return '' unless options
|
335
|
-
options.inject('') do |all,(key,value)|
|
336
|
-
next all unless value
|
337
|
-
all << ' ' if all.empty?
|
338
|
-
all << %(#{key}="#{value}" )
|
339
|
-
end.chomp!(' ')
|
340
|
-
end
|
341
|
-
|
342
|
-
def simple_format(text, options = {})
|
343
|
-
t = options.delete(:tag) || :p
|
344
|
-
start_tag = tag(t, options, true)
|
345
|
-
text = text.to_s.dup
|
346
|
-
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
|
347
|
-
text.gsub!(/\n\n+/, "</#{t}>\n\n#{start_tag}") # 2+ newline -> paragraph
|
348
|
-
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
349
|
-
text.insert 0, start_tag
|
350
|
-
text << "</#{t}>"
|
351
|
-
text
|
352
|
-
end
|
353
|
-
|
354
|
-
#########################################
|
355
|
-
# forms
|
282
|
+
module FormHelpers
|
356
283
|
|
357
284
|
def form_input(object, field, options = {})
|
358
285
|
id, name, index, label = input_base(object, field, options)
|
@@ -455,6 +382,83 @@ module Snails
|
|
455
382
|
|
456
383
|
end
|
457
384
|
|
385
|
+
module SimpleFormat
|
386
|
+
|
387
|
+
def tag(name, options = nil, open = false)
|
388
|
+
attributes = tag_attributes(options)
|
389
|
+
"<#{name}#{attributes}#{open ? '>' : ' />'}"
|
390
|
+
end
|
391
|
+
|
392
|
+
def tag_attributes(options)
|
393
|
+
return '' unless options
|
394
|
+
options.inject('') do |all,(key,value)|
|
395
|
+
next all unless value
|
396
|
+
all << ' ' if all.empty?
|
397
|
+
all << %(#{key}="#{value}" )
|
398
|
+
end.chomp!(' ')
|
399
|
+
end
|
400
|
+
|
401
|
+
def simple_format(text, options = {})
|
402
|
+
t = options.delete(:tag) || :p
|
403
|
+
start_tag = tag(t, options, true)
|
404
|
+
text = text.to_s.dup
|
405
|
+
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
|
406
|
+
text.gsub!(/\n\n+/, "</#{t}>\n\n#{start_tag}") # 2+ newline -> paragraph
|
407
|
+
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
408
|
+
text.insert 0, start_tag
|
409
|
+
text << "</#{t}>"
|
410
|
+
text
|
411
|
+
end
|
412
|
+
|
413
|
+
end
|
414
|
+
|
415
|
+
module ViewHelpers
|
416
|
+
|
417
|
+
def self.included(base)
|
418
|
+
Time.include(RelativeTime) unless Time.instance_methods.include?(:relative)
|
419
|
+
base.include(FormHelpers)
|
420
|
+
base.include(SimpleFormat)
|
421
|
+
end
|
422
|
+
|
423
|
+
def action
|
424
|
+
request.path_info.gsub('/','').blank? ? 'home' : request.path_info.gsub('/',' ')
|
425
|
+
end
|
426
|
+
|
427
|
+
def partial(name, opts = {})
|
428
|
+
partial_name = name.to_s["/"] ? name.to_s.reverse.sub("/", "_/").reverse : "_#{name}"
|
429
|
+
erb(partial_name.to_sym, { layout: false }.merge(opts))
|
430
|
+
end
|
431
|
+
|
432
|
+
def view(view_name, opts = {})
|
433
|
+
layout = request.xhr? ? false : true
|
434
|
+
erb(view_name.to_sym, { layout: layout }.merge(opts))
|
435
|
+
end
|
436
|
+
|
437
|
+
#########################################
|
438
|
+
# pagination
|
439
|
+
|
440
|
+
def get_page(counter)
|
441
|
+
curr = params[:page].to_i
|
442
|
+
i = (curr == 0 && counter == 1) ? 2
|
443
|
+
: (curr == 2 && counter == -1) ? 0
|
444
|
+
: curr + counter
|
445
|
+
i == 0 ? "" : "/page/#{i}"
|
446
|
+
end
|
447
|
+
|
448
|
+
def show_pager(array, path)
|
449
|
+
# remove page from path
|
450
|
+
path = (env['SCRIPT_NAME'] + path.gsub(/[?|&|\/]page[=|\/]\d+/,''))
|
451
|
+
|
452
|
+
prevlink = '<li>' + link_to("#{path}#{get_page(-1)}", '← Prev').sub('//', '/') + '</li>'
|
453
|
+
nextlink = array.count != Routes::PER_PAGE ? ""
|
454
|
+
: '<li>' + link_to("#{path}#{get_page(1)}", 'Next →').sub('//', '/') + '</li>'
|
455
|
+
|
456
|
+
str = params[:page] ? prevlink + nextlink : nextlink
|
457
|
+
str != "" ? "<ul class='pager'>" + str + "</ul>" : ''
|
458
|
+
end
|
459
|
+
|
460
|
+
end
|
461
|
+
|
458
462
|
module RelativeTime
|
459
463
|
|
460
464
|
def in_words
|
data/snails.gemspec
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "snails"
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.8'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ['Tomás Pollak']
|
9
9
|
s.email = ['tomas@forkhq.com']
|
10
10
|
# s.homepage = "https://github.com/tomas/snails"
|
11
|
-
s.summary = "
|
12
|
-
s.description = "
|
11
|
+
s.summary = "Ruby on Snails."
|
12
|
+
s.description = "Ruby on Snails."
|
13
13
|
|
14
14
|
s.required_rubygems_version = ">= 1.3.6"
|
15
15
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_runtime_dependency "sinatra-activerecord", ">= 2.0.13"
|
21
21
|
s.add_runtime_dependency "sinatra-flash", ">= 0.3.0"
|
22
22
|
s.add_runtime_dependency "sprockets-helpers", ">= 1.2"
|
23
|
+
s.add_runtime_dependency "tuktuk", ">= 0.6.0"
|
23
24
|
|
24
25
|
s.files = `git ls-files`.split("\n")
|
25
26
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
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.0.
|
4
|
+
version: 0.0.8
|
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: 2018-11-
|
11
|
+
date: 2018-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,7 +114,21 @@ dependencies:
|
|
114
114
|
- - ">="
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '1.2'
|
117
|
-
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: tuktuk
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.6.0
|
124
|
+
type: :runtime
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.6.0
|
131
|
+
description: Ruby on Snails.
|
118
132
|
email:
|
119
133
|
- tomas@forkhq.com
|
120
134
|
executables: []
|
@@ -152,5 +166,5 @@ rubyforge_project:
|
|
152
166
|
rubygems_version: 2.6.13
|
153
167
|
signing_key:
|
154
168
|
specification_version: 4
|
155
|
-
summary:
|
169
|
+
summary: Ruby on Snails.
|
156
170
|
test_files: []
|