summaryrefslogtreecommitdiff
path: root/src/library/structure
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-03-11 12:59:55 +0100
committerLaurenz <laurmaedje@gmail.com>2022-03-11 23:36:06 +0100
commit5ac7eb3860ebd3247f6486c227e816894cb8fd91 (patch)
treea29a868c681c7de39f15f2d9d3f031db1861b90a /src/library/structure
parent5ce2a006b6d45d29be15e4562ae3ab4fc1b8e97c (diff)
Rename template to content
Diffstat (limited to 'src/library/structure')
-rw-r--r--src/library/structure/heading.rs20
-rw-r--r--src/library/structure/list.rs46
-rw-r--r--src/library/structure/table.rs16
3 files changed, 41 insertions, 41 deletions
diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs
index a67f4f24..f5565f3c 100644
--- a/src/library/structure/heading.rs
+++ b/src/library/structure/heading.rs
@@ -8,7 +8,7 @@ pub struct HeadingNode {
/// default style, this controls the text size of the heading.
pub level: usize,
/// The heading's contents.
- pub body: Template,
+ pub body: Content,
}
#[class]
@@ -35,8 +35,8 @@ impl HeadingNode {
/// Whether the heading is block-level.
pub const BLOCK: Leveled<bool> = Leveled::Value(true);
- fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> {
- Ok(Template::show(Self {
+ fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
+ Ok(Content::show(Self {
body: args.expect("body")?,
level: args.named("level")?.unwrap_or(1),
}))
@@ -44,7 +44,7 @@ impl HeadingNode {
}
impl Show for HeadingNode {
- fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> {
+ fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> {
macro_rules! resolve {
($key:expr) => {
styles.get_cloned($key).resolve(ctx, self.level)?
@@ -55,7 +55,7 @@ impl Show for HeadingNode {
let mut body = styles
.show(self, ctx, [
Value::Int(self.level as i64),
- Value::Template(self.body.clone()),
+ Value::Content(self.body.clone()),
])?
.unwrap_or_else(|| self.body.clone());
@@ -90,22 +90,22 @@ impl Show for HeadingNode {
let above = resolve!(Self::ABOVE);
if !above.is_zero() {
- seq.push(Template::Vertical(above.into()));
+ seq.push(Content::Vertical(above.into()));
}
seq.push(body);
let below = resolve!(Self::BELOW);
if !below.is_zero() {
- seq.push(Template::Vertical(below.into()));
+ seq.push(Content::Vertical(below.into()));
}
- let mut template = Template::sequence(seq).styled_with_map(map);
+ let mut content = Content::sequence(seq).styled_with_map(map);
if resolve!(Self::BLOCK) {
- template = Template::block(template);
+ content = Content::block(content);
}
- Ok(template)
+ Ok(content)
}
}
diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs
index 2c536e2a..2630d231 100644
--- a/src/library/structure/list.rs
+++ b/src/library/structure/list.rs
@@ -22,7 +22,7 @@ pub struct ListItem {
/// The number of the item.
pub number: Option<usize>,
/// The node that produces the item's body.
- pub body: Box<Template>,
+ pub body: Box<Content>,
}
/// An ordered list.
@@ -43,8 +43,8 @@ impl<const L: ListKind> ListNode<L> {
/// The extra padding below the list.
pub const BELOW: Length = Length::zero();
- fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> {
- Ok(Template::show(Self {
+ fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
+ Ok(Content::show(Self {
start: args.named("start")?.unwrap_or(0),
wide: args.named("wide")?.unwrap_or(false),
items: args
@@ -57,13 +57,13 @@ impl<const L: ListKind> ListNode<L> {
}
impl<const L: ListKind> Show for ListNode<L> {
- fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> {
- let template = if let Some(template) = styles.show(
+ fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> {
+ let content = if let Some(content) = styles.show(
self,
ctx,
- self.items.iter().map(|item| Value::Template((*item.body).clone())),
+ self.items.iter().map(|item| Value::Content((*item.body).clone())),
)? {
- template
+ content
} else {
let mut children = vec![];
let mut number = self.start;
@@ -91,7 +91,7 @@ impl<const L: ListKind> Show for ListNode<L> {
let indent = styles.get(Self::INDENT).resolve(em);
let body_indent = styles.get(Self::BODY_INDENT).resolve(em);
- Template::block(GridNode {
+ Content::block(GridNode {
tracks: Spec::with_x(vec![
TrackSizing::Linear(indent.into()),
TrackSizing::Auto,
@@ -106,17 +106,17 @@ impl<const L: ListKind> Show for ListNode<L> {
let mut seq = vec![];
let above = styles.get(Self::ABOVE);
if !above.is_zero() {
- seq.push(Template::Vertical(above.into()));
+ seq.push(Content::Vertical(above.into()));
}
- seq.push(template);
+ seq.push(content);
let below = styles.get(Self::BELOW);
if !below.is_zero() {
- seq.push(Template::Vertical(below.into()));
+ seq.push(Content::Vertical(below.into()));
}
- Ok(Template::sequence(seq))
+ Ok(Content::sequence(seq))
}
}
@@ -135,15 +135,15 @@ pub const UNORDERED: ListKind = 0;
/// Ordered list labelling style.
pub const ORDERED: ListKind = 1;
-/// Either a template or a closure mapping to a template.
+/// Either content or a closure mapping to content.
#[derive(Debug, Clone, PartialEq, Hash)]
pub enum Label {
/// The default labelling.
Default,
/// A pattern with prefix, numbering, lower / upper case and suffix.
Pattern(EcoString, Numbering, bool, EcoString),
- /// A bare template.
- Template(Template),
+ /// Bare content.
+ Content(Content),
/// A closure mapping from an item number to a value.
Func(Func, Span),
}
@@ -155,18 +155,18 @@ impl Label {
ctx: &mut Context,
kind: ListKind,
number: usize,
- ) -> TypResult<Template> {
+ ) -> TypResult<Content> {
Ok(match self {
Self::Default => match kind {
- UNORDERED => Template::Text('•'.into()),
- ORDERED | _ => Template::Text(format_eco!("{}.", number)),
+ UNORDERED => Content::Text('•'.into()),
+ ORDERED | _ => Content::Text(format_eco!("{}.", number)),
},
Self::Pattern(prefix, numbering, upper, suffix) => {
let fmt = numbering.apply(number);
let mid = if *upper { fmt.to_uppercase() } else { fmt.to_lowercase() };
- Template::Text(format_eco!("{}{}{}", prefix, mid, suffix))
+ Content::Text(format_eco!("{}{}{}", prefix, mid, suffix))
}
- Self::Template(template) => template.clone(),
+ Self::Content(content) => content.clone(),
Self::Func(func, span) => {
let args = Args::from_values(*span, [Value::Int(number as i64)]);
func.call(ctx, args)?.cast().at(*span)?
@@ -177,7 +177,7 @@ impl Label {
impl Cast<Spanned<Value>> for Label {
fn is(value: &Spanned<Value>) -> bool {
- matches!(&value.v, Value::Template(_) | Value::Func(_))
+ matches!(&value.v, Value::Content(_) | Value::Func(_))
}
fn cast(value: Spanned<Value>) -> StrResult<Self> {
@@ -200,9 +200,9 @@ impl Cast<Spanned<Value>> for Label {
let suffix = s.rest().into();
Ok(Self::Pattern(prefix.into(), numbering, upper, suffix))
}
- Value::Template(v) => Ok(Self::Template(v)),
+ Value::Content(v) => Ok(Self::Content(v)),
Value::Func(v) => Ok(Self::Func(v, value.span)),
- _ => Err("expected pattern, template or function")?,
+ _ => Err("expected pattern, content or function")?,
}
}
}
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs
index 555dcc44..42b62eac 100644
--- a/src/library/structure/table.rs
+++ b/src/library/structure/table.rs
@@ -9,7 +9,7 @@ pub struct TableNode {
/// Defines sizing of gutter rows and columns between content.
pub gutter: Spec<Vec<TrackSizing>>,
/// The nodes to be arranged in the table.
- pub children: Vec<Template>,
+ pub children: Vec<Content>,
}
#[class]
@@ -25,13 +25,13 @@ impl TableNode {
/// How much to pad the cells's content.
pub const PADDING: Linear = Length::pt(5.0).into();
- fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> {
+ fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let columns = args.named("columns")?.unwrap_or_default();
let rows = args.named("rows")?.unwrap_or_default();
let base_gutter: Vec<TrackSizing> = args.named("gutter")?.unwrap_or_default();
let column_gutter = args.named("column-gutter")?;
let row_gutter = args.named("row-gutter")?;
- Ok(Template::show(Self {
+ Ok(Content::show(Self {
tracks: Spec::new(columns, rows),
gutter: Spec::new(
column_gutter.unwrap_or_else(|| base_gutter.clone()),
@@ -53,13 +53,13 @@ impl TableNode {
}
impl Show for TableNode {
- fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> {
- if let Some(template) = styles.show(
+ fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> {
+ if let Some(content) = styles.show(
self,
ctx,
- self.children.iter().map(|child| Value::Template(child.clone())),
+ self.children.iter().map(|child| Value::Content(child.clone())),
)? {
- return Ok(template);
+ return Ok(content);
}
let primary = styles.get(Self::PRIMARY);
@@ -91,7 +91,7 @@ impl Show for TableNode {
})
.collect();
- Ok(Template::block(GridNode {
+ Ok(Content::block(GridNode {
tracks: self.tracks.clone(),
gutter: self.gutter.clone(),
children,