bootstrap-email 1.1.5 → 1.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: 49b2f67b9148d550ac5694fc59d9d279e942a51dbcb5505cb32bfa0c5a84dade
4
- data.tar.gz: 4f470a2edd130fdb054fa6dc9a32f70ab03e2bbb479afd2bfe354d33e32735ff
3
+ metadata.gz: c82d69b4546e02daeeff5fc09df8e91c3c372f6da42e39fd96b438bd0776a7c3
4
+ data.tar.gz: 8cc3f250c82b779ddb99ae0d9618523b716d8110e0cbd3b639a71255158c181d
5
5
  SHA512:
6
- metadata.gz: cd6942d8716f6f6876bf71821ecb53f4a192edff297087815638ce1eb7855efb26efe1f43852730f8b8f864a7d5a8e2301819d2ac078129e309db3bdf14c6f75
7
- data.tar.gz: 7419c2b2fa545037cf327689dfe9def42065edcc6c1b566ee2bcf7e9a3299c580aa2c3b3512172905b52597d0353cc554bb28457e3558c7fd5330ed2b1ec3e4a
6
+ metadata.gz: 7154cdcef0287e4fbcb37f117f5c73ae4dbf15b11a28b287b13b082d1ac05b63d5010b664a230cf907e7eafb8c27901db5e584db8a65fa7eb7ea1101cf42c6a1
7
+ data.tar.gz: bc5f07bdcb6ffca350685b5b39114d121ed27e33d4e18b24ce624143a4bd29f7210e405958634e1b86bc0ae6acdd5b70c259b5a77c805a3085d345a392f412c0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.5
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.load_options(options)
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 << BootstrapEmail.config.sass_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
- attr_writer :sass_email_location, # path to main sass file
6
- :sass_head_location, # path to head sass file
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 sass_location_for(type:)
22
- ivar = instance_variable_get("@sass_#{type.sub('bootstrap-', '')}_location")
23
- return ivar if ivar
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
- @sass_load_paths ||= []
33
- paths_array.concat(@sass_load_paths)
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
- @sass_cache_location ||= begin
38
- if defined?(::Rails) && ::Rails.root
39
- ::Rails.root.join('tmp', 'cache', 'bootstrap-email', '.sass-cache')
40
- elsif File.writable?(Dir.pwd)
41
- File.join(Dir.pwd, '.sass-cache', 'bootstrap-email')
42
- else
43
- File.join(Dir.tmpdir, '.sass-cache', 'bootstrap-email')
44
- end
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
- defined?(@sass_log_enabled) ? @sass_log_enabled : true
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
@@ -10,8 +10,8 @@ module BootstrapEmail
10
10
  @cached_templates = {}
11
11
  end
12
12
 
13
- def self.build(doc)
14
- new(doc).build
13
+ def self.build(doc, *args)
14
+ new(doc).build(*args)
15
15
  end
16
16
 
17
17
  private
@@ -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
@@ -7,11 +7,19 @@ module BootstrapEmail
7
7
  CLOSE_BRACKETS = CGI.escape('}}').freeze
8
8
 
9
9
  def self.replace(html)
