Class: BootstrapEmail::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/bootstrap-email/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
10
11
12
13
# File 'lib/bootstrap-email/config.rb', line 5

def initialize(options = {})
  @config_store = BootstrapEmail::ConfigStore.new(options)
  file = File.expand_path('bootstrap-email.config.rb', Dir.pwd)
  if options[:config_path]
    require_relative options[:config_path]
  elsif File.exist?(file)
    require_relative file
  end
end

Instance Method Details

#sass_cache_locationObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bootstrap-email/config.rb', line 37

def sass_cache_location
  option = config_for_option(:sass_cache_location)
  return option unless option.nil?

  if defined?(::Rails) && ::Rails.root
    ::Rails.root.join('tmp', 'cache', 'bootstrap-email', '.sass-cache')
  elsif File.writable?(Dir.pwd)
    File.join(Dir.pwd, '.sass-cache', 'bootstrap-email')
  else
    File.join(Dir.tmpdir, '.sass-cache', 'bootstrap-email')
  end
end

#sass_load_pathsObject



31
32
33
34
35
# File 'lib/bootstrap-email/config.rb', line 31

def sass_load_paths
  library_paths = [SassCache::SASS_DIR]
  user_paths = config_for_option(:sass_load_paths) || []
  library_paths + user_paths
end

#sass_log_enabled?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/bootstrap-email/config.rb', line 50

def sass_log_enabled?
  option = config_for_option(:sass_log_enabled)
  option.nil? ? true : option
end

#sass_string_for(type:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bootstrap-email/config.rb', line 15

def sass_string_for(type:)
  # look for custom sass string
  sub_type = type.sub('bootstrap-', '')
  string = config_for_option("sass_#{sub_type}_string")
  return string unless string.nil?

  # look for custom sass path
  path = config_for_option("sass_#{sub_type}_location")
  return File.read(path) unless path.nil?

  # look up and return others if found in default locations
  lookup_locations = ["#{type}.scss", "app/assets/stylesheets/#{type}.scss"]
  locations = lookup_locations.map { |location| File.expand_path(location, Dir.pwd) }.select { |location| File.exist?(location) }
  File.read(locations.first) if locations.any?
end