bootstrap-email 0.3.1 → 0.3.2
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/VERSION +1 -1
- data/lib/bootstrap-email.rb +20 -20
- data/lib/bootstrap-email/action_mailer.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62c6c5c793d4efc84cce78d500c28962ed044dcb2ee4cfa340ac366711d78275
|
4
|
+
data.tar.gz: 591fe6126e0b9029ba96fa8d6c00ce99dae098a08a590d70f8aed75893dde83d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '048c1bb0ed2d42b612e4fa052e6dc8f0872cb474aaa06664b6b3030f07f226d572213de43b459575ffca84d5ec75936c0341fbaa59a6fa47e9b490a47ff6c750'
|
7
|
+
data.tar.gz: 14ab4f2fe71b5966e39dedc63283851b9d9650f7a2bbebe3cf2ac30e69e2ca59465101c4536935f1e77e08e285df70d1c94e9338bb1404dbce4545e40a3113c3
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/bootstrap-email.rb
CHANGED
@@ -8,13 +8,13 @@ require 'rails'
|
|
8
8
|
|
9
9
|
module BootstrapEmail
|
10
10
|
class Compiler
|
11
|
-
def initialize
|
11
|
+
def initialize(mail)
|
12
12
|
@mail = mail
|
13
13
|
@source = mail.html_part || mail
|
14
14
|
update_doc(@source.body.raw_source)
|
15
15
|
end
|
16
16
|
|
17
|
-
def update_doc
|
17
|
+
def update_doc(source)
|
18
18
|
@doc = Nokogiri::HTML(source)
|
19
19
|
end
|
20
20
|
|
@@ -63,21 +63,21 @@ module BootstrapEmail
|
|
63
63
|
engine = defined?(SassC::Engine).nil? ? Sass::Engine : SassC::Engine
|
64
64
|
html_string = <<-HEREDOC
|
65
65
|
<style type="text/css">
|
66
|
-
#{engine.new(File.open(File.expand_path('../core/head.scss', __dir__)).read,
|
66
|
+
#{engine.new(File.open(File.expand_path('../core/head.scss', __dir__)).read, syntax: :scss, style: :compressed, cache: false, read_cache: false).render}
|
67
67
|
</style>
|
68
68
|
HEREDOC
|
69
69
|
html_string
|
70
70
|
end
|
71
71
|
|
72
|
-
def template
|
72
|
+
def template(file, locals_hash = {})
|
73
73
|
namespace = OpenStruct.new(locals_hash)
|
74
74
|
template_html = File.open(File.expand_path("../core/templates/#{file}.html.erb", __dir__)).read
|
75
75
|
ERB.new(template_html).result(namespace.instance_eval { binding })
|
76
76
|
end
|
77
77
|
|
78
|
-
def each_node
|
78
|
+
def each_node(css_lookup, &blk)
|
79
79
|
# sort by youngest child and traverse backwards up the tree
|
80
|
-
@doc.css(css_lookup).sort_by{ |n| n.ancestors.size }.reverse!.each(&blk)
|
80
|
+
@doc.css(css_lookup).sort_by { |n| n.ancestors.size }.reverse!.each(&blk)
|
81
81
|
end
|
82
82
|
|
83
83
|
def button
|
@@ -110,7 +110,7 @@ module BootstrapEmail
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
-
def align_helper
|
113
|
+
def align_helper(node, klass, template)
|
114
114
|
if node.name != 'table' # if it is already on a table, set the proprieties on the current table
|
115
115
|
node['class'] = node['class'].sub(klass, '')
|
116
116
|
node.replace(template("align-#{template}", contents: node.to_html))
|
@@ -154,12 +154,12 @@ module BootstrapEmail
|
|
154
154
|
|
155
155
|
def padding
|
156
156
|
each_node('*[class*=p-], *[class*=pt-], *[class*=pr-], *[class*=pb-], *[class*=pl-], *[class*=px-], *[class*=py-]') do |node|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
157
|
+
next unless node.name != 'table' # if it is already on a table, set the padding on the table, else wrap the content in a table
|
158
|
+
|
159
|
+
padding_regex = /(p[trblxy]?-\d)/
|
160
|
+
classes = node['class'].scan(padding_regex).join(' ')
|
161
|
+
node['class'] = node['class'].gsub(padding_regex, '')
|
162
|
+
node.replace(template('table', classes: classes, contents: node.to_html))
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
@@ -213,13 +213,13 @@ module BootstrapEmail
|
|
213
213
|
|
214
214
|
def preview_text
|
215
215
|
preview_node = @doc.at_css('preview')
|
216
|
-
if preview_node.
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
216
|
+
return if preview_node.blank?
|
217
|
+
|
218
|
+
# apply spacing after the text max of 100 characters so it doesn't show body text
|
219
|
+
preview_node.content += ' ' * [(100 - preview_node.content.length.to_i), 0].max
|
220
|
+
node = template('div', classes: 'preview', contents: preview_node.content)
|
221
|
+
preview_node.remove
|
222
|
+
node
|
223
223
|
end
|
224
224
|
end
|
225
225
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class ActionMailer::Base
|
2
2
|
# sit in the middle and compile the html
|
3
|
-
def bootstrap_mail
|
3
|
+
def bootstrap_mail(*args)
|
4
4
|
bootstrap = BootstrapEmail::Compiler.new(mail(*args) { |format| format.html { render layout: 'layouts/bootstrap-mailer.html.erb' } })
|
5
5
|
bootstrap.perform_full_compile
|
6
6
|
end
|
7
7
|
|
8
|
-
def make_bootstrap_mail
|
8
|
+
def make_bootstrap_mail(*args, &block)
|
9
9
|
bootstrap = BootstrapEmail::Compiler.new(mail(*args, &block))
|
10
10
|
bootstrap.perform_full_compile
|
11
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstrap-email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Yamartino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionmailer
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3'
|
69
69
|
description:
|
70
|
-
email:
|
70
|
+
email: stu@stuyam.com
|
71
71
|
executables: []
|
72
72
|
extensions: []
|
73
73
|
extra_rdoc_files: []
|