Class: BootstrapEmail::SassCache
- Inherits:
-
Object
- Object
- BootstrapEmail::SassCache
- Defined in:
- lib/bootstrap-email/sass_cache.rb
Constant Summary collapse
- SASS_DIR =
File.('../../core', __dir__)
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
Returns the value of attribute cache_dir.
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#config ⇒ Object
Returns the value of attribute config.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#sass_config ⇒ Object
Returns the value of attribute sass_config.
-
#style ⇒ Object
Returns the value of attribute style.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(type, config, style) ⇒ SassCache
constructor
A new instance of SassCache.
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_dir ⇒ Object
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 |
#checksum ⇒ Object
Returns the value of attribute checksum.
11 12 13 |
# File 'lib/bootstrap-email/sass_cache.rb', line 11 def checksum @checksum end |
#config ⇒ Object
Returns the value of attribute config.
11 12 13 |
# File 'lib/bootstrap-email/sass_cache.rb', line 11 def config @config end |
#file_path ⇒ Object
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_config ⇒ Object
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 |
#style ⇒ Object
Returns the value of attribute style.
11 12 13 |
# File 'lib/bootstrap-email/sass_cache.rb', line 11 def style @style end |
#type ⇒ Object
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
#compile ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bootstrap-email/sass_cache.rb', line 23 def compile cache_path = "#{cache_dir}/#{checksum}/#{type}.css" lock_path = "#{cache_dir}/#{checksum}/#{type}.css.lock" FileUtils.mkdir_p("#{cache_dir}/#{checksum}") unless File.directory?("#{cache_dir}/#{checksum}") File.open(lock_path, File::RDWR | File::CREAT) do |lock_file| lock_file.flock(File::LOCK_EX) if cached?(cache_path) File.read(cache_path) else compile_and_cache_scss(cache_path) end end end |