From f682a516e7428e7d7e6c9ff876a6fb58af025cc8 Mon Sep 17 00:00:00 2001 From: Chinedu Francis Nwafili Date: Tue, 5 Mar 2019 23:14:13 -0500 Subject: [PATCH] Add text docs --- book/src/html-macro/text/README.md | 40 +++++++++++++++++++++++++++++- crates/html-macro-test/src/text.rs | 22 ++++++++-------- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/book/src/html-macro/text/README.md b/book/src/html-macro/text/README.md index ffba1356..1c632e0d 100644 --- a/book/src/html-macro/text/README.md +++ b/book/src/html-macro/text/README.md @@ -3,8 +3,46 @@ Rather than needing you to wrap your text in `"` quotation marks, the `html-macro` will work with raw unquoted text. -Here are some examples of how the `html!` macro works with text: +```rust +fn main () { + let interpolated_var = "interpolate text variables."; + + let example = html! { +
+ Text can be typed directly into your HTML. +
Or you can also {interpolated_var}
+
+ }; +} +``` + +You should always get the same spacing (or lack there of) between text and/or elements as you would +if you were working in a regular old `.html` file. + +When it comes to interpolated variables, we base spacing on the spacing outside of the brackets. + +```rust +fn main () { + let text = "hello"; + + html! {
{ hello }
}; //
hello
+ html! {
{hello}
}; //
hello
+ + html! {
{ hello }
}; //
hello
+ html! {
{hello}
}; //
hello
+ + html! {
{hello}
}; //
hello
+ html! {
{hello}
}; //
hello
+} +``` + +## More Examples + +Here are a bunch of examples showing you what happens when you try and mix +text nodes / variables / elements. ```rust +// Imported into book from crates/html-macro-test/src/text.rs + {{ #include ../../../../crates/html-macro-test/src/text.rs }} ``` diff --git a/crates/html-macro-test/src/text.rs b/crates/html-macro-test/src/text.rs index f8b006cc..60d9a92f 100644 --- a/crates/html-macro-test/src/text.rs +++ b/crates/html-macro-test/src/text.rs @@ -7,24 +7,22 @@ use virtual_node::{IterableNodes, VElement, VirtualNode}; #[test] fn text_root_node() { - HtmlMacroTest { - desc: "Text as root node", - generated: html! { some text }, - expected: VirtualNode::text("some text"), - } - .test() + assert_eq!(&html! { some text }.to_string(), "some text"); } #[test] fn text_variable_root() { let text = "hello world"; - HtmlMacroTest { - desc: "Text variable root", - generated: html! { { text } }, - expected: VirtualNode::text("hello world"), - } - .test() + assert_eq!(&html! { { text } }.to_string(), "hello world"); +} + +#[test] +fn raw_string_literal() { + assert_eq!( + &html! {
{ r#"Hello World"# }
}.to_string(), + "
Hello World
" + ); } #[test]