41 Commits

Author SHA1 Message Date
Maximilian Goisser
c97d23cb40 Update proc-macro2, syn and quote to 1.0
CLOSES #590
2019-08-21 09:18:06 +02:00
bors[bot]
84db98ccde Merge #585
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>
2019-08-13 13:52:35 +00:00
Boyd Johnson
76336b3940 Add touch events (#584)
This adds:
   - TouchCancel
   - TouchEnd
   - TouchEnter
   - TouchMove
   - TouchStart
2019-08-13 09:31:30 -04:00
Denis Kolodin
46ae317926 Add own Classes struct implementation
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>`.
2019-08-13 00:56:00 +09:00
Justin Starry
74373e6164 Add lifetime support to derive props macro 2019-08-11 17:38:49 -04:00
Justin Starry
c9d5c70af0 Bump version to 0.9.0 2019-08-10 19:48:21 -04:00
Justin Starry
584973c9f6 Enable 'extra-traits' feature for syn dep 2019-08-10 19:22:28 -04:00
Thomas Lacroix
78d4376c38
html!: handle misleading '>' in tag attributes
### 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
```
2019-08-07 11:52:52 +02:00
Thomas Lacroix
c6e1a395d1
html!: fix explicit return types in callbacks
### 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
2019-08-05 15:37:32 +02:00
Justin Starry
480a099397 Add support for svg by creating elements with correct namespace 2019-08-03 10:38:00 -04:00
Justin Starry
f2e0f4886b @totorigolo feedback 2019-07-31 12:23:55 -04:00
Justin Starry
e97bc98ce5 Add PeekValue trait 2019-07-30 09:47:32 -04:00
Justin Starry
478b5b99bb Support dashed custom tag names 2019-07-30 01:30:24 -04:00
Thomas Lacroix
5908d33b2c
html!: allow mixing self-closing and non-sc tags
#### 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
2019-07-26 15:09:18 +02:00
Justin Starry
97818842d7 Improve component trait check 2019-07-21 10:37:42 -04:00
Justin Starry
073d0af65d Update macro doc tests 2019-07-20 23:03:05 -04:00
Justin Starry
da1374540f Refactor props derive 2019-07-20 22:38:50 -04:00
Justin Starry
3fed651b42 Add support for required props 2019-07-20 22:38:50 -04:00
Justin Starry
d8ca45e9dd Bump version to 0.8.0 2019-07-19 10:44:03 -04:00
Justin Starry
4d775730ca Small fixes to yew-macro Cargo.toml 2019-07-19 10:25:07 -04:00
Justin Starry
43e101d201 Update macro docs and set macro version in yew cargo.toml 2019-07-18 08:38:26 -04:00
Justin Starry
af45d91f05 Remove macro-impl crate 2019-07-15 10:06:43 -04:00
Justin Starry
18e045eb51 Rework macro tests and remove yew-shared dependency 2019-07-14 22:47:15 -04:00
Justin Starry
c0bb528f76 Allow using keyword for as tag attribute 2019-07-06 10:30:59 -04:00
Justin Starry
e373df1ca2
Merge branch 'master' into refactor-vcomp 2019-07-05 20:41:26 -04:00
Justin Starry
0f87b5506d Fix test 2019-07-03 09:10:11 -04:00
Justin Starry
8962b77ff5 Support dashed tag labels 2019-07-03 00:13:12 -04:00
Justin Starry
1e1eb6f019 Code cleanup 2019-06-27 15:55:58 -04:00
Justin Starry
5615f53540 Add more test cases and improve error messages 2019-05-28 16:31:04 -04:00
Justin Starry
47f4b5088f Add test for invalid list children 2019-05-28 15:54:16 -04:00
Justin Starry
eccee9c39e Improve error messages 2019-05-28 15:52:45 -04:00
Justin Starry
a12a38f1e5 Code cleanup and small fix for component type parsing 2019-05-28 10:33:05 -04:00
Justin Starry
58c69d3bfb Special handling for href 2019-05-27 23:23:16 -04:00
Justin Starry
4011a7c7e1 Use component transform trait to set props 2019-05-27 23:08:22 -04:00
Justin Starry
1625a81b67 Add tag listener support 2019-05-27 17:35:45 -04:00
Justin Starry
44775c1abd Support special tag attributes 2019-05-27 09:34:22 -04:00
Justin Starry
9a8b0ad06e Disallow type prop for components 2019-05-27 09:01:13 -04:00
Justin Starry
284a680ba2 Implement tag attributes and overhaul prop parsing 2019-05-27 08:51:23 -04:00
Justin Starry
3aca0d8c17 Support component props 2019-05-26 09:44:10 -04:00
Justin Starry
a7291b87a1 Add root component tests 2019-05-25 16:15:56 -04:00
Justin Starry
1605c15f35 Rename macro crates, add proc_macro feature switch, split off shared crate 2019-05-25 16:14:32 -04:00