Text

Lorem ipsum

Placeholder text for mock-ups, seed data and tests: Lorem ipsum words, sentences, paragraphs and titles, the same every time for a given seed.

Version 1.0.0 · 4 functions · 3 crates

#seed#mockups#testing#text

Functions

What use lorem.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use lorem_words, lorem_sentences from lorem (Quillo 0.6).

lorem_words(n: int) → str

n words of the classic text, starting "Lorem ipsum dolor sit amet", with its punctuation; up to 100,000.

lorem_sentences(n: int, seed: int) → str

n sentences of 6 to 16 words each, joined by spaces; seed 0 gives other ones each time, any other seed the same ones each time. Up to 10,000.

lorem_paragraphs(n: int, seed: int) → list

n paragraphs of 3 to 7 sentences, as a list; seed as for lorem_sentences. Up to 1,000.

lorem_title(seed: int) → str

A title of 2 to 5 words in Title Case, such as "Fugiat Dolore Exercitation"; seed as above.

Get it

$ quillo install lorem               # lorem.qwer into this folder$ quillo install lorem --example     # and its example, lorem.qwe

Or with curl:

$ curl -O https://quillolang.org/plugins/files/lorem.qwer$ curl -O https://quillolang.org/plugins/files/lorem.qwe

Then, in your program, all of it or only what you call:

main.qwe
use lorem.qweruse lorem_words, lorem_sentences from lorem      // Quillo 0.6: only these

It uses these crates, which cargo fetches the first time the plugin is built:

[dependencies]
lipsum = "0.9"rand_chacha = "0.3"rand = { version = "0.8", default-features = false }

Example

lorem.qwe
// Seed data for a blog mock-up: posts with titles and paragraphs, the same on every run.////   quillo run lorem.qwe      then open http://localhost:8080/postsuse "lorem.qwer"route GET /posts = range(1, 4) | map((i) => { id: i, title: lorem_title(i), excerpt: lorem_sentences(1, i), body: lorem_paragraphs(2, i) })route GET /words ? { n: int = 8 } = { text: lorem_words(n) }route GET /page = <html>    <body>        <h1>{lorem_title(7)}</h1>        {lorem_paragraphs(3, 7) | map((p) => <p>{p}</p>)}    </body></html>
$ quillo run lorem.qwe$ curl 'localhost:8080/words'$ curl 'localhost:8080/posts'

Source

lorem.qwer
//! Placeholder text for mock-ups, seed data and tests: Lorem ipsum words, sentences, paragraphs and titles, the same every time for a given seed.//! version: 1.0.0//!//! [dependencies]//! lipsum = "0.9"//! rand_chacha = "0.3"//! rand = { version = "0.8", default-features = false }use rand::SeedableRng;use rand_chacha::ChaCha8Rng;fn rng(seed: i64) -> ChaCha8Rng {    if seed == 0 {        let t = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(1, |d| d.as_nanos() as u64);        ChaCha8Rng::seed_from_u64(t)    } else {        ChaCha8Rng::seed_from_u64(seed as u64)    }}/// `n` words of the classic text, starting "Lorem ipsum dolor sit amet", with its punctuation; up to 100,000.pub fn lorem_words(n: i64) -> String {    lipsum::lipsum(n.clamp(0, 100_000) as usize)}/// `n` sentences of 6 to 16 words each, joined by spaces; `seed` 0 gives other ones each time, any other seed the same ones each time. Up to 10,000.pub fn lorem_sentences(n: i64, seed: i64) -> String {    use rand::Rng;    let mut r = rng(seed);    (0..n.clamp(0, 10_000))        .map(|_| {            let k = r.gen_range(6..=16);            let words = lipsum::lipsum_words_with_rng(&mut r, k);            let mut s: String = words.trim_end_matches(|c: char| !c.is_alphanumeric()).to_string();            if let Some(f) = s.get(..1) {                s = f.to_uppercase() + &s[1..];            }            s + "."        })        .collect::<Vec<_>>()        .join(" ")}/// `n` paragraphs of 3 to 7 sentences, as a list; `seed` as for `lorem_sentences`. Up to 1,000.pub fn lorem_paragraphs(n: i64, seed: i64) -> Vec<String> {    use rand::Rng;    let mut r = rng(seed);    (0..n.clamp(0, 1000)).map(|_| { let k = r.gen_range(3..=7); lorem_sentences(k, r.gen_range(1..i64::MAX)) }).collect()}/// A title of 2 to 5 words in Title Case, such as "Fugiat Dolore Exercitation"; `seed` as above.pub fn lorem_title(seed: i64) -> String {    use rand::Rng;    let mut r = rng(if seed == 0 { 0 } else { seed ^ 0x5DEE_CE66 });    let k = r.gen_range(2..=5);    lipsum::lipsum_words_with_rng(&mut r, k)        .split_whitespace()        .map(|w| {            let w: String = w.chars().filter(|c| c.is_alphanumeric()).collect();            let mut c = w.chars();            c.next().map_or(String::new(), |f| f.to_uppercase().collect::<String>() + c.as_str())        })        .filter(|w| !w.is_empty())        .collect::<Vec<_>>()        .join(" ")}
Thread
77Useful? Like it, or add to its thread below.

Thread 0 posts

On Lorem ipsum: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.