Class: BootstrapEmail::SassCache

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

Constant Summary collapse

SASS_DIR =
File.expand_path('../../core', __dir__)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, config, style) ⇒ SassCache

Returns a new instance of SassCache.



13
14
15
16
17
18
19
20
21
# File 'lib/bootstrap-email/sass_cache.rb', line 13

def initialize(type, config, style)
  self.type = type
  self.config = config
  self.style = style
  self.file_path = "#{SASS_DIR}/#{type}"
  self.sass_config = load_sass_config
  self.checksum = checksum_files
  self.cache_dir = config.sass_cache_location
end

Instance Attribute Details

#cache_dirObject

Returns the value of attribute cache_dir.



11
12
13
# File 'lib/bootstrap-email/sass_cache.rb', line 11

def cache_dir
  @cache_dir
end

#checksumObject

Returns the value of attribute checksum.



11
12
13
# File 'lib/bootstrap-email/sass_cache.rb', line 11

def checksum
  @checksum
end

#configObject

Returns the value of attribute config.



11
12
13
# File 'lib/bootstrap-email/sass_cache.rb', line 11

def config
  @config
end

#file_pathObject

Returns the value of attribute file_path.



11
12
13
# File 'lib/bootstrap-email/sass_cache.rb', line 11

def file_path
  @file_path
end

#sass_configObject

Returns the value of attribute sass_config.



11
12
13
# File 'lib/bootstrap-email/sass_cache.rb', line 11

def sass_config
  @sass_config
end

#styleObject

Returns the value of attribute style.



11
12
13
# File 'lib/bootstrap-email/sass_cache.rb', line 11

def style
  @style
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/bootstrap-email/sass_cache.rb', line 11

def type
  @type
end

Class Method Details

.compile(type, config, style: :compressed) ⇒ Object



7
8
9
# File 'lib/bootstrap-email/sass_cache.rb', line 7

def self.compile(type, config, style: :compressed)
  new(type, config, style).compile
end

Instance Method Details

#compileObject



23
24
25
26
27
# File 'lib/bootstrap-email/sass_cache.rb', line 23

def compile
  cache_path = "#{cache_dir}/#{checksum}/#{type}.css"
  compile_and_cache_scss(cache_path) unless cached?(cache_path)
  File.read(cache_path)
end