html_email_creator 1.0.10 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ module HtmlEmailCreator
2
+
3
+ # Mail creation consists of many steps. This is a place where you coordinate additional steps.
4
+ # In the future you may even register callbacks to your plugins if that feture is needed.
5
+ class Callbacks
6
+
7
+ def initialize(settings = HtmlEmailCreator.settings)
8
+ @settings = settings
9
+ end
10
+
11
+ def html_created(html)
12
+ HtmlEmailCreator::Extensions.new.process_html(html, *@settings.built_in_extensions)
13
+ end
14
+
15
+ end
16
+ end
@@ -27,11 +27,12 @@ module HtmlEmailCreator
27
27
  'unsubscribe_url' => '*|UNSUBSCRIBE|*'
28
28
  }
29
29
  }
30
-
31
- def initialize(settings = HtmlEmailCreator.settings)
32
- @settings = settings
30
+
31
+ # This is a mechanism for handling HTML email for certain extension
32
+
33
+ def initialize()
33
34
  end
34
-
35
+
35
36
  def built_in(*extensions)
36
37
  new_data = {}
37
38
  extensions.flatten.each do |extension|
@@ -40,7 +41,7 @@ module HtmlEmailCreator
40
41
  end
41
42
  new_data
42
43
  end
43
-
44
+
44
45
  def custom(data = {}, extensions)
45
46
  new_data = {}
46
47
  extensions.each_pair do |key, value|
@@ -48,5 +49,30 @@ module HtmlEmailCreator
48
49
  end
49
50
  new_data
50
51
  end
52
+
53
+ # HTML callback after the HTML is created.
54
+ def process_html(html, *extensions)
55
+ processed_html = html.dup
56
+
57
+ extensions.each do |extension|
58
+ method_name = "process_html_for_#{extension}".to_sym
59
+
60
+ if self.respond_to?(method_name)
61
+ processed_html = self.send(method_name, html)
62
+ end
63
+ end
64
+
65
+ processed_html
66
+ end
67
+
68
+ protected
69
+
70
+ def process_html_for_aweber(html)
71
+ html.gsub(/%7B/, '{').gsub(/%7D/, '}').gsub(/!global%20/, '!global ')
72
+ end
73
+
74
+ def process_html_for_mailchimp(html)
75
+ html.gsub(/\*%7C/, '*|').gsub(/%7C\*/, '|*')
76
+ end
51
77
  end
52
78
  end
@@ -5,7 +5,7 @@ require 'inline-style'
5
5
 
6
6
  module HtmlEmailCreator
7
7
  class Processor
8
- def initialize(email_string, settings = HtmlEmailCreator.settings)
8
+ def initialize(email_string, settings = HtmlEmailCreator::settings)
9
9
  @email = email_string
10
10
  @settings = settings
11
11
  end
@@ -41,14 +41,9 @@ module HtmlEmailCreator
41
41
 
42
42
  html_email = doc.to_html
43
43
 
44
- inlined_html_email = InlineStyle.process(html_email)
45
-
46
- # Then remove escaping of Aweber templates
47
- @processed_html_email = if @settings.built_in_extensions.include?("aweber")
48
- inlined_html_email.gsub(/%7B/, '{').gsub(/%7D/, '}').gsub(/!global%20/, '!global ')
49
- else
50
- inlined_html_email
51
- end
44
+ # process and then call callback
45
+ inlined_html_email = InlineStyle.process(html_email)
46
+ HtmlEmailCreator::callbacks(@settings).html_created(inlined_html_email)
52
47
  end
53
48
 
54
49
  def to_plain_text
@@ -43,7 +43,7 @@ module HtmlEmailCreator
43
43
 
44
44
  def extension_data
45
45
  return @extension_data if @extension_data
46
- extensions = HtmlEmailCreator::Extensions.new(self)
46
+ extensions = HtmlEmailCreator::Extensions.new
47
47
  built_in_data = extensions.built_in(built_in_extensions)
48
48
  # use built in data for creating custom data
49
49
  custom_data = extensions.custom(built_in_data, custom_extensions)
@@ -53,7 +53,7 @@ module HtmlEmailCreator
53
53
  def built_in_extensions
54
54
  (@config["extensions"] || {})["built_in"] || []
55
55
  end
56
-
56
+
57
57
  private
58
58
 
59
59
  def custom_extensions
@@ -1,3 +1,3 @@
1
1
  module HtmlEmailCreator
2
- VERSION = "1.0.10" unless defined?(::HtmlEmailCreator::VERSION)
2
+ VERSION = "1.0.13" unless defined?(::HtmlEmailCreator::VERSION)
3
3
  end
@@ -11,6 +11,7 @@ require_all 'html_email_creator/formatters'
11
11
 
12
12
  module HtmlEmailCreator
13
13
 
14
+ autoload :Callbacks, "html_email_creator/callbacks"
14
15
  autoload :Email, "html_email_creator/email"
15
16
  autoload :EmailCreator, "html_email_creator/email_creator"
16
17
  autoload :EmailVersion, "html_email_creator/email_version"
@@ -32,6 +33,10 @@ module HtmlEmailCreator
32
33
  Dir.pwd
33
34
  end
34
35
 
36
+ def callbacks(current_settings = settings)
37
+ Callbacks.new(current_settings)
38
+ end
39
+
35
40
  def settings
36
41
  @settings ||= read_settings(current_dir)
37
42
  end
