Class: Canvas::DartSass
- Inherits:
-
Object
- Object
- Canvas::DartSass
- Defined in:
- lib/canvas/dartsass.rb
Overview
Compiles SCSS with dart-sass via the sass-embedded Ruby API.
It is compatible with SassC::Engine as much as we were using it, but 100% compatability is not a goal.
We use the in-process API rather than shelling out to the dartsass
executable: the CLI resolves Gem.bin_path("sass-embedded", "sass"), which
is ambiguous (and noisy on stderr) whenever another bundled gem — e.g. the
legacy sass gem — also ships a sass executable. The API has no such
dependency on executable resolution and avoids a subprocess per render.
Constant Summary collapse
- Error =
Class.new(StandardError)
Instance Method Summary collapse
-
#initialize(css, config) ⇒ DartSass
constructor
A new instance of DartSass.
- #render ⇒ Object
Constructor Details
#initialize(css, config) ⇒ DartSass
Returns a new instance of DartSass.
19 20 21 22 |
# File 'lib/canvas/dartsass.rb', line 19 def initialize(css, config) @css = css @config = config end |
Instance Method Details
#render ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/canvas/dartsass.rb', line 24 def render Sass.compile_string( @css, load_paths: Array(@config[:load_paths]), style: @config[:style] || :expanded ).css rescue Sass::CompileError => e # detailed_message keeps the formatted dart-sass error (source snippet and # line:column) the CLI used to print to stderr; highlight: false strips ANSI. raise Error.new(e.(highlight: false)) end |