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"
hyaenidae-toolkit = { version = "0.1.0", path = "../toolkit" }
mime = "0.3.16"
minify-html = "0.3.9"
minify-html = "0.4.0"
[build-dependencies]
ructe = { version = "0.13.0", features = ["mime03", "sass"] }

View file

@ -40,16 +40,20 @@ async fn try_index() -> anyhow::Result<HttpResponse> {
}
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> {
let mut cursor = Cursor::new(vec![]);
(f)(&mut cursor)?;
let mut html = cursor.into_inner();
let len = minify_html::in_place(&mut html, &minify_html::Cfg { minify_js: false })
.map_err(|_| anyhow::anyhow!("Truncate error"))?;
html.truncate(len);
let mut bytes = vec![];
(f)(&mut Cursor::new(&mut bytes))?;
minify_html::truncate(
&mut bytes,
&minify_html::Cfg {
minify_js: false,
minify_css: false,
},
)
.map_err(|_| anyhow::anyhow!("Truncate error"))?;
Ok(HttpResponse::Ok()
.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)
<li>
@:centered(false, {
@:card(&Card::full_width(), {
<h4>@title</h4>
}, {
@:card_title({
<h4>@title</h4>
})
@:card_body({
<p>@description</p>
<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};
@()
@ -144,10 +144,11 @@
@:section("Card", "Card template", {
@:demo("Card", "Create a card with a Title and Body", &[
"@:card(&Card::new(), {",
" <div>",
" <h3>Title</h3>",
" </div>",
"}, {",
" @:card_title({",
" <div>",
" <h3>Title</h3>",
" </div>",
" })",
" @:card_body({",
" <div>",
" <p>Body</p>",
@ -156,10 +157,11 @@
"})",
], {
@:card(&Card::new(), {
<div>
<h3>Title</h3>
</div>
}, {
@:card_title({
<div>
<h3>Title</h3>
</div>
})
@:card_body({
<div>
<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", &[
"@:card(&Card::full_width(), {",
" <div>",
" <h3>Title</h3>",
" </div>",
"}, {",
" @:card_title({",
" <div>",
" <h3>Title</h3>",
" </div>",
" })",
" @:card_body({",
" <div>",
" <p>Body</p>",
@ -181,10 +184,11 @@
"})",
], {
@:card(&Card::full_width(), {
<div>
<h3>Title</h3>
</div>
}, {
@:card_title({
<div>
<h3>Title</h3>
</div>
})
@:card_body({
<div>
<p>Body<p>