Dissolve utility category

This commit is contained in:
Laurenz 2023-02-16 14:43:38 +01:00
parent f60d344621
commit 67b4540397
13 changed files with 57 additions and 57 deletions

View File

@ -136,7 +136,6 @@ fn reference_page(resolver: &dyn Resolver) -> PageModel {
category_page(resolver, "calculate"), category_page(resolver, "calculate"),
category_page(resolver, "construct"), category_page(resolver, "construct"),
category_page(resolver, "data-loading"), category_page(resolver, "data-loading"),
category_page(resolver, "utility"),
]; ];
page page
} }

View File

@ -4,10 +4,8 @@ mod calc;
mod construct; mod construct;
mod data; mod data;
mod foundations; mod foundations;
mod utility;
pub use self::calc::*; pub use self::calc::*;
pub use self::construct::*; pub use self::construct::*;
pub use self::data::*; pub use self::data::*;
pub use self::foundations::*; pub use self::foundations::*;
pub use self::utility::*;

View File

@ -1,7 +1,7 @@
use std::str::FromStr; use std::str::FromStr;
use crate::compute::{Numbering, NumberingPattern};
use crate::layout::{BlockNode, GridNode, ParNode, Sizing, Spacing}; use crate::layout::{BlockNode, GridNode, ParNode, Sizing, Spacing};
use crate::meta::{Numbering, NumberingPattern};
use crate::prelude::*; use crate::prelude::*;
use crate::text::TextNode; use crate::text::TextNode;

View File

