diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-08 13:02:41 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-08 14:35:33 +0100 |
| commit | d7a65fa26d131179d9d82226e5ee1b562084e48a (patch) | |
| tree | c21ab20e9fb851e14e1ebea3e14fc351b1fdbcc9 /src/model/content.rs | |
| parent | e5eab73374880077971f3f22acbdd3d302877128 (diff) | |
Rework style chain access
Diffstat (limited to 'src/model/content.rs')
| -rw-r--r-- | src/model/content.rs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/model/content.rs b/src/model/content.rs index 1b87aaea..05c5d430 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -7,7 +7,7 @@ use std::ops::{Add, AddAssign}; use comemo::Tracked; use ecow::{EcoString, EcoVec}; -use super::{node, Guard, Key, Property, Recipe, Style, StyleMap}; +use super::{node, Guard, Recipe, Style, StyleMap}; use crate::diag::{SourceResult, StrResult}; use crate::eval::{cast_from_value, Args, Cast, ParamInfo, Value, Vm}; use crate::syntax::Span; @@ -66,14 +66,9 @@ impl Content { self.with_field("label", label) } - /// Style this content with a single style property. - pub fn styled<K: Key>(self, key: K, value: K::Value) -> Self { - self.styled_with_entry(Style::Property(Property::new(key, value))) - } - /// Style this content with a style entry. - pub fn styled_with_entry(self, style: Style) -> Self { - self.styled_with_map(style.into()) + pub fn styled(self, style: impl Into<Style>) -> Self { + self.styled_with_map(style.into().into()) } /// Style this content with a full style map. @@ -90,7 +85,7 @@ impl Content { } /// Style this content with a recipe, eagerly applying it if possible. - pub fn styled_with_recipe( + pub fn apply_recipe( self, world: Tracked<dyn World>, recipe: Recipe, @@ -98,7 +93,7 @@ impl Content { if recipe.selector.is_none() { recipe.apply(world, self) } else { - Ok(self.styled_with_entry(Style::Recipe(recipe))) + Ok(self.styled(Style::Recipe(recipe))) } } @@ -135,6 +130,7 @@ impl Content { } } + /// Attach a field to the content. pub fn with_field( mut self, name: impl Into<EcoString>, @@ -154,6 +150,7 @@ impl Content { } } + /// Access a field on the content. pub fn field(&self, name: &str) -> Option<&Value> { static NONE: Value = Value::None; self.fields @@ -163,10 +160,6 @@ impl Content { .or_else(|| (name == "label").then(|| &NONE)) } - pub fn fields(&self) -> &[(EcoString, Value)] { - &self.fields - } - #[track_caller] pub fn cast_field<T: Cast>(&self, name: &str) -> T { match self.field(name) { @@ -175,6 +168,11 @@ impl Content { } } + /// List all fields on the content. + pub fn fields(&self) -> &[(EcoString, Value)] { + &self.fields + } + /// Whether the contained node is of type `T`. pub fn is<T>(&self) -> bool where |
