bootstrap-email 1.0.0.alpha1 → 1.0.0.alpha3
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/core/bootstrap-email.scss +2 -0
- data/core/bootstrap-head.scss +1 -1
- data/core/scss/_selectors_for_utils.scss +24 -0
- data/core/scss/_utilities.scss +24 -4
- data/core/scss/components/_grid.scss +12 -9
- data/core/scss/components/_stack.scss +33 -0
- data/core/scss/utilities/_sizing.scss +21 -2
- data/core/scss/utilities/_typography.scss +4 -10
- data/core/scss/utilities/_valign.scss +5 -0
- data/core/templates/body.html +9 -0
- data/core/templates/{container.html.erb → container.html} +4 -4
- data/core/templates/div.html +3 -0
- data/core/templates/table-left.html +9 -0
- data/core/templates/table-to-tbody.html +5 -0
- data/core/templates/table-to-tr.html +7 -0
- data/core/templates/table.html +9 -0
- data/core/templates/td.html +3 -0
- data/core/templates/tr.html +5 -0
- data/lib/{bootstrap_email.rb → bootstrap-email.rb} +6 -1
- data/lib/bootstrap-email/bootstrap_email_cli.rb +9 -9
- data/lib/bootstrap-email/compiler.rb +49 -65
- data/lib/bootstrap-email/config.rb +50 -0
- data/lib/bootstrap-email/{components → converters}/alert.rb +1 -1
- data/lib/bootstrap-email/converters/align.rb +22 -0
- data/lib/bootstrap-email/{components → converters}/badge.rb +1 -1
- data/lib/bootstrap-email/converters/base.rb +62 -0
- data/lib/bootstrap-email/converters/block.rb +13 -0
- data/lib/bootstrap-email/converters/body.rb +10 -0
- data/lib/bootstrap-email/{components → converters}/button.rb +1 -1
- data/lib/bootstrap-email/{components → converters}/card.rb +3 -3
- data/lib/bootstrap-email/{components → converters}/color.rb +1 -1
- data/lib/bootstrap-email/{components → converters}/container.rb +1 -1
- data/lib/bootstrap-email/converters/force_encoding.rb +16 -0
- data/lib/bootstrap-email/converters/grid.rb +14 -0
- data/lib/bootstrap-email/converters/head_style.rb +33 -0
- data/lib/bootstrap-email/{components → converters}/hr.rb +2 -2
- data/lib/bootstrap-email/{components → converters}/margin.rb +1 -1
- data/lib/bootstrap-email/{components → converters}/padding.rb +1 -1
- data/lib/bootstrap-email/converters/paragraph.rb +13 -0
- data/lib/bootstrap-email/converters/preview_text.rb +18 -0
- data/lib/bootstrap-email/{components → converters}/spacer.rb +1 -1
- data/lib/bootstrap-email/{components → converters}/spacing.rb +5 -6
- data/lib/bootstrap-email/converters/stack.rb +30 -0
- data/lib/bootstrap-email/{components → converters}/table.rb +1 -1
- data/lib/bootstrap-email/converters/version_comment.rb +15 -0
- data/lib/bootstrap-email/erb.rb +9 -0
- data/lib/bootstrap-email/rails/action_mailer.rb +7 -2
- data/lib/bootstrap-email/sass_cache.rb +43 -26
- data/lib/bootstrap-email/setup.rb +27 -0
- metadata +44 -31
- data/core/templates/body.html.erb +0 -9
- data/core/templates/col.html.erb +0 -3
- data/core/templates/div.html.erb +0 -3
- data/core/templates/row.html.erb +0 -7
- data/core/templates/table-left.html.erb +0 -9
- data/core/templates/table.html.erb +0 -9
- data/lib/bootstrap-email/components/align.rb +0 -21
- data/lib/bootstrap-email/components/base.rb +0 -26
- data/lib/bootstrap-email/components/body.rb +0 -22
- data/lib/bootstrap-email/components/grid.rb +0 -14
- data/lib/bootstrap-email/components/paragraph.rb +0 -24
@@ -2,9 +2,14 @@ ActiveSupport.on_load(:action_mailer, {yield: true}) do |action_mailer|
|
|
2
2
|
action_mailer.class_eval do # To support Rails less than 6
|
3
3
|
# sit in the middle and compile the html
|
4
4
|
def bootstrap_mail(*args, &block)
|
5
|
-
|
6
|
-
|
5
|
+
mail_message = mail(*args, &block)
|
6
|
+
# if you override the #mail method in you ApplicationMailer you may intentionally return something other than a mail message
|
7
|
+
if mail_message
|
8
|
+
bootstrap = BootstrapEmail::Compiler.new(mail_message, type: :rails)
|
9
|
+
bootstrap.perform_full_compile
|
10
|
+
end
|
7
11
|
end
|
12
|
+
alias bootstrap_email bootstrap_mail
|
8
13
|
alias make_bootstrap_mail bootstrap_mail
|
9
14
|
end
|
10
15
|
end
|
@@ -1,38 +1,45 @@
|
|
1
1
|
module BootstrapEmail
|
2
2
|
class SassCache
|
3
|
-
CACHE_DIR = File.expand_path('../../.sass-cache', __dir__)
|
4
3
|
SASS_DIR = File.expand_path('../../core', __dir__)
|
5
4
|
|
6
|
-
def self.compile(
|
7
|
-
|
8
|
-
|
5
|
+
def self.compile(type, style: :compressed)
|
6
|
+
new(type, style).compile
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
locations = lookup_locations.select { |location| File.exist?(File.expand_path(location, Dir.pwd)) }
|
9
|
+
attr_accessor :type, :style, :file_path, :config_file, :checksum
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
def initialize(type, style)
|
12
|
+
self.type = type
|
13
|
+
self.style = style
|
14
|
+
self.file_path = "#{SASS_DIR}/#{type}"
|
15
|
+
self.config_file = load_config
|
16
|
+
self.checksum = checksum_files
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
Dir.mkdir("#{CACHE_DIR}/#{check}") unless File.directory?("#{CACHE_DIR}/#{check}")
|
29
|
-
File.write(cache_path, css)
|
30
|
-
puts "New css file cached for #{name}"
|
31
|
-
end
|
19
|
+
def cache_dir
|
20
|
+
BootstrapEmail.config.sass_cache_location
|
21
|
+
end
|
22
|
+
|
23
|
+
def compile
|
24
|
+
cache_path = "#{cache_dir}/#{checksum}/#{type}.css"
|
25
|
+
unless cached?(cache_path)
|
26
|
+
compile_and_cache_scss(cache_path)
|
32
27
|
end
|
28
|
+
File.read(cache_path)
|
33
29
|
end
|
34
30
|
|
35
|
-
|
31
|
+
private
|
32
|
+
|
33
|
+
def load_config
|
34
|
+
path = BootstrapEmail.config.sass_location_for(type: type)
|
35
|
+
replace_config(File.read(path)) if path
|
36
|
+
end
|
37
|
+
|
38
|
+
def replace_config(config_file)
|
39
|
+
config_file.gsub("//= @import #{type};", "@import '#{file_path}';")
|
40
|
+
end
|
41
|
+
|
42
|
+
def checksum_files
|
36
43
|
checksums = config_file.nil? ? [] : [Digest::SHA1.hexdigest(config_file)]
|
37
44
|
Dir.glob('../../core/**/*.scss', base: __dir__).each do |path|
|
38
45
|
checksums << Digest::SHA1.file(File.expand_path(path, __dir__)).hexdigest
|
@@ -40,8 +47,18 @@ module BootstrapEmail
|
|
40
47
|
Digest::SHA1.hexdigest(checksums.join)
|
41
48
|
end
|
42
49
|
|
43
|
-
def
|
50
|
+
def cached?(cache_path)
|
44
51
|
File.file?(cache_path)
|
45
52
|
end
|
53
|
+
|
54
|
+
def compile_and_cache_scss(cache_path)
|
55
|
+
file = config_file || File.read("#{file_path}.scss")
|
56
|
+
css = SassC::Engine.new(file, style: style).render
|
57
|
+
FileUtils.mkdir_p("#{cache_dir}/#{checksum}") unless File.directory?("#{cache_dir}/#{checksum}")
|
58
|
+
File.write(cache_path, css)
|
59
|
+
if BootstrapEmail.config.sass_log_enabled?
|
60
|
+
puts "New css file cached for #{type}"
|
61
|
+
end
|
62
|
+
end
|
46
63
|
end
|
47
64
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module BootstrapEmail
|
2
|
+
class << self
|
3
|
+
def config
|
4
|
+
@config ||= BootstrapEmail::Config.new
|
5
|
+
@config
|
6
|
+
end
|
7
|
+
|
8
|
+
def load_options(options)
|
9
|
+
@config ||= BootstrapEmail::Config.new
|
10
|
+
@config.load_options(options)
|
11
|
+
@config
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure(&proc)
|
15
|
+
@config ||= BootstrapEmail::Config.new
|
16
|
+
yield @config
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset_config!
|
20
|
+
remove_instance_variable :@config if defined?(@config)
|
21
|
+
end
|
22
|
+
|
23
|
+
def clear_sass_cache!
|
24
|
+
FileUtils.rm_rf(BootstrapEmail.config.sass_cache_location)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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: 1.0.0.
|
4
|
+
version: 1.0.0.alpha3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Yamartino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -30,28 +30,28 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.7'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.7'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sassc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2.
|
47
|
+
version: '2.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2.
|
54
|
+
version: '2.0'
|
55
55
|
description:
|
56
56
|
email: stu@stuyam.com
|
57
57
|
executables:
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- core/scss/components/_hr.scss
|
81
81
|
- core/scss/components/_image.scss
|
82
82
|
- core/scss/components/_preview.scss
|
83
|
+
- core/scss/components/_stack.scss
|
83
84
|
- core/scss/components/_table.scss
|
84
85
|
- core/scss/utilities/_background.scss
|
85
86
|
- core/scss/utilities/_border-radius.scss
|
@@ -90,38 +91,50 @@ files:
|
|
90
91
|
- core/scss/utilities/_spacing.scss
|
91
92
|
- core/scss/utilities/_text-decoration.scss
|
92
93
|
- core/scss/utilities/_typography.scss
|
93
|
-
- core/
|
94
|
-
- core/templates/
|
95
|
-
- core/templates/container.html
|
96
|
-
- core/templates/div.html
|
97
|
-
- core/templates/
|
98
|
-
- core/templates/table-
|
99
|
-
- core/templates/table.html
|
94
|
+
- core/scss/utilities/_valign.scss
|
95
|
+
- core/templates/body.html
|
96
|
+
- core/templates/container.html
|
97
|
+
- core/templates/div.html
|
98
|
+
- core/templates/table-left.html
|
99
|
+
- core/templates/table-to-tbody.html
|
100
|
+
- core/templates/table-to-tr.html
|
101
|
+
- core/templates/table.html
|
102
|
+
- core/templates/td.html
|
103
|
+
- core/templates/tr.html
|
104
|
+
- lib/bootstrap-email.rb
|
100
105
|
- lib/bootstrap-email/bootstrap_email_cli.rb
|
101
106
|
- lib/bootstrap-email/compiler.rb
|
102
|
-
- lib/bootstrap-email/
|
103
|
-
- lib/bootstrap-email/
|
104
|
-
- lib/bootstrap-email/
|
105
|
-
- lib/bootstrap-email/
|
106
|
-
- lib/bootstrap-email/
|
107
|
-
- lib/bootstrap-email/
|
108
|
-
- lib/bootstrap-email/
|
109
|
-
- lib/bootstrap-email/
|
110
|
-
- lib/bootstrap-email/
|
111
|
-
- lib/bootstrap-email/
|
112
|
-
- lib/bootstrap-email/
|
113
|
-
- lib/bootstrap-email/
|
114
|
-
- lib/bootstrap-email/
|
115
|
-
- lib/bootstrap-email/
|
116
|
-
- lib/bootstrap-email/
|
117
|
-
- lib/bootstrap-email/
|
118
|
-
- lib/bootstrap-email/
|
107
|
+
- lib/bootstrap-email/config.rb
|
108
|
+
- lib/bootstrap-email/converters/alert.rb
|
109
|
+
- lib/bootstrap-email/converters/align.rb
|
110
|
+
- lib/bootstrap-email/converters/badge.rb
|
111
|
+
- lib/bootstrap-email/converters/base.rb
|
112
|
+
- lib/bootstrap-email/converters/block.rb
|
113
|
+
- lib/bootstrap-email/converters/body.rb
|
114
|
+
- lib/bootstrap-email/converters/button.rb
|
115
|
+
- lib/bootstrap-email/converters/card.rb
|
116
|
+
- lib/bootstrap-email/converters/color.rb
|
117
|
+
- lib/bootstrap-email/converters/container.rb
|
118
|
+
- lib/bootstrap-email/converters/force_encoding.rb
|
119
|
+
- lib/bootstrap-email/converters/grid.rb
|
120
|
+
- lib/bootstrap-email/converters/head_style.rb
|
121
|
+
- lib/bootstrap-email/converters/hr.rb
|
122
|
+
- lib/bootstrap-email/converters/margin.rb
|
123
|
+
- lib/bootstrap-email/converters/padding.rb
|
124
|
+
- lib/bootstrap-email/converters/paragraph.rb
|
125
|
+
- lib/bootstrap-email/converters/preview_text.rb
|
126
|
+
- lib/bootstrap-email/converters/spacer.rb
|
127
|
+
- lib/bootstrap-email/converters/spacing.rb
|
128
|
+
- lib/bootstrap-email/converters/stack.rb
|
129
|
+
- lib/bootstrap-email/converters/table.rb
|
130
|
+
- lib/bootstrap-email/converters/version_comment.rb
|
131
|
+
- lib/bootstrap-email/erb.rb
|
119
132
|
- lib/bootstrap-email/initialize.rb
|
120
133
|
- lib/bootstrap-email/rails/action_mailer.rb
|
121
134
|
- lib/bootstrap-email/rails/engine.rb
|
122
135
|
- lib/bootstrap-email/sass_cache.rb
|
136
|
+
- lib/bootstrap-email/setup.rb
|
123
137
|
- lib/bootstrap-email/version.rb
|
124
|
-
- lib/bootstrap_email.rb
|
125
138
|
homepage: https://bootstrapemail.com
|
126
139
|
licenses:
|
127
140
|
- MIT
|
data/core/templates/col.html.erb
DELETED
data/core/templates/div.html.erb
DELETED
data/core/templates/row.html.erb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module BootstrapEmail
|
2
|
-
module Component
|
3
|
-
class Align < Base
|
4
|
-
def build
|
5
|
-
['left', 'center', 'right'].each do |type|
|
6
|
-
each_node(".align-#{type}") do |node|
|
7
|
-
align_helper(node, type)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def align_helper(node, type)
|
13
|
-
if node.name != 'table'
|
14
|
-
node['class'] = node['class'].sub("align-#{type}", '')
|
15
|
-
node = node.replace(template('table', classes: "align-#{type}", contents: node.to_html))[0]
|
16
|
-
end
|
17
|
-
node['align'] = type
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module BootstrapEmail
|
2
|
-
module Component
|
3
|
-
class Base
|
4
|
-
attr_reader :doc
|
5
|
-
def initialize(doc)
|
6
|
-
@doc = doc
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.build(doc)
|
10
|
-
new(doc).build
|
11
|
-
end
|
12
|
-
|
13
|
-
def template(file, locals_hash = {})
|
14
|
-
locals_hash[:classes] = locals_hash[:classes].split.join(' ') if locals_hash[:classes]
|
15
|
-
namespace = OpenStruct.new(locals_hash)
|
16
|
-
template_html = File.read(File.expand_path("../../../core/templates/#{file}.html.erb", __dir__))
|
17
|
-
ERB.new(template_html).result(namespace.instance_eval { binding })
|
18
|
-
end
|
19
|
-
|
20
|
-
def each_node(css_lookup, &blk)
|
21
|
-
# sort by youngest child and traverse backwards up the tree
|
22
|
-
doc.css(css_lookup).sort_by { |n| n.ancestors.size }.reverse!.each(&blk)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module BootstrapEmail
|
2
|
-
module Component
|
3
|
-
class Body < Base
|
4
|
-
def build
|
5
|
-
each_node('body') do |node|
|
6
|
-
node.replace('<body>' + preview_text.to_s + template('body', classes: "#{node['class']} body", contents: node.inner_html) + '</body>')
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def preview_text
|
11
|
-
preview_node = doc.at_css('preview')
|
12
|
-
return if preview_node.nil?
|
13
|
-
|
14
|
-
# apply spacing after the text max of 100 characters so it doesn't show body text
|
15
|
-
preview_node.content += ' ' * [(100 - preview_node.content.length.to_i), 0].max
|
16
|
-
node = template('div', classes: 'preview', contents: preview_node.content)
|
17
|
-
preview_node.remove
|
18
|
-
node
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module BootstrapEmail
|
2
|
-
module Component
|
3
|
-
class Grid < Base
|
4
|
-
def build
|
5
|
-
each_node('.row') do |node|
|
6
|
-
node.replace(template('row', classes: node['class'], contents: node.inner_html))
|
7
|
-
end
|
8
|
-
each_node('*[class*=col]') do |node|
|
9
|
-
node.replace(template('col', classes: node['class'], contents: node.inner_html))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module BootstrapEmail
|
2
|
-
module Component
|
3
|
-
class Paragraph < Base
|
4
|
-
def build
|
5
|
-
each_node('p') do |node|
|
6
|
-
next if margin?(node) || space_y?(node)
|
7
|
-
|
8
|
-
node['class'] ||= ''
|
9
|
-
node['class'] += 'mb-4'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def margin?(node)
|
16
|
-
node['class'].to_s.match?(/m[tby]{1}-(lg-)?\d+/)
|
17
|
-
end
|
18
|
-
|
19
|
-
def space_y?(node)
|
20
|
-
node.parent['class'].to_s.match?(/space-y-(lg-)?\d+/)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|