Skip to content

Commit c3174ba

Browse files
committed
Save file as JSON representation of root layer
Also added dependency on serde_json. Snippet of what the file looks like ```json { "nodes":{}, "root": { "blend_mode":"Normal","cache":"","cache_dirty":true, "data":{"Folder":{"layer_ids":[0,1],"layers":[...], "visible":true }, "version":0} ```
1 parent f0209f0 commit c3174ba

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/document/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ log = "0.4"
1313

1414
kurbo = {version="0.8", features = ["serde"]}
1515
serde = { version = "1.0", features = ["derive"] }
16+
serde_json = { version = "1.0" }
1617
glam = { version = "0.16", features = ["serde"] }

core/document/src/document.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ impl Document {
6565

6666
// Returns string that represents the full document (not just svg)
6767
pub fn serialize_document(&mut self) -> String {
68-
// Manually constructing JSON. Should switch to serde_json
69-
format!("{{\"version\": 0, \"svg\": \"{}\"}}", self.render_root())
68+
let doc = serde_json::json!({
69+
"version": 0,
70+
"root": self.root,
71+
"nodes": {}
72+
});
73+
doc.to_string()
7074
}
7175

7276
/// Checks whether each layer under `path` intersects with the provided `quad` and adds all intersection layers as paths to `intersections`.

0 commit comments

Comments
 (0)