idlemailer 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad91007cd0d5f336f443b3107e150dc865e52cd7048642a388e9d3b476fd180c
4
- data.tar.gz: 822bbb3f19ffb0878d568574672fca4a6ad531c9b73f51935ce1ecae9ff77a7d
3
+ metadata.gz: 288e28b5d6f7ac40873806faa8bf56b8e66143a96819be6025238bcbc5fbc239
4
+ data.tar.gz: 76389af5d9027c264ae2cd2ae0f014a184a3bff41204a001d0a9061ef83e223f
5
5
  SHA512:
6
- metadata.gz: dc64bf86b25a4fc15d99d9d3a38b99c48a759816ed73e90182169236de159e003a2e44b473c09d079ad4f06eb0ba5fcf2b3c980c3cb7630585a3c7139c7a2f14
7
- data.tar.gz: 2291ccedc03e3d310c59eda8e98d153560221ef22d71e47898942e7b9d3adef053c5a235a41f3a58eb26ef2b0fbcc01b4665f2df2887b111db3b2a807c2fd4b1
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 (~150 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.
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
- gem 'idlemailer'
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'] = ERB.new str.chomp
16
+ templates['text'] = Templates.compile str.chomp
16
17
  end
17
18
 
18
19
  def html(str)
19
- templates['html'] = ERB.new str.chomp
20
+ templates['html'] = Templates.compile str.chomp
20
21
  end
21
22
 
22
23
  def template(type)
23
- templates[type] || ERB.new(template_path(template_name, type).read.chomp)
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] || ERB.new(template_path(layout_name, type).read.chomp)
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
@@ -1,5 +1,5 @@
1
1
  # IdleMailer module
2
2
  module IdleMailer
3
3
  # Version number
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  end
data/lib/idlemailer.rb CHANGED
@@ -7,6 +7,8 @@ require 'idlemailer/defaults'
7
7
  require 'idlemailer/message'
8
8
  require 'idlemailer/mailer'
9
9
  require 'idlemailer/template_manager'
10
+ require 'idlemailer/templates'
11
+ require 'idlemailer/html_safe_string'
10
12
  require 'idlemailer/version'
11
13
 
12
14
  module IdleMailer
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.1.0
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: 2017-07-18 00:00:00.000000000 Z
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
- rubyforge_project:
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