from_json/from_json.rs
1//! Read a token spec from `tokens.json` (relative to the working directory) and write CSS to
2//! `tokens.css`. Run with `cargo run --example from_json`.
3//!
4//! Uses `std::fs` directly for brevity; production code in this crate goes through
5//! [`tangible::io::FileOps`] so it can be tested without touching disk.
6
7// Examples illustrate library usage, not internal conventions — bypass the FileOps boundary.
8#![allow(clippy::disallowed_methods)]
9
10use std::error::Error;
11use std::fs;
12
13use tangible::{Renderer, Spec};
14
15fn main() -> Result<(), Box<dyn Error>> {
16 let json = fs::read_to_string("tokens.json")?;
17 let spec: Spec = serde_json::from_str(&json)?;
18 let manifest = Renderer::new().render(&spec)?;
19 fs::write("tokens.css", manifest.to_string())?;
20 println!("Wrote tokens.css ({} bytes)", manifest.as_str().len());
21 Ok(())
22}