From 122d6333a0dd0b8a232d7f345b65bcc1cc86099d Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Sun, 15 Jul 2018 21:32:38 +1200 Subject: [PATCH] Add braces for all examples (lfairy/maud#137) --- README.md | 4 ++-- basic_syntax.md | 22 +++++++++------------- control_structures.md | 32 ++++++++++++++++---------------- dynamic_content.md | 12 +++++++----- web_frameworks.md | 6 +++--- 5 files changed, 37 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index bc75537..3a6a247 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ ```rust html! { - h1 "Hello, world!" + h1 { "Hello, world!" } p.intro { "This is an example of the " - a href="https://github.com/lfairy/maud" "Maud" + a href="https://github.com/lfairy/maud" { "Maud" } " template language." } } diff --git a/basic_syntax.md b/basic_syntax.md index ce8c683..a506d30 100644 --- a/basic_syntax.md +++ b/basic_syntax.md @@ -34,7 +34,7 @@ Terminate a void element using a semicolon: `br;`. Note that the result will be ```rust html! { - h1 "Poem" + h1 { "Poem" } p { "Rock, you are a rock." br; @@ -51,15 +51,9 @@ Maud also supports ending a void element with a slash: `br /`. This syntax is [d [#96]: https://github.com/lfairy/maud/pull/96 -### Nested elements `p small em` +Before version 0.18, Maud allowed the curly braces to be omitted. This syntax was [removed][#137] and now causes an error instead. -If the element has only a single child, you can omit the brackets. This shorthand works with nested elements too. - -```rust -html! { - p small em "squee" -} -``` +[#137]: https://github.com/lfairy/maud/pull/137 ## Non-empty attributes `id="yay"` @@ -84,7 +78,7 @@ html! { form { input type="checkbox" name="cupcakes" checked?; " " - label for="cupcakes" "Do you like cupcakes?" + label for="cupcakes" { "Do you like cupcakes?" } } } ``` @@ -95,7 +89,9 @@ To toggle an attribute based on a boolean flag, use a `?[]` suffix instead: `che let allow_editing = true; html! { p contenteditable?[allow_editing] { - "Edit me, I " em "dare" " you." + "Edit me, I " + em { "dare" } + " you." } } ``` @@ -117,7 +113,7 @@ To toggle a class based on a boolean flag, use a `[]` suffix: `.foo[is_foo]`. Th ```rust let cuteness = 95; html! { - p.cute[cuteness > 50] "Squee!" + p.cute[cuteness > 50] { "Squee!" } } ``` @@ -126,7 +122,7 @@ html! { ```rust html! { // This text is ignored - p "Hello!" + p { "Hello!" } /* This as well */ } ``` diff --git a/control_structures.md b/control_structures.md index 776424c..b71114d 100644 --- a/control_structures.md +++ b/control_structures.md @@ -14,16 +14,16 @@ let user = Princess::Celestia; html! { @if user == Princess::Luna { - h1 "Super secret woona to-do list" + h1 { "Super secret woona to-do list" } ul { - li "Nuke the Crystal Empire" - li "Kick a puppy" - li "Evil laugh" + li { "Nuke the Crystal Empire" } + li { "Kick a puppy" } + li { "Evil laugh" } } } @else if user == Princess::Celestia { - p "Sister, please stop reading my diary. It's rude." + p { "Sister, please stop reading my diary. It's rude." } } @else { - p "Nothing to see here; move along." + p { "Nothing to see here; move along." } } } ``` @@ -52,10 +52,10 @@ Use `@for .. in ..` to loop over the elements of an iterator. ```rust let names = ["Applejack", "Rarity", "Fluttershy"]; html! { - p "My favorite ponies are:" + p { "My favorite ponies are:" } ol { @for name in &names { - li (name) + li { (name) } } } } @@ -72,9 +72,9 @@ html! { @let first_letter = name.chars().next().unwrap(); p { "The first letter of " - b (name) + b { (name) } " is " - b (first_letter) + b { (first_letter) } "." } } @@ -93,17 +93,17 @@ let user = Princess::Celestia; html! { @match user { Princess::Luna => { - h1 "Super secret woona to-do list" + h1 { "Super secret woona to-do list" } ul { - li "Nuke the Crystal Empire" - li "Kick a puppy" - li "Evil laugh" + li { "Nuke the Crystal Empire" } + li { "Kick a puppy" } + li { "Evil laugh" } } }, Princess::Celestia => { - p "Sister, please stop reading my diary. It's rude." + p { "Sister, please stop reading my diary. It's rude." } }, - _ => p "Nothing to see here; move along." + _ => p { "Nothing to see here; move along." } } } ``` diff --git a/dynamic_content.md b/dynamic_content.md index 4052da1..521daf5 100644 --- a/dynamic_content.md +++ b/dynamic_content.md @@ -18,10 +18,12 @@ Arbitrary Rust code can be included in a splice by using a [block](https://doc.r ```rust html! { - p ({ - let f: Foo = something_convertible_to_foo()?; - f.time().format("%H%Mh") - }) + p { + ({ + let f: Foo = something_convertible_to_foo()?; + f.time().format("%H%Mh") + }) + } } ``` @@ -59,7 +61,7 @@ To change this behavior for some type, you can implement the [`Render`][Render] use maud::PreEscaped; let post = "

Pre-escaped

"; html! { - h1 "My super duper blog post" + h1 { "My super duper blog post" } (PreEscaped(post)) } ``` diff --git a/web_frameworks.md b/web_frameworks.md index 0b421d4..1a8ec22 100644 --- a/web_frameworks.md +++ b/web_frameworks.md @@ -32,7 +32,7 @@ use maud::html; fn main() { Iron::new(|r: &mut Request| { let markup = html! { - h1 "Hello, world!" + h1 { "Hello, world!" } p { "You are viewing the page at " (r.url) } @@ -72,7 +72,7 @@ use std::borrow::Cow; fn hello<'a>(name: Cow<'a, str>) -> Markup { html! { h1 { "Hello, " (name) "!" } - p "Nice to meet you!" + p { "Nice to meet you!" } } } @@ -100,7 +100,7 @@ fn main() { (GET) (/{name: String}) => { html! { h1 { "Hello, " (name) "!" } - p "Nice to meet you!" + p { "Nice to meet you!" } } }, _ => Response::empty_404()