idlemailer 2.1.0 → 2.2.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.
- checksums.yaml +4 -4
- data/README.md +13 -3
- data/lib/idlemailer/html_safe_string.rb +16 -0
- data/lib/idlemailer/template_manager.rb +5 -4
- data/lib/idlemailer/templates.rb +27 -0
- data/lib/idlemailer/version.rb +1 -1
- data/lib/idlemailer.rb +2 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 288e28b5d6f7ac40873806faa8bf56b8e66143a96819be6025238bcbc5fbc239
|
4
|
+
data.tar.gz: 76389af5d9027c264ae2cd2ae0f014a184a3bff41204a001d0a9061ef83e223f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 294f547d16812a33f260ac1dfd10602de80e62cda27c8bf6d4401745c2b8e75c74fd840103f2bb04552df1bc4da4da6878de8a4bd40ad213301171ba6649c8aa
|
7
|
+
data.tar.gz: f86dfb20178f2dbc43826b6ffb1e879009eed952be403be29f41873c2d19d7aa431e2e00b90ae6d1a8ebc58bd2d92a1637c054be7d4fe6f323fdb0443c47a480
|
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# IdleMailer
|
2
2
|
|
3
|
-
A lightweight (~
|
3
|
+
A lightweight (~200 line) alternative to ActionMailer for Rubyists who are too cool for Rails. Powered by the [mail](http://www.rubydoc.info/gems/mail) gem. Great for API-only backends that need to send email.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add to your Gemfile.
|
8
8
|
|
9
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'idlemailer'
|
11
|
+
```
|
10
12
|
|
11
13
|
## Use
|
12
14
|
|
@@ -27,12 +29,20 @@ class WidgetMailer
|
|
27
29
|
end
|
28
30
|
|
29
31
|
# Create widget.html.erb and/or widget.text.erb in your templates directory.
|
30
|
-
# They'll have access to instance variables like @widget above.
|
32
|
+
# They'll have access to instance variables like @widget above, as well as any methods you define.
|
31
33
|
|
32
34
|
# Send your mail
|
33
35
|
WidgetMailer.new(current_user, widget).deliver
|
34
36
|
```
|
35
37
|
|
38
|
+
### HTML escaping
|
39
|
+
|
40
|
+
All values will be automatically HTML-escaped. If you need to bypass escapeing, use the `raw` helper:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
<%= raw @something_with_safe_html %>
|
44
|
+
```
|
45
|
+
|
36
46
|
### Inline templates
|
37
47
|
|
38
48
|
If you prefer, you can embed your ERB templates right inside your Ruby class, instead of making separate template files. Slick amiright?
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module IdleMailer
|
2
|
+
class HtmlSafeString < String
|
3
|
+
def <<(str)
|
4
|
+
safe_str = str.is_a?(HtmlSafeString) ? str : ERB::Util.html_escape(str.to_s)
|
5
|
+
super safe_str
|
6
|
+
end
|
7
|
+
|
8
|
+
def safe_concat(val)
|
9
|
+
self << HtmlSafeString.new(val)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
self
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -3,6 +3,7 @@ module IdleMailer
|
|
3
3
|
module TemplateManager
|
4
4
|
def self.extended(klass)
|
5
5
|
klass.class_eval do
|
6
|
+
include Templates::Helpers
|
6
7
|
class << self
|
7
8
|
attr_reader :layouts, :templates
|
8
9
|
end
|
@@ -12,19 +13,19 @@ module IdleMailer
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def text(str)
|
15
|
-
templates['text'] =
|
16
|
+
templates['text'] = Templates.compile str.chomp
|
16
17
|
end
|
17
18
|
|
18
19
|
def html(str)
|
19
|
-
templates['html'] =
|
20
|
+
templates['html'] = Templates.compile str.chomp
|
20
21
|
end
|
21
22
|
|
22
23
|
def template(type)
|
23
|
-
templates[type] ||
|
24
|
+
templates[type] || Templates.compile(template_path(template_name, type).read.chomp)
|
24
25
|
end
|
25
26
|
|
26
27
|
def layout(type)
|
27
|
-
layouts[type] ||
|
28
|
+
layouts[type] || Templates.compile(template_path(layout_name, type).read.chomp)
|
28
29
|
end
|
29
30
|
|
30
31
|
def layout=(new_name)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module IdleMailer
|
2
|
+
module Templates
|
3
|
+
def self.compile(src)
|
4
|
+
compiler = ERB::Compiler.new("<>")
|
5
|
+
compiler.pre_cmd = ["_erbout=+HtmlSafeString.new"]
|
6
|
+
compiler.put_cmd = "_erbout.safe_concat"
|
7
|
+
compiler.insert_cmd = "_erbout.<<"
|
8
|
+
compiler.post_cmd = ["_erbout"]
|
9
|
+
code, _enc = compiler.compile(src)
|
10
|
+
Template.new code.freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
Template = Struct.new(:code) do
|
14
|
+
def result(bind)
|
15
|
+
_erbout = HtmlSafeString.new
|
16
|
+
eval code, bind
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Helpers
|
21
|
+
# Don't HTML-escape the given value
|
22
|
+
def raw(str)
|
23
|
+
HtmlSafeString.new(str)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/idlemailer/version.rb
CHANGED
data/lib/idlemailer.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idlemailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|
@@ -36,9 +36,11 @@ files:
|
|
36
36
|
- lib/idlemailer.rb
|
37
37
|
- lib/idlemailer/config.rb
|
38
38
|
- lib/idlemailer/defaults.rb
|
39
|
+
- lib/idlemailer/html_safe_string.rb
|
39
40
|
- lib/idlemailer/mailer.rb
|
40
41
|
- lib/idlemailer/message.rb
|
41
42
|
- lib/idlemailer/template_manager.rb
|
43
|
+
- lib/idlemailer/templates.rb
|
42
44
|
- lib/idlemailer/testing.rb
|
43
45
|
- lib/idlemailer/version.rb
|
44
46
|
homepage: https://github.com/jhollinger/idlemailer
|
@@ -59,8 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
61
|
- !ruby/object:Gem::Version
|
60
62
|
version: '0'
|
61
63
|
requirements: []
|
62
|
-
|
63
|
-
rubygems_version: 2.7.6
|
64
|
+
rubygems_version: 3.0.3
|
64
65
|
signing_key:
|
65
66
|
specification_version: 4
|
66
67
|
summary: A lightweight alternative to ActionMailer
|