* Add render method to Component and auto implement Renderable
* More cleanup
* Rename Renderable method from view to render
* Doc fixes
* fix
* Update CHANGELOG.md
589: Allow components to accept children elements r=jstarry a=jstarry
Fixes: https://github.com/yewstack/yew/issues/537
#### Terminology
- (B) Base component that renders components nested inside each other
- (P) Parent component that has a `children` property and can render those children
- (C) Child component that is nested inside parent and included inside the Parent's `children`
#### Todo
- [x] Add example for nested components
- [x] Support arbitrary html nested inside component tags
- [x] Support nested components inside component tags
- [x] Allow modifying & accessing (C) props when rendering (P)
- [x] Allow filtering (C) components when rendering (P)
- [x] Children prop be required or optional
- [x] Clean up nested component example
- [x] Fix parser for generic component type
- [x] Write tests
- [x] Update documentation and README
- [x] ~~Investigate passing required properties from (P) -> (C)~~
- [x] ~~Allow sending messages from (C) -> (B)~~
Co-authored-by: Justin Starry <jstarry@users.noreply.github.com>
585: Add own Classes struct implementation r=DenisKolodin a=DenisKolodin
Hide details of Classes set implementation and add a feature to produce that struct from variety of sources like `&str`, `String` and `Vec<T> where T: AsRef<str>`.
I need this to have an effective way to construct complex classes set for https://github.com/yewstack/facade. With this PR we can do something like:
```rust
let mut classes = vec!["container"];
classes.push("fluid");
// or
let mut classes = Classes::new();
classes.append("container");
if fluid_flag {
container.append("fluid");
}
html! {
<div classes=classes />
}
```
In the future we can implement `impl Info<Classes> for (tuple)` and simplify macro by delegating **tuples to classes** conversion to type system (instead of macro).
Let's give a chance to CI to check it 🤞
Also I applied `cargo fmt` to the root crate sources.
Co-authored-by: Denis Kolodin <deniskolodin@gmail.com>
Hide details of Classes set implementation and add a feature to produce that struct
from variety of sources like `&str`, `String` and `Vec<T> where T: AsRef<str>`.
### Problem
The html! macro didn't handle cases like this one:
```rust
html! {
<div onclick=|_| 2 > 1 />
// ^ this
}
```
Moreover, the introduction of handling of mixed self-closing and not
self-closing tags introduced a buggy error message, which is now fixed.
### Solution
The parser only allows '<', '{' or nothing after a tag's closing '>'.
`verify_end` is removed, and the presence of a closing tag is checked
when parsing the children.
Note: I also moved some tests around.
### Regression
Unfortunately, this change has a regression: the error message is less
good now, like here in `html-tag-fail.stderr`:
```
diff --git a/tests/macro/html-tag-fail.stderr b/tests/macro/html-tag-fail.stderr
index b14fc14..d59e8f4 100644
--- a/tests/macro/html-tag-fail.stderr
+++ b/tests/macro/html-tag-fail.stderr
@@ -52,11 +52,13 @@ error: only one root html element allowed
12 | html! { <img /></img> };
| ^^^^^^
-error: expected valid html element
- --> $DIR/html-tag-fail.rs:13:18
+error: unexpected end of input, expected token tree
+ --> $DIR/html-tag-fail.rs:13:5
|
13 | html! { <div>Invalid</div> };
- | ^^^^^^^
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: only one `attr` attribute allowed
--> $DIR/html-tag-fail.rs:15:27
```
### Problem
The html! macro didn't properly handle explicit return types in
callbacks, considering the '>' in '->' as the end of the HTML tag.
```rust
html! {
<div onblur=|_| -> u32 0 />
// ^ here
}
```
Fixes: #560
#### Problem
Self-closing tags are more convenient when there are no children. For
instance, React's JSX allows it.
Before, self-closing tags where considered as open tags in `verify_end`,
causing codes like this to not compile:
```rust
html! {
<div>
<div/> // <- considered as open tag
</div>
}
```
```
error: this open tag has no corresponding close tag
--> src/lib.rs:264:17
|
... | <div>
| ^^^^^
```
#### Solution
Add a new `Peek`-able `HtmlSelfClosingTag`, used in `verify_end`.
However, this fix isn't ideal because it peeks the buffer twice for
non self-closing tags. I did it that way in order to keep the peek
thing. An alternative would be to turn HtmlSelfClosingTag::peek into a
function returning (ident, is_self_closing).
#### Notes
I added a TODO for when proc-macro::Diagnostic gets stabilized, in
order to replace the clunky `eprintln!` with proper diagnostics. I
didn't try to return a Result to get a nice error right now because
this error should be fairly rare so we can just wait IMO.
Fixes: #522