10
- regex = /((href|src)=("|').*?)((#{Regexp.quote(OPEN_BRACKETS)}).*?(#{Regexp.quote(CLOSE_BRACKETS)}))(.*?("|'))/
10
+ regex = /((href|src)=("|'))(.*?((#{Regexp.quote(OPEN_BRACKETS)}).*?(#{Regexp.quote(CLOSE_BRACKETS)})).*?)("|')/
11
11
  return unless regex.match?(html)
12
12
 
13
+ inner_regex = /((#{Regexp.quote(OPEN_BRACKETS)}).*?(#{Regexp.quote(CLOSE_BRACKETS)}))/
14
+
13
15
  html.gsub!(regex) do |_match|
14
- "#{Regexp.last_match(1)}#{CGI.unescape(Regexp.last_match(4))}#{Regexp.last_match(7)}"
16
+ start_text = Regexp.last_match(1)
17
+ middle_text = Regexp.last_match(4)
18
+ end_text = Regexp.last_match(8)
19
+ middle_text.gsub!(inner_regex) do |match|
20
+ CGI.unescape(match)
21
+ end
22
+ "#{start_text}#{middle_text}#{end_text}"
15
23
  end
16
24
  end
17
25
  end
@@ -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, :config_file, :checksum
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.config_file = load_config
18
+ self.sass_config = load_sass_config
18
19
  self.checksum = checksum_files
19
- end
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,20 +28,23 @@ module BootstrapEmail
30
28
 
31
29
  private
32
30
 
33
- def load_config
34
- path = BootstrapEmail.config.sass_location_for(type: type)
35
- replace_config(File.read(path)) if path
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(config_file)
39
- config_file.gsub("//= @import #{type};", "@import '#{file_path}';")
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 = config_file.nil? ? [] : [Digest::SHA1.hexdigest(config_file)]
44
- Dir.glob('../../core/**/*.scss', base: __dir__).each do |path|
45
- checksums << Digest::SHA1.file(File.expand_path(path, __dir__)).hexdigest
41
+ checksums = sass_config.nil? ? [] : [Digest::SHA1.hexdigest(sass_config)]
42
+ config.sass_load_paths.each do |load_path|
43
+ Dir.glob(File.join(load_path, '**', '*.scss'), base: __dir__).each do |path|
44
+ checksums << Digest::SHA1.file(File.expand_path(path, __dir__)).hexdigest
45
+ end
46
46
  end
47
+
47
48
  Digest::SHA1.hexdigest(checksums.join)
48
49
  end
49
50
 
@@ -52,11 +53,11 @@ module BootstrapEmail
52
53
  end
53
54
 
54
55
  def compile_and_cache_scss(cache_path)
55
- file = config_file || File.read("#{file_path}.scss")
56
+ file = sass_config || File.read("#{file_path}.scss")
56
57
  css = SassC::Engine.new(file, style: style).render
57
58
  FileUtils.mkdir_p("#{cache_dir}/#{checksum}") unless File.directory?("#{cache_dir}/#{checksum}")
58
59
  File.write(cache_path, css)
59
- puts "New css file cached for #{type}" if BootstrapEmail.config.sass_log_enabled?
60
+ puts "New css file cached for #{type}" if config.sass_log_enabled?
60
61
  end
61
62
  end
62
63
  end
@@ -2,28 +2,20 @@
2
2
 
3
3
  module BootstrapEmail
4
4
  class << self
5
- def config
6
- @config ||= BootstrapEmail::Config.new
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
- @config ||= BootstrapEmail::Config.new
18
- yield @config
10
+ yield static_config
19
11
  end
20
12
 
21
13
  def reset_config!
22
- remove_instance_variable :@config if defined?(@config)
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.config.sass_cache_location)
18
+ FileUtils.rm_rf(BootstrapEmail::Config.new.sass_cache_location)
27
19
  end
28
20
  end
29
21
  end
@@ -16,6 +16,7 @@ rescue LoadError; end
16
16
 
17
17
  require 'action_mailer' if defined?(Rails)
18
18
 
19
+ require_relative 'bootstrap-email/config_store'
19
20
  require_relative 'bootstrap-email/config'
20
21
  require_relative 'bootstrap-email/setup'
21
22
  require_relative 'bootstrap-email/erb'
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.1.5
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stuart Yamartino
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-30 00:00:00.000000000 Z
11
+ date: 2022-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: htmlbeautifier
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.1'
69
- description:
69
+ description:
70
70
  email: stu@stuyam.com
71
71
  executables:
72
72
  - bootstrap-email
@@ -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
@@ -157,7 +158,7 @@ licenses:
157
158
  - MIT
158
159
  metadata:
159
160
  rubygems_mfa_required: 'true'
160
- post_install_message:
161
+ post_install_message:
161
162
  rdoc_options: []
162
163
  require_paths:
163
164
  - lib
@@ -172,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
173
  - !ruby/object:Gem::Version
173
174
  version: '0'
174
175
  requirements: []
175
- rubygems_version: 3.0.3.1
176
- signing_key:
176
+ rubygems_version: 3.2.3
177
+ signing_key:
177
178
  specification_version: 4
178
179
  summary: 'Bootstrap 5+ stylesheet, compiler, and inliner for responsive and consistent
179
180
  emails with the Bootstrap syntax you know and love. Support: command line, ruby,