Module: Sasso
- Defined in:
- lib/sasso.rb,
lib/sasso.rb,
lib/sasso/version.rb
Defined Under Namespace
Classes: CompileError, Error
Constant Summary collapse
- STYLES =
%i[expanded compressed].freeze
- SYNTAXES =
%i[scss sass css].freeze
- VERSION =
The gem version floats INDEPENDENTLY of the core ‘sasso` crate version; the native extension pins the crate exactly (ext/sasso/Cargo.toml: sasso = “=…”).
"0.1.0"
Class Method Summary collapse
-
.compile(path, **opts) ⇒ Object
Compile the file at ‘path`.
-
.compile_string(source, style: :expanded, syntax: :scss, indented: false, load_paths: [], url: nil, alert_ascii: false) ⇒ Object
Compile a SCSS/Sass source String to a CSS String.
Class Method Details
.compile(path, **opts) ⇒ Object
Compile the file at ‘path`. Syntax is inferred from the extension unless overridden; `url:` defaults to `path` so diagnostics get the dart-exact block.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/sasso.rb', line 55 def compile(path, **opts) src = File.read(path) inferred = case File.extname(path) when ".sass" then :sass when ".css" then :css else :scss end compile_string(src, syntax: inferred, url: path.to_s, **opts) end |
.compile_string(source, style: :expanded, syntax: :scss, indented: false, load_paths: [], url: nil, alert_ascii: false) ⇒ Object
Compile a SCSS/Sass source String to a CSS String.
style: :expanded (default) | :compressed
syntax: :scss (default) | :sass | :css
indented: true => shorthand for syntax: :sass
load_paths: dirs searched for @use/@forward/@import (built-in importer)
url: filename shown in diagnostics; ENABLES the dart-exact error block
alert_ascii: true => ASCII-only diagnostics (maps to the compiler's no-unicode)
Raises Sasso::CompileError on a compile failure; ArgumentError on bad options.
43 44 45 46 47 48 49 50 51 |
# File 'lib/sasso.rb', line 43 def compile_string(source, style: :expanded, syntax: :scss, indented: false, load_paths: [], url: nil, alert_ascii: false) syntax = :sass if indented validate!(style, STYLES, :style) validate!(syntax, SYNTAXES, :syntax) paths = Array(load_paths).map(&:to_s) Sasso::Native._compile(String(source), style.to_s, syntax.to_s, paths, url && url.to_s, !alert_ascii) end |