Skip to content
This repository has been archived by the owner on Sep 14, 2019. It is now read-only.

Commit

Permalink
Add braces for all examples (lambda-fairy/maud#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-fairy committed Jul 15, 2018
1 parent b451817 commit 122d633
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}
Expand Down
22 changes: 9 additions & 13 deletions basic_syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"`

Expand All @@ -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?" }
}
}
```
Expand All @@ -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."
}
}
```
Expand All @@ -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!" }
}
```

Expand All @@ -126,7 +122,7 @@ html! {
```rust
html! {
// This text is ignored
p "Hello!"
p { "Hello!" }
/* This as well */
}
```
Expand Down
32 changes: 16 additions & 16 deletions control_structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -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." }
}
}
```
Expand Down Expand Up @@ -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) }
}
}
}
Expand All @@ -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) }
"."
}
}
Expand All @@ -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." }
}
}
```
12 changes: 7 additions & 5 deletions dynamic_content.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}
}
```

Expand Down Expand Up @@ -59,7 +61,7 @@ To change this behavior for some type, you can implement the [`Render`][Render]
use maud::PreEscaped;
let post = "<p>Pre-escaped</p>";
html! {
h1 "My super duper blog post"
h1 { "My super duper blog post" }
(PreEscaped(post))
}
```
Expand Down
6 changes: 3 additions & 3 deletions web_frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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!" }
}
}

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 122d633

Please sign in to comment.