pub struct TokenFile {
pub name: String,
pub description: Option<String>,
pub extends: Option<String>,
pub extensions: Option<Value>,
pub tokens: BTreeMap<String, RawToken>,
}Expand description
A token file: a theme, a density overlay or any other layer.
Its tokens are keyed by their dotted path (surface.panel). At the
root, $extends names the theme this file builds on (every token not
given here comes from it), $description describes the file and
$extensions is kept as written.
Fields§
§name: String§description: Option<String>§extends: Option<String>§extensions: Option<Value>The root $extensions, kept as written.
tokens: BTreeMap<String, RawToken>Implementations§
Source§impl TokenFile
impl TokenFile
Sourcepub fn parse(name: &str, text: &str) -> Result<TokenFile, Error>
pub fn parse(name: &str, text: &str) -> Result<TokenFile, Error>
Reads a token file under the given name: JSON when its text
starts with {, YAML otherwise (the same tree, with comments).
Sourcepub fn parse_cached(
name: &str,
text: &str,
source: &Path,
cache: &Cache,
) -> (Result<TokenFile, Error>, Option<CacheError>)
pub fn parse_cached( name: &str, text: &str, source: &Path, cache: &Cache, ) -> (Result<TokenFile, Error>, Option<CacheError>)
TokenFile::parse for a file read from source, its YAML
compiled through a cache (crate::cache): on a hit the JSON the
YAML was compiled to is read; on a miss or a stale entry the YAML
is parsed (its problems are the error, and are not cached) and its
JSON kept. JSON files are read as they are. The second value is
the entry that could not be written: the file is read uncached.
Source§impl TokenFile
impl TokenFile
Sourcepub fn to_json(&self) -> Json
pub fn to_json(&self) -> Json
The file as DTCG JSON: $description, $extends and
$extensions at the root, then each token nested in groups by
its path, with its $type, $value, $description and
$extensions. TokenFile::parse reads it back as it was.
Sourcepub fn to_json_pretty(&self) -> String
pub fn to_json_pretty(&self) -> String
TokenFile::to_json, indented for people.
Source§impl TokenFile
impl TokenFile
Sourcepub fn stamp(&mut self)
pub fn stamp(&mut self)
Stamps the file with FormatStamp::CURRENT under
FORMAT_EXTENSION, keeping the rest of its root $extensions.
Source§impl TokenFile
impl TokenFile
Sourcepub fn upgrade(&mut self) -> Vec<Warning>
pub fn upgrade(&mut self) -> Vec<Warning>
Brings a file to the current contract: reads its stamp
(FormatStamp::read) and moves the tokens renamed since the
contract it was written for to their new names (RENAMED), the
aliases naming them too. What was read otherwise than written
comes back as warnings. The stamp itself is left as it was.
Source§impl TokenFile
impl TokenFile
Source§impl TokenFile
impl TokenFile
Sourcepub fn set_extension(&mut self, key: &str, value: Option<Json>)
pub fn set_extension(&mut self, key: &str, value: Option<Json>)
Sets (or, with None, removes) one entry of the root
$extensions, keeping the others.
Sourcepub fn counterpart_file(&self) -> Option<Result<TokenFile, Error>>
pub fn counterpart_file(&self) -> Option<Result<TokenFile, Error>>
The counterpart this file carries (COUNTERPART_EXTENSION),
under its name; None when it carries none, an error when the
entry cannot be read.
Sourcepub fn set_counterpart_file(&mut self, counterpart: Option<TokenFile>)
pub fn set_counterpart_file(&mut self, counterpart: Option<TokenFile>)
Makes this file carry counterpart (COUNTERPART_EXTENSION),
each naming the other (VARIANT_OF_EXTENSION); None removes
it.