@ -42,6 +42,7 @@ fn global(math: Module, calc: Module) -> Module {
global.def_func::<text::StrikeNode>("strike"); global.def_func::<text::StrikeNode>("strike");
global.def_func::<text::OverlineNode>("overline"); global.def_func::<text::OverlineNode>("overline");
global.def_func::<text::RawNode>("raw"); global.def_func::<text::RawNode>("raw");
global.def_func::<text::LoremFunc>("lorem");
// Math. // Math.
global.define("math", math); global.define("math", math);
@ -86,6 +87,7 @@ fn global(math: Module, calc: Module) -> Module {
global.def_func::<meta::LinkNode>("link"); global.def_func::<meta::LinkNode>("link");
global.def_func::<meta::OutlineNode>("outline"); global.def_func::<meta::OutlineNode>("outline");
global.def_func::<meta::HeadingNode>("heading"); global.def_func::<meta::HeadingNode>("heading");
global.def_func::<meta::NumberingFunc>("numbering");
// Symbols. // Symbols.
global.define("sym", symbols::sym()); global.define("sym", symbols::sym());
@ -110,8 +112,6 @@ fn global(math: Module, calc: Module) -> Module {
global.def_func::<compute::CsvFunc>("csv"); global.def_func::<compute::CsvFunc>("csv");
global.def_func::<compute::JsonFunc>("json"); global.def_func::<compute::JsonFunc>("json");
global.def_func::<compute::XmlFunc>("xml"); global.def_func::<compute::XmlFunc>("xml");
global.def_func::<compute::LoremFunc>("lorem");
global.def_func::<compute::NumberingFunc>("numbering");
// Calc. // Calc.
global.define("calc", calc); global.define("calc", calc);

View File

@ -1,6 +1,6 @@
use typst::font::FontWeight; use typst::font::FontWeight;
use crate::compute::Numbering; use super::Numbering;
use crate::layout::{BlockNode, VNode}; use crate::layout::{BlockNode, VNode};
use crate::prelude::*; use crate::prelude::*;
use crate::text::{SpaceNode, TextNode, TextSize}; use crate::text::{SpaceNode, TextNode, TextSize};

View File

@ -3,11 +3,13 @@
mod document; mod document;
mod heading; mod heading;
mod link; mod link;
mod numbering;
mod outline; mod outline;
mod reference; mod reference;
pub use self::document::*; pub use self::document::*;
pub use self::heading::*; pub use self::heading::*;
pub use self::link::*; pub use self::link::*;
pub use self::numbering::*;
pub use self::outline::*; pub use self::outline::*;
pub use self::reference::*; pub use self::reference::*;

View File

@ -3,37 +3,6 @@ use std::str::FromStr;
use crate::prelude::*; use crate::prelude::*;
use crate::text::Case; use crate::text::Case;
/// # Blind Text
/// Create blind text.
///
/// This function yields a Latin-like _Lorem Ipsum_ blind text with the given
/// number of words. The sequence of words generated by the function is always
/// the same but randomly chosen. As usual for blind texts, it does not make any
/// sense. Use it as a placeholder to try layouts.
///
/// ## Example
/// ```example
/// = Blind Text
/// #lorem(30)
///
/// = More Blind Text
/// #lorem(15)
/// ```
///
/// ## Parameters
/// - words: `usize` (positional, required)
/// The length of the blind text in words.
///
/// - returns: string
///
/// ## Category
/// utility
#[func]
pub fn lorem(args: &mut Args) -> SourceResult<Value> {
let words: usize = args.expect("number of words")?;
Ok(Value::Str(lipsum::lipsum(words).into()))
}
/// # Numbering /// # Numbering
/// Apply a numbering to a sequence of numbers. /// Apply a numbering to a sequence of numbers.
/// ///
@ -93,7 +62,7 @@ pub fn lorem(args: &mut Args) -> SourceResult<Value> {
/// - returns: any /// - returns: any
/// ///
/// ## Category /// ## Category
/// utility /// meta
#[func] #[func]
pub fn numbering(vm: &Vm, args: &mut Args) -> SourceResult<Value> { pub fn numbering(vm: &Vm, args: &mut Args) -> SourceResult<Value> {
let numbering = args.expect::<Numbering>("pattern or function")?; let numbering = args.expect::<Numbering>("pattern or function")?;

View File

@ -345,3 +345,34 @@ pub fn smallcaps(args: &mut Args) -> SourceResult<Value> {
let body: Content = args.expect("content")?; let body: Content = args.expect("content")?;
Ok(Value::Content(body.styled(TextNode::SMALLCAPS, true))) Ok(Value::Content(body.styled(TextNode::SMALLCAPS, true)))
} }
/// # Blind Text
/// Create blind text.
///
/// This function yields a Latin-like _Lorem Ipsum_ blind text with the given
/// number of words. The sequence of words generated by the function is always
/// the same but randomly chosen. As usual for blind texts, it does not make any
/// sense. Use it as a placeholder to try layouts.
///
/// ## Example
/// ```example
/// = Blind Text
/// #lorem(30)
///
/// = More Blind Text
/// #lorem(15)
/// ```
///
/// ## Parameters
/// - words: `usize` (positional, required)
/// The length of the blind text in words.
///
/// - returns: string
///
/// ## Category
/// text
#[func]
pub fn lorem(args: &mut Args) -> SourceResult<Value> {
let words: usize = args.expect("number of words")?;
Ok(Value::Str(lipsum::lipsum(words).into()))
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

BIN
tests/ref/text/lorem.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -0,0 +1,18 @@
// Test integrated numbering patterns.
---
#for i in range(1, 9) {
numbering("*", i)
[ and ]
numbering("I.a", i, i)
[ for #i]
parbreak()
}
---
// Error: 17-18 number must be positive
#numbering("1", 0)
---
// Error: 17-19 number must be positive
#numbering("1", -1)

View File

@ -1,4 +1,4 @@
// Test integrated numbering patterns. // Test blind text.
--- ---
// Test basic call. // Test basic call.
@ -30,20 +30,3 @@
--- ---
// Error: 7-9 missing argument: number of words // Error: 7-9 missing argument: number of words
#lorem() #lorem()
---
#for i in range(1, 9) {
numbering("*", i)
[ and ]
numbering("I.a", i, i)
[ for #i]
parbreak()
}
---
// Error: 17-18 number must be positive
#numbering("1", 0)
---
// Error: 17-19 number must be positive
#numbering("1", -1)