Skip to content

Commit

Permalink
fix: add crate name on examples to fix unit tests on README
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcAntoine-Arnaud committed Aug 26, 2023
1 parent 1b6b8bb commit 453fe4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
```

```rust
let html = template_html!("templates/hello.html", name="World");
let html = yew_template::template_html!("templates/hello.html", name="World");
```

The code above will actually compile to the following code:
Expand Down Expand Up @@ -56,7 +56,7 @@ let html = yew::html! {

```rust
let name = "World";
let html = template_html!("templates/hello.html", name);
let html = yew_template::template_html!("templates/hello.html", name);
```

Would compile to:
Expand All @@ -74,7 +74,7 @@ When the name of your variable isn't the same as the name in the template, you c

```rust
let other_name = "Yew";
let html = template_html!("templates/hello.html", name=other_name);
let html = yew_template::template_html!("templates/hello.html", name=other_name);
```

### Attributes
Expand All @@ -86,7 +86,7 @@ let html = template_html!("templates/hello.html", name=other_name);
```

```rust
let html = template_html!(
let html = yew_template::template_html!(
"templates/hello.html",
name="Yew",
style="color: red;"
Expand Down Expand Up @@ -122,14 +122,14 @@ let person = Person {
first_name: "Edouard".to_string(),
last_name: "Foobar".to_string()
};
let html = template_html!("templates/fields.html", person);
let html = yew_template::template_html!("templates/fields.html", person);
```

### Expressions

```rust
let name_reversed = String::from("dlroW");
let html = template_html!(
let html = yew_template::template_html!(
"templates/hello.html",
name = {
let mut name = name_reversed.into_bytes();
Expand Down Expand Up @@ -169,11 +169,12 @@ Note that the curly brackets around expressions are required for expressions.
```

```rust
let link = ctx.link();
let html = template_html!(
let onclick = yew::Callback::from(|()| {});

let html = yew_template::template_html!(
"templates/hello.html",
name="World",
onclick={link.callback(|_| Msg::AddOne)}
onclick={onclick}
);
```

Expand Down Expand Up @@ -240,7 +241,7 @@ From the Rust side, there is no usage difference. Note that curly brackets are r
```rust
let opt_age: Option<u8> = Some(20);
let opt_birth_city: Option<String> = None;
let html = template_html!(
let html = yew_template::template_html!(
"templates/opt.html",
name="John",
opt_age,
Expand All @@ -265,8 +266,8 @@ Elements can be given a `present-if` attribute. The value will be evaluated at r
</div>
```

```rust
let html = template_html!("templates/present_if.html", condition={ 1+1==3 });
```rust ignore
let html = yew_template::template_html!("templates/present_if.html", condition={ 1+1==3 });
```

### Iterators
Expand All @@ -285,7 +286,7 @@ The looping html element is marked with the `iter` attribute. The element will r

```rust
let contributors = vec!["John", "Jane", "Jack"]; // Owned values need to be declared as `let` or they would be freed before the template is rendered.
let html = template_html!(
let html = yew_template::template_html!(
"templates/iter.html",
contributors_iter = {contributors.iter()},
commits_iter = {[42, 21, 7].iter()}
Expand All @@ -294,7 +295,7 @@ let html = template_html!(

The code above will act as the following for Yew:

```rust
```rust ignore
let contributors = vec!["John", "Jane", "Jack"];
let html = yew::html! {
<div>
Expand Down Expand Up @@ -328,7 +329,7 @@ The whole point of using this crate is making your code more readable than when

```rust
let name = "World";
let html = template_html!("templates/hello.html", ...);
let html = yew_template::template_html!("templates/hello.html", ...);
```

This behavior is disabled by default because missing variables are often mistakes. If you want to enable it without have to add `...` to every macro call, please set `auto_default` to true in your [config](#config).
Expand All @@ -345,7 +346,7 @@ Yew-template often requires you to add attributes on html elements such as `iter

```rust
let opt_name = Some("John".to_string());
let html = template_html!("templates/virtual.html", opt_name);
let html = yew_template::template_html!("templates/virtual.html", opt_name);
```

On Yew side, this will be seen as:
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ pub(crate) use {
pub(crate) use crate::i18n::*;

/// Reads a file and replaces the variables it contains with the supplied values. Produces a Yew html! macro invocation.
///
/// ```ignore
/// let html = template_html!("path", arg="value", arg2="value2", arg3={expression});
///
/// ```rust ignore
/// let html = yew_template::template_html!("path", arg="value", arg2="value2", arg3={expression});
/// ```
///
///
/// See top-level documentation for more information.
#[proc_macro]
#[proc_macro_error]
Expand Down

0 comments on commit 453fe4d

Please sign in to comment.