@@ -0,0 +1,11 @@
1
+ layouts_path: "Layouts"
2
+ output_path: "Output"
3
+ emails_path: "Emails"
4
+ includes_path: "Includes"
5
+ cdn_url: "http://cdn.example.com"
6
+ extensions:
7
+ built_in:
8
+ - "mailchimp"
9
+ custom:
10
+ foobar: "Hi, this is foobar."
11
+ great: "Hi, this is **great**"
@@ -0,0 +1,7 @@
1
+ config:
2
+ output: "first"
3
+ layout: "simple.liquid"
4
+ data:
5
+ first_content: "{% include 'Emails/foobar.md' %}"
6
+ second_content: "{% include 'Emails/barfoo.md' %}"
7
+ third_content: "{{ 'foo/bar' | photo: 'alt text' }}"
@@ -0,0 +1 @@
1
+ A bore is a person who opens his {{ what }} and puts his feats in it.
File without changes
@@ -0,0 +1,7 @@
1
+ This is simple template.
2
+
3
+ {{ first_content }}
4
+
5
+ {{ second_content }}
6
+
7
+ {{ third_content }}
File without changes
@@ -90,22 +90,31 @@ eos
90
90
  end
91
91
  end
92
92
 
93
- describe "aweber escaping" do
94
- it "should not escape aweber markup if using aweber extension" do
95
- html = <<-eos
96
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
97
- <html>
98
- <body>
99
- <p>{!date dayname+7}</p>
100
- </body>
101
- </html>
102
- eos
103
-
93
+ describe "Character unescaping" do
94
+ html = <<-eos
95
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
96
+ <html>
97
+ <body>
98
+ <p>%7B!date dayname+7%7D *%7CFNAME%7C*</p>
99
+ </body>
100
+ </html>
101
+ eos
102
+
103
+ it "should unescape Aweber markup if using Aweber extension" do
104
104
  run_in_fixture_dir("with_config") do
105
105
  processor = HtmlEmailCreator::Processor.new(html)
106
- processor.to_html.should include("<p>{!date dayname+7}</p>")
107
- processor.to_plain_text.should include("{!date dayname+7}")
106
+ processor.to_html.should include("<p>{!date dayname+7} *%7CFNAME%7C*</p>")
107
+ processor.to_plain_text.should include("{!date dayname+7} *%7CFNAME%7C*")
108
+ end
109
+ end
110
+
111
+ it "should unescape Mailchimp markup if using Mailchimp extension" do
112
+ run_in_fixture_dir("with_mailchimp_config") do
113
+ processor = HtmlEmailCreator::Processor.new(html)
114
+ processor.to_html.should include("<p>%7B!date dayname+7%7D *|FNAME|*</p>")
115
+ processor.to_plain_text.should include("%7B!date dayname+7%7D *|FNAME|*")
108
116
  end
109
117
  end
118
+
110
119
  end
111
120
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 10
9
- version: 1.0.10
8
+ - 13
9
+ version: 1.0.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - Pekka Mattila
@@ -137,6 +137,7 @@ files:
137
137
  - bin/html_email_creator
138
138
  - html_email_creator.gemspec
139
139
  - lib/html_email_creator.rb
140
+ - lib/html_email_creator/callbacks.rb
140
141
  - lib/html_email_creator/email.rb
141
142
  - lib/html_email_creator/email_creator.rb
142
143
  - lib/html_email_creator/email_version.rb
@@ -175,6 +176,14 @@ files:
175
176
  - spec/fixtures/with_config/Layouts/.keep
176
177
  - spec/fixtures/with_config/Layouts/simple.liquid
177
178
  - spec/fixtures/with_config/Output/.keep
179
+ - spec/fixtures/with_mailchimp_config/.html_config.yaml
180
+ - spec/fixtures/with_mailchimp_config/Emails/first_email.yaml
181
+ - spec/fixtures/with_mailchimp_config/Includes/Emails/barfoo.md
182
+ - spec/fixtures/with_mailchimp_config/Includes/Emails/foobar.md
183
+ - spec/fixtures/with_mailchimp_config/Includes/Quotes/henry_ford.txt
184
+ - spec/fixtures/with_mailchimp_config/Layouts/.keep
185
+ - spec/fixtures/with_mailchimp_config/Layouts/simple.liquid
186
+ - spec/fixtures/with_mailchimp_config/Output/.keep
178
187
  - spec/html_email_creator/email_creator_spec.rb
179
188
  - spec/html_email_creator/email_spec.rb
180
189
  - spec/html_email_creator/formatter_spec.rb
@@ -238,6 +247,14 @@ test_files:
238
247
  - spec/fixtures/with_config/Layouts/.keep
239
248
  - spec/fixtures/with_config/Layouts/simple.liquid
240
249
  - spec/fixtures/with_config/Output/.keep
250
+ - spec/fixtures/with_mailchimp_config/.html_config.yaml
251
+ - spec/fixtures/with_mailchimp_config/Emails/first_email.yaml
252
+ - spec/fixtures/with_mailchimp_config/Includes/Emails/barfoo.md
253
+ - spec/fixtures/with_mailchimp_config/Includes/Emails/foobar.md
254
+ - spec/fixtures/with_mailchimp_config/Includes/Quotes/henry_ford.txt
255
+ - spec/fixtures/with_mailchimp_config/Layouts/.keep
256
+ - spec/fixtures/with_mailchimp_config/Layouts/simple.liquid
257
+ - spec/fixtures/with_mailchimp_config/Output/.keep
241
258
  - spec/html_email_creator/email_creator_spec.rb
242
259
  - spec/html_email_creator/email_spec.rb
243
260
  - spec/html_email_creator/formatter_spec.rb