sasso 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a89d43cae2462c899283a30eedf28a07811521af60786fff3bc0e98d03b52b62
4
- data.tar.gz: 30aef843e37e9fa3367a0d7237ceafade28c9c8abaee6af01481d1cc58e8d5fa
3
+ metadata.gz: 528ef999790af85bfa776bd1d0ccc46d9769a89f382b820146edf5b3751ae7f3
4
+ data.tar.gz: f451c06e65645007798c25774b7b7b1091b14ff469b1550826973e47ddeb090c
5
5
  SHA512:
6
- metadata.gz: ab4de39d13910cbfa5b8ffdce884f053ce6843f160951647228c4ad998056c86bedc576e2293f7e9bbc2fef1da9cc5f04431e84850a0620df0fa003a93eb2f82
7
- data.tar.gz: 234390250dd93325342a67fe173d79dc5e23c630334f3381112d49b230e5ae15850fa15634f434fa147d4087dfc262ad8d6aa67158bd1d9b5e1cd0759d38d390
6
+ metadata.gz: fbefa4b411714cf73f0afa5edb079b28b69f7b9f107c85b6d5e37157c9cb8a8fe9ec658f7064819c0c508723d0d7a8555a8f476d4265e0e4e94c1ae415236b44
7
+ data.tar.gz: 19b4659b99da7bc4ec2257d3b81bd6f4ce882abce4248e79fb1c74d5aa8a6df26c0c0e115b24f95d595960f35f2078eec1a292bb8553bef167d44d8aa2a23caf
data/CHANGELOG.md CHANGED
@@ -8,6 +8,20 @@ notes the exact core crate version it pins.
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [0.2.0] - 2026-06-14
12
+
13
+ Adopts core crate **v0.4.0**.
14
+
15
+ ### Added
16
+
17
+ - **Source map support.** `Sasso.compile_string(source, source_map: true)` (and
18
+ `Sasso.compile(path, source_map: true)`) returns a `Sasso::CompileResult` with
19
+ `#css` (the CSS String) and `#source_map` (the Source Map v3 as a parsed Hash:
20
+ `"version" => 3`, `"mappings"`, `"sources"`, …). Pass
21
+ `source_map_include_sources: true` to embed the full source text in the map's
22
+ `sourcesContent`. Without `source_map:` the methods still return a plain CSS
23
+ String (backwards compatible). The mappings are byte-identical to dart-sass.
24
+
11
25
  ## [0.1.2] - 2026-06-13
12
26
 
13
27
  Adopts core crate **v0.3.1**.
data/Cargo.lock CHANGED
@@ -239,14 +239,14 @@ dependencies = [
239
239
  "magnus",
240
240
  "rb-sys",
241
241
  "rb-sys-env",
242
- "sasso 0.3.1",
242
+ "sasso 0.4.0",
243
243
  ]
244
244
 
245
245
  [[package]]
246
246
  name = "sasso"
247
- version = "0.3.1"
247
+ version = "0.4.0"
248
248
  source = "registry+https://github.com/rust-lang/crates.io-index"
249
- checksum = "638b15699dc3af4dd6f9e2a75cddfb95217620264baba75f214f52f55daca8ef"
249
+ checksum = "aa9edae1ffa8368d44560b7519bbe27ff2a36c29b48b5b69421d1f490667607d"
250
250
 
251
251
  [[package]]
252
252
  name = "seq-macro"
data/ext/sasso/Cargo.toml CHANGED
@@ -29,7 +29,7 @@ rb-sys = "0.9"
29
29
  # The published core compiler, pinned exactly to the API surface this binding
30
30
  # targets. Renamed to `sasso_core` so this package can be named `sasso` (a
31
31
  # package may not depend on a crate of its own name without a rename).
32
- sasso_core = { package = "sasso", version = "=0.3.1" }
32
+ sasso_core = { package = "sasso", version = "=0.4.0" }
33
33
 
34
34
  [build-dependencies]
35
35
  rb-sys-env = "0.1"
data/ext/sasso/src/lib.rs CHANGED
@@ -64,10 +64,56 @@ fn native_compile(
64
64
  sasso::compile(&source, &opts).map_err(|e| compile_error(ruby, e.to_string()))
65
65
  }
66
66
 
