bootstrap-email 1.1.7 → 1.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/VERSION +1 -1
- data/lib/bootstrap-email/compiler.rb +5 -5
- data/lib/bootstrap-email/config.rb +36 -23
- data/lib/bootstrap-email/config_store.rb +31 -0
- data/lib/bootstrap-email/converters/base.rb +2 -2
- data/lib/bootstrap-email/converters/head_style.rb +3 -2
- data/lib/bootstrap-email/sass_cache.rb +16 -18
- data/lib/bootstrap-email/setup.rb +5 -13
- data/lib/bootstrap-email.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c82d69b4546e02daeeff5fc09df8e91c3c372f6da42e39fd96b438bd0776a7c3
|
4
|
+
data.tar.gz: 8cc3f250c82b779ddb99ae0d9618523b716d8110e0cbd3b639a71255158c181d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7154cdcef0287e4fbcb37f117f5c73ae4dbf15b11a28b287b13b082d1ac05b63d5010b664a230cf907e7eafb8c27901db5e584db8a65fa7eb7ea1101cf42c6a1
|
7
|
+
data.tar.gz: bc5f07bdcb6ffca350685b5b39114d121ed27e33d4e18b24ce624143a4bd29f7210e405958634e1b86bc0ae6acdd5b70c259b5a77c805a3085d345a392f412c0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module BootstrapEmail
|
4
4
|
class Compiler
|
5
|
-
attr_accessor :type, :doc, :premailer
|
5
|
+
attr_accessor :type, :config, :doc, :premailer
|
6
6
|
|
7
7
|
def initialize(input, type: :string, options: {})
|
8
|
-
BootstrapEmail.
|
8
|
+
self.config = BootstrapEmail::Config.new(options)
|
9
9
|
self.type = type
|
10
10
|
case type
|
11
11
|
when :rails
|
@@ -41,11 +41,11 @@ module BootstrapEmail
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def sass_load_paths
|
44
|
-
SassC.load_paths <<
|
44
|
+
SassC.load_paths << config.sass_load_paths
|
45
45
|
end
|
46
46
|
|
47
47
|
def build_premailer_doc(html)
|
48
|
-
css_string = BootstrapEmail::SassCache.compile('bootstrap-email', style: :expanded)
|
48
|
+
css_string = BootstrapEmail::SassCache.compile('bootstrap-email', config, style: :expanded)
|
49
49
|
self.premailer = Premailer.new(
|
50
50
|
html,
|
51
51
|
with_html_string: true,
|
@@ -86,7 +86,7 @@ module BootstrapEmail
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def configure_html!
|
89
|
-
BootstrapEmail::Converter::HeadStyle.build(doc)
|
89
|
+
BootstrapEmail::Converter::HeadStyle.build(doc, config)
|
90
90
|
BootstrapEmail::Converter::AddMissingMetaTags.build(doc)
|
91
91
|
BootstrapEmail::Converter::VersionComment.build(doc)
|
92
92
|
end
|
@@ -2,51 +2,64 @@
|
|
2
2
|
|
3
3
|
module BootstrapEmail
|
4
4
|
class Config
|
5
|
-
|
6
|
-
|
7
|
-
:sass_load_paths, # array of directories for loading sass imports
|
8
|
-
:sass_cache_location, # path to tmp folder for sass cache
|
9
|
-
:sass_log_enabled # turn on or off sass log when caching new sass
|
10
|
-
|
11
|
-
def load_options(options)
|
5
|
+
def initialize(options = {})
|
6
|
+
@config_store = BootstrapEmail::ConfigStore.new(options)
|
12
7
|
file = File.expand_path('bootstrap-email.config.rb', Dir.pwd)
|
13
8
|
if options[:config_path]
|
14
9
|
require_relative options[:config_path]
|
15
10
|
elsif File.exist?(file)
|
16
11
|
require_relative file
|
17
12
|
end
|
18
|
-
options.each { |name, value| instance_variable_set("@#{name}", value) }
|
19
13
|
end
|
20
14
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
15
|
+
def sass_string_for(type:)
|
16
|
+
# look for custom sass string
|
17
|
+
sub_type = type.sub('bootstrap-', '')
|
18
|
+
string = config_for_option("sass_#{sub_type}_string")
|
19
|
+
return string unless string.nil?
|
20
|
+
|
21
|
+
# look for custom sass path
|
22
|
+
path = config_for_option("sass_#{sub_type}_location")
|
23
|
+
return File.read(path) unless path.nil?
|
24
24
|
|
25
|
+
# look up and return others if found in default locations
|
25
26
|
lookup_locations = ["#{type}.scss", "app/assets/stylesheets/#{type}.scss"]
|
26
27
|
locations = lookup_locations.map { |location| File.expand_path(location, Dir.pwd) }.select { |location| File.exist?(location) }
|
27
|
-
locations.first if locations.any?
|
28
|
+
File.read(locations.first) if locations.any?
|
28
29
|
end
|
29
30
|
|
30
31
|
def sass_load_paths
|
31
32
|
paths_array = [SassCache::SASS_DIR]
|
32
|
-
|
33
|
-
paths_array.concat(
|
33
|
+
custom_load_paths = config_for_option(:sass_load_paths) || []
|
34
|
+
paths_array.concat(custom_load_paths)
|
34
35
|
end
|
35
36
|
|
36
37
|
def sass_cache_location
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
option = config_for_option(:sass_cache_location)
|
39
|
+
return option unless option.nil?
|
40
|
+
|
41
|
+
if defined?(::Rails) && ::Rails.root
|
42
|
+
::Rails.root.join('tmp', 'cache', 'bootstrap-email', '.sass-cache')
|
43
|
+
elsif File.writable?(Dir.pwd)
|
44
|
+
File.join(Dir.pwd, '.sass-cache', 'bootstrap-email')
|
45
|
+
else
|
46
|
+
File.join(Dir.tmpdir, '.sass-cache', 'bootstrap-email')
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
50
|
def sass_log_enabled?
|
49
|
-
|
51
|
+
option = config_for_option(:sass_log_enabled)
|
52
|
+
option.nil? ? true : option
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def config_for_option(option)
|
58
|
+
if @config_store.did_set?(option)
|
59
|
+
@config_store.public_send(option)
|
60
|
+
else
|
61
|
+
BootstrapEmail.static_config.public_send(option)
|
62
|
+
end
|
50
63
|
end
|
51
64
|
end
|
52
65
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BootstrapEmail
|
4
|
+
class ConfigStore
|
5
|
+
OPTIONS = [
|
6
|
+
:sass_email_location, # path to main sass file
|
7
|
+
:sass_head_location, # path to head sass file
|
8
|
+
:sass_email_string, # main sass file passed in as a string
|
9
|
+
:sass_head_string, # head sass file passed in as a string
|
10
|
+
:sass_load_paths, # array of directories for loading sass imports
|
11
|
+
:sass_cache_location, # path to tmp folder for sass cache
|
12
|
+
:sass_log_enabled # turn on or off sass log when caching new sass
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
attr_reader(*OPTIONS)
|
16
|
+
|
17
|
+
OPTIONS.each do |option|
|
18
|
+
define_method("#{option}=") do |value|
|
19
|
+
instance_variable_set("@#{option}", value)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(options = [])
|
24
|
+
options.each { |name, value| instance_variable_set("@#{name}", value) if OPTIONS.include?(name) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def did_set?(option)
|
28
|
+
instance_variable_defined?("@#{option}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -3,7 +3,8 @@
|
|
3
3
|
module BootstrapEmail
|
4
4
|
module Converter
|
5
5
|
class HeadStyle < Base
|
6
|
-
def build
|
6
|
+
def build(config)
|
7
|
+
@config = config
|
7
8
|
doc.at_css('head').add_child(bootstrap_email_head)
|
8
9
|
end
|
9
10
|
|
@@ -18,7 +19,7 @@ module BootstrapEmail
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def purged_css_from_head
|
21
|
-
default, custom = BootstrapEmail::SassCache.compile('bootstrap-head').split('/*! allow_purge_after */')
|
22
|
+
default, custom = BootstrapEmail::SassCache.compile('bootstrap-head', @config).split('/*! allow_purge_after */')
|
22
23
|
# get each CSS declaration
|
23
24
|
custom.scan(/\w*\.[\w\-]*[\s\S\n]+?(?=})}{1}/).each do |group|
|
24
25
|
# get the first class for each comma separated CSS declaration
|
@@ -4,22 +4,20 @@ module BootstrapEmail
|
|
4
4
|
class SassCache
|
5
5
|
SASS_DIR = File.expand_path('../../core', __dir__)
|
6
6
|
|
7
|
-
def self.compile(type, style: :compressed)
|
8
|
-
new(type, style).compile
|
7
|
+
def self.compile(type, config, style: :compressed)
|
8
|
+
new(type, config, style).compile
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_accessor :type, :style, :file_path, :
|
11
|
+
attr_accessor :type, :config, :style, :file_path, :sass_config, :checksum, :cache_dir
|
12
12
|
|
13
|
-
def initialize(type, style)
|
13
|
+
def initialize(type, config, style)
|
14
14
|
self.type = type
|
15
|
+
self.config = config
|
15
16
|
self.style = style
|
16
17
|
self.file_path = "#{SASS_DIR}/#{type}"
|
17
|
-
self.
|
18
|
+
self.sass_config = load_sass_config
|
18
19
|
self.checksum = checksum_files
|
19
|
-
|
20
|
-
|
21
|
-
def cache_dir
|
22
|
-
BootstrapEmail.config.sass_cache_location
|
20
|
+
self.cache_dir = config.sass_cache_location
|
23
21
|
end
|
24
22
|
|
25
23
|
def compile
|
@@ -30,18 +28,18 @@ module BootstrapEmail
|
|
30
28
|
|
31
29
|
private
|
32
30
|
|
33
|
-
def
|
34
|
-
|
35
|
-
replace_config(
|
31
|
+
def load_sass_config
|
32
|
+
sass_string = config.sass_string_for(type: type)
|
33
|
+
replace_config(sass_string) if sass_string
|
36
34
|
end
|
37
35
|
|
38
|
-
def replace_config(
|
39
|
-
|
36
|
+
def replace_config(sass_config)
|
37
|
+
sass_config.gsub("//= @import #{type};", "@import '#{file_path}';")
|
40
38
|
end
|
41
39
|
|
42
40
|
def checksum_files
|
43
|
-
checksums =
|
44
|
-
|
41
|
+
checksums = sass_config.nil? ? [] : [Digest::SHA1.hexdigest(sass_config)]
|
42
|
+
config.sass_load_paths.each do |load_path|
|
45
43
|
Dir.glob(File.join(load_path, '**', '*.scss'), base: __dir__).each do |path|
|
46
44
|
checksums << Digest::SHA1.file(File.expand_path(path, __dir__)).hexdigest
|
47
45
|
end
|
@@ -55,11 +53,11 @@ module BootstrapEmail
|
|
55
53
|
end
|
56
54
|
|
57
55
|
def compile_and_cache_scss(cache_path)
|
58
|
-
file =
|
56
|
+
file = sass_config || File.read("#{file_path}.scss")
|
59
57
|
css = SassC::Engine.new(file, style: style).render
|
60
58
|
FileUtils.mkdir_p("#{cache_dir}/#{checksum}") unless File.directory?("#{cache_dir}/#{checksum}")
|
61
59
|
File.write(cache_path, css)
|
62
|
-
puts "New css file cached for #{type}" if
|
60
|
+
puts "New css file cached for #{type}" if config.sass_log_enabled?
|
63
61
|
end
|
64
62
|
end
|
65
63
|
end
|
@@ -2,28 +2,20 @@
|
|
2
2
|
|
3
3
|
module BootstrapEmail
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
@
|
7
|
-
@config
|
8
|
-
end
|
9
|
-
|
10
|
-
def load_options(options)
|
11
|
-
@config ||= BootstrapEmail::Config.new
|
12
|
-
@config.load_options(options)
|
13
|
-
@config
|
5
|
+
def static_config
|
6
|
+
@static_config ||= BootstrapEmail::ConfigStore.new
|
14
7
|
end
|
15
8
|
|
16
9
|
def configure
|
17
|
-
|
18
|
-
yield @config
|
10
|
+
yield static_config
|
19
11
|
end
|
20
12
|
|
21
13
|
def reset_config!
|
22
|
-
remove_instance_variable :@
|
14
|
+
remove_instance_variable :@static_config if defined?(@static_config)
|
23
15
|
end
|
24
16
|
|
25
17
|
def clear_sass_cache!
|
26
|
-
FileUtils.rm_rf(BootstrapEmail.
|
18
|
+
FileUtils.rm_rf(BootstrapEmail::Config.new.sass_cache_location)
|
27
19
|
end
|
28
20
|
end
|
29
21
|
end
|
data/lib/bootstrap-email.rb
CHANGED
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.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stuart Yamartino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlbeautifier
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/bootstrap-email/bootstrap_email_cli.rb
|
120
120
|
- lib/bootstrap-email/compiler.rb
|
121
121
|
- lib/bootstrap-email/config.rb
|
122
|
+
- lib/bootstrap-email/config_store.rb
|
122
123
|
- lib/bootstrap-email/converters/add_missing_meta_tags.rb
|
123
124
|
- lib/bootstrap-email/converters/alert.rb
|
124
125
|
- lib/bootstrap-email/converters/align.rb
|