New toolkit card api

This commit is contained in:
asonix 2021-01-07 22:45:21 -06:00
parent 46e45e8b68
commit 7f5e01eb9f
4 changed files with 38 additions and 29 deletions

View file

@ -13,7 +13,7 @@ anyhow = "1.0.35"
env_logger = "0.8.2" env_logger = "0.8.2"
hyaenidae-toolkit = { version = "0.1.0", path = "../toolkit" } hyaenidae-toolkit = { version = "0.1.0", path = "../toolkit" }
mime = "0.3.16" mime = "0.3.16"
minify-html = "0.3.9" minify-html = "0.4.0"
[build-dependencies] [build-dependencies]
ructe = { version = "0.13.0", features = ["mime03", "sass"] } ructe = { version = "0.13.0", features = ["mime03", "sass"] }

View file

@ -40,16 +40,20 @@ async fn try_index() -> anyhow::Result<HttpResponse> {
} }
fn rendered( fn rendered(
f: impl FnOnce(&mut Cursor<Vec<u8>>) -> std::io::Result<()>, f: impl FnOnce(&mut Cursor<&mut Vec<u8>>) -> std::io::Result<()>,
) -> anyhow::Result<HttpResponse> { ) -> anyhow::Result<HttpResponse> {
let mut cursor = Cursor::new(vec![]); let mut bytes = vec![];
(f)(&mut cursor)?; (f)(&mut Cursor::new(&mut bytes))?;
let mut html = cursor.into_inner(); minify_html::truncate(
let len = minify_html::in_place(&mut html, &minify_html::Cfg { minify_js: false }) &mut bytes,
.map_err(|_| anyhow::anyhow!("Truncate error"))?; &minify_html::Cfg {
html.truncate(len); minify_js: false,
minify_css: false,
},
)
.map_err(|_| anyhow::anyhow!("Truncate error"))?;
Ok(HttpResponse::Ok() Ok(HttpResponse::Ok()
.content_type(mime::TEXT_HTML.essence_str()) .content_type(mime::TEXT_HTML.essence_str())
.body(html)) .body(bytes))
} }

View file

@ -1,12 +1,13 @@
@use hyaenidae_toolkit::{templates::{card, card_body, centered, code}, Card}; @use hyaenidae_toolkit::{templates::{card, card_body, card_title, centered, code}, Card};
@(title: &str, description: &str, example: &[&str], body: Content) @(title: &str, description: &str, example: &[&str], body: Content)
<li> <li>
@:centered(false, { @:centered(false, {
@:card(&Card::full_width(), { @:card(&Card::full_width(), {
<h4>@title</h4> @:card_title({
}, { <h4>@title</h4>
})
@:card_body({ @:card_body({
<p>@description</p> <p>@description</p>
<div class="code"> <div class="code">

View file

@ -1,4 +1,4 @@
@use hyaenidae_toolkit::{Button, Card, Link, TextInput, templates::{button, button_group, card, card_body, code, link, text_input, statics::toolkit_css}}; @use hyaenidae_toolkit::{Button, Card, Link, TextInput, templates::{button, button_group, card, card_body, card_title, code, link, text_input, statics::toolkit_css}};
@use super::{demo, section, statics::layout_css}; @use super::{demo, section, statics::layout_css};
@() @()
@ -144,10 +144,11 @@
@:section("Card", "Card template", { @:section("Card", "Card template", {
@:demo("Card", "Create a card with a Title and Body", &[ @:demo("Card", "Create a card with a Title and Body", &[
"@:card(&Card::new(), {", "@:card(&Card::new(), {",
" <div>", " @:card_title({",
" <h3>Title</h3>", " <div>",
" </div>", " <h3>Title</h3>",
"}, {", " </div>",
" })",
" @:card_body({", " @:card_body({",
" <div>", " <div>",
" <p>Body</p>", " <p>Body</p>",
@ -156,10 +157,11 @@
"})", "})",
], { ], {
@:card(&Card::new(), { @:card(&Card::new(), {
<div> @:card_title({
<h3>Title</h3> <div>
</div> <h3>Title</h3>
}, { </div>
})
@:card_body({ @:card_body({
<div> <div>
<p>Body<p> <p>Body<p>
@ -169,10 +171,11 @@
}) })
@:demo("Card", "Create a full-width card with a Title and Body. This card loses its border radius and left & right borders when the viewport width is under 700px", &[ @:demo("Card", "Create a full-width card with a Title and Body. This card loses its border radius and left & right borders when the viewport width is under 700px", &[
"@:card(&Card::full_width(), {", "@:card(&Card::full_width(), {",
" <div>", " @:card_title({",
" <h3>Title</h3>", " <div>",
" </div>", " <h3>Title</h3>",
"}, {", " </div>",
" })",
" @:card_body({", " @:card_body({",
" <div>", " <div>",
" <p>Body</p>", " <p>Body</p>",
@ -181,10 +184,11 @@
"})", "})",
], { ], {
@:card(&Card::full_width(), { @:card(&Card::full_width(), {
<div> @:card_title({
<h3>Title</h3> <div>
</div> <h3>Title</h3>
}, { </div>
})
@:card_body({ @:card_body({
<div> <div>
<p>Body<p> <p>Body<p>