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, style) ⇒ SassCache

Returns a new instance of SassCache.



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

def initialize(type, style)
  self.type = type
  self.style = style
  self.file_path = "#{SASS_DIR}/#{type}"
  self.config_file = load_config
  self.checksum = checksum_files
end

Instance Attribute Details

#checksumObject

Returns the value of attribute checksum.



9
10
11
# File 'lib/bootstrap-email/sass_cache.rb', line 9

def checksum
  @checksum
end

#config_fileObject

Returns the value of attribute config_file.



9
10
11
# File 'lib/bootstrap-email/sass_cache.rb', line 9

def config_file
  @config_file
end

#file_pathObject

Returns the value of attribute file_path.



9
10
11
# File 'lib/bootstrap-email/sass_cache.rb', line 9

def file_path
  @file_path
end

#styleObject

Returns the value of attribute style.



9
10
11
# File 'lib/bootstrap-email/sass_cache.rb', line 9

def style
  @style
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/bootstrap-email/sass_cache.rb', line 9

def type
  @type
end

Class Method Details

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



5
6
7
# File 'lib/bootstrap-email/sass_cache.rb', line 5

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

Instance Method Details

#cache_dirObject



19
20
21
# File 'lib/bootstrap-email/sass_cache.rb', line 19

def cache_dir
  BootstrapEmail.config.sass_cache_location
end

#compileObject



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

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