67
+ /// Source-map variant: returns `[css, source_map_json]` (a Ruby Array via the
68
+ /// Rust tuple). `include_sources` populates the map's `sourcesContent`.
69
+ fn native_compile_with_map(
70
+ ruby: &Ruby,
71
+ source: String,
72
+ style: String,
73
+ syntax: String,
74
+ load_paths: RArray,
75
+ url: Option<String>,
76
+ unicode: bool,
77
+ include_sources: bool,
78
+ ) -> Result<(String, String), Error> {
79
+ let mut opts = sasso::Options::default()
80
+ .with_style(if style == "compressed" {
81
+ sasso::OutputStyle::Compressed
82
+ } else {
83
+ sasso::OutputStyle::Expanded
84
+ })
85
+ .with_syntax(match syntax.as_str() {
86
+ "sass" => sasso::Syntax::Sass,
87
+ "css" => sasso::Syntax::Css,
88
+ _ => sasso::Syntax::Scss,
89
+ })
90
+ .with_unicode(unicode)
91
+ .with_source_map_include_sources(include_sources);
92
+
93
+ if let Some(ref u) = url {
94
+ opts = opts.with_url(u);
95
+ }
96
+
97
+ let paths: Vec<PathBuf> = load_paths
98
+ .to_vec::<String>()?
99
+ .into_iter()
100
+ .map(PathBuf::from)
101
+ .collect();
102
+ let importer = sasso::FsImporter::new(paths.clone());
103
+ if !paths.is_empty() {
104
+ opts = opts.with_importer(&importer);
105
+ }
106
+
107
+ let result =
108
+ sasso::compile_with_source_map(&source, &opts).map_err(|e| compile_error(ruby, e.to_string()))?;
109
+ Ok((result.css, result.source_map.to_json()))
110
+ }
111
+
67
112
  #[magnus::init]
68
113
  fn init(ruby: &Ruby) -> Result<(), Error> {
69
114
  let module = ruby.define_module("Sasso")?;
70
115
  let native = module.define_module("Native")?;
71
116
  native.define_module_function("_compile", function!(native_compile, 6))?;
117
+ native.define_module_function("_compile_with_map", function!(native_compile_with_map, 7))?;
72
118
  Ok(())
73
119
  }
data/lib/sasso/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  module Sasso
4
4
  # The gem version floats INDEPENDENTLY of the core `sasso` crate version; the
5
5
  # native extension pins the crate exactly (ext/sasso/Cargo.toml: sasso = "=…").
6
- VERSION = "0.1.2"
6
+ VERSION = "0.2.0"
7
7
  end
data/lib/sasso.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "json"
3
4
  require_relative "sasso/version"
4
5
 
5
6
  module Sasso
@@ -10,6 +11,11 @@ module Sasso
10
11
  # diagnostic (the same text the `sasso` CLI prints) when a `url:` is given,
11
12
  # otherwise the legacy `Error: <msg> (line:col)` one-liner.
12
13
  class CompileError < Error; end
14
+
15
+ # Returned by `compile_string`/`compile` when `source_map: true`. `#css` is the
16
+ # CSS String (identical to the plain-String return); `#source_map` is the
17
+ # Source Map v3 as a parsed Hash (`"version" => 3`, `"mappings"`, `"sources"`, …).
18
+ CompileResult = Struct.new(:css, :source_map)
13
19
  end
14
20
 
15
21
  # Load the compiled native extension. Precompiled ("fat") gems place a copy per
@@ -41,13 +47,18 @@ module Sasso
41
47
  #
42
48
  # Raises Sasso::CompileError on a compile failure; ArgumentError on bad options.
43
49
  def compile_string(source, style: :expanded, syntax: :scss, indented: false,
44
- load_paths: [], url: nil, alert_ascii: false)
50
+ load_paths: [], url: nil, alert_ascii: false,
51
+ source_map: false, source_map_include_sources: false)
45
52
  syntax = :sass if indented
46
53
  validate!(style, STYLES, :style)
47
54
  validate!(syntax, SYNTAXES, :syntax)
48
55
  paths = Array(load_paths).map(&:to_s)
49
- Sasso::Native._compile(String(source), style.to_s, syntax.to_s,
50
- paths, url && url.to_s, !alert_ascii)
56
+ src = String(source)
57
+ return Sasso::Native._compile(src, style.to_s, syntax.to_s, paths, url && url.to_s, !alert_ascii) unless source_map
58
+
59
+ css, map_json = Sasso::Native._compile_with_map(src, style.to_s, syntax.to_s, paths,
60
+ url && url.to_s, !alert_ascii, source_map_include_sources)
61
+ CompileResult.new(css, JSON.parse(map_json))
51
62
  end
52
63
 
53
64
  # Compile the file at `path`. Syntax is inferred from the extension unless
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sasso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - momiji-rs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-13 00:00:00.000000000 Z
11
+ date: 2026-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys