Looking to incorporate sass into a Ruby script but want to compile only when necessary. The typical method for compiling involves using the following code:
require "sass"
Sass::Engine.new(File.read(scss), options).render
By utilizing appropriate hash values for options
, we can achieve this. However, my goal is to trigger compilation only if the main scss
file or any of its imported partials have been updated.
The key aspect here is leveraging sass caching within the options
. Caching stores update information about files in a specific directory. I believe that after executing up to:
engine = Sass::Engine.new(File.read(scss), options)
there should be some data available in the engine
object that indicates whether the main scss
file or any partials have been modified. Only under these conditions should we proceed with:
engine.render
for the actual compilation process. How can I effectively detect file updates based on the information provided by the sass cache?