Skip to content

Commit

Permalink
Merge branch 'master' into silence-field-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
voidpumpkin committed Dec 15, 2021
2 parents 58cb457 + 1ef364f commit 803e0be
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 350 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Expand Up @@ -137,7 +137,7 @@ jobs:
- name: Run website code snippet tests
run: |
cd packages/website-test
cd tools/website-test
cargo test
integration_tests:
Expand Down
11 changes: 5 additions & 6 deletions Cargo.toml
@@ -1,11 +1,9 @@
[workspace]
members = [
# Packages
"packages/yew",
"packages/yew-macro",
"packages/yew-validation",
"packages/yew-agent",

# Router
"packages/yew-router",
"packages/yew-router-macro",

Expand Down Expand Up @@ -35,9 +33,10 @@ members = [
"examples/webgl",
"examples/web_worker_fib",

# Release tools
"packages/changelog",
# Tools
"tools/changelog",
]
exclude = [
"packages/website-test",
# Tools
"tools/website-test",
]
2 changes: 1 addition & 1 deletion Makefile.toml
Expand Up @@ -97,7 +97,7 @@ args = ["test", "--doc"]
[tasks.website-test]
script = [
"""
cd packages/website-test
cd tools/website-test
cargo test
"""
]
Expand Down
9 changes: 5 additions & 4 deletions packages/yew-macro/src/derive_props/builder.rs
Expand Up @@ -8,7 +8,7 @@
use super::generics::{to_arguments, with_param_bounds, GenericArguments};
use super::{DerivePropsInput, PropField};
use proc_macro2::{Ident, Span};
use quote::{quote, ToTokens};
use quote::{format_ident, quote, ToTokens};
use syn::Attribute;

pub struct PropsBuilder<'a> {
Expand Down Expand Up @@ -126,9 +126,10 @@ impl PropsBuilder<'_> {
.filter(|pf| pf.is_required())
.map(|pf| pf.to_step_name(prefix))
.collect();
step_names.push(Ident::new(
&format!("{}PropsBuilder", prefix),
prefix.span(),
step_names.push(format_ident!(
"{}PropsBuilder",
prefix,
span = prefix.span(),
));
step_names
}
Expand Down
12 changes: 7 additions & 5 deletions packages/yew-macro/src/derive_props/field.rs
@@ -1,7 +1,7 @@
use super::generics::GenericArguments;
use super::should_preserve_attr;
use proc_macro2::{Ident, Span};
use quote::{quote, quote_spanned};
use quote::{format_ident, quote, quote_spanned};
use std::cmp::{Ord, Ordering, PartialEq, PartialOrd};
use std::convert::TryFrom;
use syn::parse::Result;
Expand Down Expand Up @@ -34,9 +34,11 @@ impl PropField {

/// This step name is descriptive to help a developer realize they missed a required prop
pub fn to_step_name(&self, props_name: &Ident) -> Ident {
Ident::new(
&format!("{}_missing_required_prop_{}", props_name, self.name),
Span::call_site(),
format_ident!(
"{}_missing_required_prop_{}",
props_name,
self.name,
span = Span::call_site(),
)
}

Expand Down Expand Up @@ -189,7 +191,7 @@ impl PropField {
Ok(PropAttr::Option)
} else {
let ident = named_field.ident.as_ref().unwrap();
let wrapped_name = Ident::new(&format!("{}_wrapper", ident), Span::call_site());
let wrapped_name = format_ident!("{}_wrapper", ident, span = Span::call_site());
Ok(PropAttr::Required { wrapped_name })
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/yew-macro/src/derive_props/mod.rs
Expand Up @@ -6,7 +6,7 @@ mod wrapper;
use builder::PropsBuilder;
use field::PropField;
use proc_macro2::{Ident, Span};
use quote::{quote, ToTokens};
use quote::{format_ident, quote, ToTokens};
use std::convert::TryInto;
use syn::parse::{Parse, ParseStream, Result};
use syn::{Attribute, DeriveInput, Generics, Visibility};
Expand Down Expand Up @@ -80,7 +80,7 @@ impl ToTokens for DerivePropsInput {
} = self;

// The wrapper is a new struct which wraps required props in `Option`
let wrapper_name = Ident::new(&format!("{}Wrapper", props_name), Span::call_site());
let wrapper_name = format_ident!("{}Wrapper", props_name, span = Span::call_site());
let wrapper = PropsWrapper::new(
&wrapper_name,
generics,
Expand All @@ -90,8 +90,8 @@ impl ToTokens for DerivePropsInput {
tokens.extend(wrapper.into_token_stream());

// The builder will only build if all required props have been set
let builder_name = Ident::new(&format!("{}Builder", props_name), Span::call_site());
let builder_step = Ident::new(&format!("{}BuilderStep", props_name), Span::call_site());
let builder_name = format_ident!("{}Builder", props_name, span = Span::call_site());
let builder_step = format_ident!("{}BuilderStep", props_name, span = Span::call_site());
let builder = PropsBuilder::new(
&builder_name,
&builder_step,
Expand Down
21 changes: 14 additions & 7 deletions packages/yew-macro/src/html_tree/html_element.rs
Expand Up @@ -298,10 +298,9 @@ impl ToTokens for HtmlElement {
TagName::Lit(name) => {
let name_span = name.span();
let name = name.to_ascii_lowercase_string();
match &*name {
let node = match &*name {
"input" => {
quote_spanned! {name_span=>
#[allow(clippy::redundant_clone, unused_braces)]
quote! {
::std::convert::Into::<::yew::virtual_dom::VNode>::into(
::yew::virtual_dom::VTag::__new_input(
#value,
Expand All @@ -315,8 +314,7 @@ impl ToTokens for HtmlElement {
}
}
"textarea" => {
quote_spanned! {name_span=>
#[allow(clippy::redundant_clone, unused_braces)]
quote! {
::std::convert::Into::<::yew::virtual_dom::VNode>::into(
::yew::virtual_dom::VTag::__new_textarea(
#value,
Expand All @@ -329,8 +327,7 @@ impl ToTokens for HtmlElement {
}
}
_ => {
quote_spanned! {name_span=>
#[allow(clippy::redundant_clone, unused_braces)]
quote! {
::std::convert::Into::<::yew::virtual_dom::VNode>::into(
::yew::virtual_dom::VTag::__new_other(
::std::borrow::Cow::<'static, ::std::primitive::str>::Borrowed(#name),
Expand All @@ -343,6 +340,16 @@ impl ToTokens for HtmlElement {
)
}
}
};
// the return value can be inlined without the braces when this is stable:
// https://github.com/rust-lang/rust/issues/15701
quote_spanned!{
name_span =>
{
#[allow(clippy::redundant_clone, unused_braces)]
let node = #node;
node
}
}
}
TagName::Expr(name) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/yew-macro/tests/derive_props/pass.rs
Expand Up @@ -260,6 +260,14 @@ mod t13 {
create_message: ::std::option::Option<bool>,
NonSnakeCase: u32,
}
}

mod raw_field_names {
#[derive(::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props {
r#true: u32,
r#pointless_raw_name: u32,
}

}

Expand Down
3 changes: 3 additions & 0 deletions packages/yew-macro/tests/html_macro/component-pass.rs
Expand Up @@ -95,6 +95,8 @@ impl ::std::convert::Into<::yew::virtual_dom::VNode> for ChildrenVariants {
pub struct ChildProperties {
#[prop_or_default]
pub string: ::std::string::String,
#[prop_or_default]
pub r#fn: ::std::primitive::i32,
pub int: ::std::primitive::i32,
#[prop_or_default]
pub opt_str: ::std::option::Option<::std::string::String>,
Expand Down Expand Up @@ -159,6 +161,7 @@ mod scoped {

fn compile_pass() {
::yew::html! { <Child int=1 /> };
::yew::html! { <Child int=1 r#fn=1 /> };

::yew::html! {
<>
Expand Down
14 changes: 13 additions & 1 deletion packages/yew-macro/tests/html_macro_test.rs
@@ -1,4 +1,4 @@
use yew::html;
use yew::{html, html_nested};

#[allow(dead_code)]
#[rustversion::attr(stable(1.51), test)]
Expand Down Expand Up @@ -28,3 +28,15 @@ fn dynamic_tags_catch_non_ascii() {
<@{"❤"}/>
};
}

/// test that compilation on html elements pass
/// fixes: https://github.com/yewstack/yew/issues/2268
#[test]
fn html_nested_macro_on_html_element() {
let _node = html_nested! {
<div/>
};
let _node = html_nested! {
<input/>
};
}
10 changes: 10 additions & 0 deletions packages/yew-macro/tests/props_macro/props-pass.rs
Expand Up @@ -43,10 +43,20 @@ struct Props {
b: ::std::primitive::usize,
}

#[derive(::yew::Properties, ::std::cmp::PartialEq)]
pub struct RawIdentProps {
r#true: ::std::primitive::usize,
#[prop_or_default]
r#pointless_raw_name: ::std::primitive::usize,
}

fn compile_pass() {
::yew::props!(Props { a: 5 });
let (a, b) = (3, 5);
::yew::props!(Props { a, b });
::yew::props!(RawIdentProps { r#true: 5 });
let (r#true, r#pointless_raw_name) = (3, 5);
::yew::props!(RawIdentProps { r#true, r#pointless_raw_name });
}

fn main() {}
78 changes: 1 addition & 77 deletions packages/yew-router/README.md
@@ -1,80 +1,4 @@
# yew-router
A routing library for the [Yew](https://github.com/yewstack/yew) frontend framework.


### Example

```rust
use yew::prelude::*;
use yew_functional::*;
use yew_router::prelude::*;

#[derive(Debug, Clone, Copy, PartialEq, Routable)]
enum Route {
#[at("/")]
Home,
#[at("/secure")]
Secure,
#[not_found]
#[at("/404")]
NotFound,
}

fn switch(routes: &Route) -> Html {
let onclick_callback = Callback::from(|_| yew_router::service::push(Route::Home, None));
match routes {
Route::Home => html! { <h1>{ "Home" }</h1> },
Route::Secure => html! {
<div>
<h1>{ "Secure" }</h1>
<button onclick={onclick_callback}>{ "Go Home" }</button>
</div>
},
Route::NotFound => html! { <h1>{ "404" }</h1> },
}
}

// Component's `view` method
html! {
<Router<Route> render={Router::render(switch)} />
}
```

### How it works
This library works by getting the url location from the browser and uses it to instantiate a type that implements Switch.
Simply using `<a></a>` tags to go to your route will not work out of the box, and are inefficient because the server will return the whole app bundle again at best, and at worst just return a 404 message if the server isn't configured properly.
Using this library's RouteService, RouteAgent, RouterButton, and RouterLink to set the location via `history.push_state()` will change the route without retrieving the whole app again.
#### Server configuration
In order for an external link to your webapp to work, the server must be configured to return the `index.html` file for any GET request that would otherwise return a `404` for any conceivable client-side route.
It can't be a `3xx` redirect to `index.html`, as that will change the url in the browser, causing the routing to fail - it must be a `200` response containing the content of `index.html`.
Once the content of `index.html` loads, it will in turn load the rest of your assets as expected and your app will start, the router will detect the current route, and set your application state accordingly.

If you choose to serve the app from the same server as your api, it is recommended to mount your api under `/api` and mount your assets under `/` and have `/` return the content of `index.html`.

Look at https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback for info on how to configure a webpack dev server to have this behavior.


### How to Include
You can use the released version by adding these to your dependencies.
```toml
[dependencies]
yew-router = "0.14.0"
yew = "0.17.0"
```

You can use the in-development version in your project by adding it to your dependencies like so:
```toml
[dependencies]
yew-router = { git = "https://github.com/yewstack/yew", branch="master" }
yew = {git = "https://github.com/yewstack/yew", branch = "master"}
```


#### Minimum rustc
Currently, this library targets rustc 1.39.0, but development is done on the latest stable release.
This library aims to track Yew`s minimum supported rustc version.

-----
### Contributions/Requests

If you have any questions, suggestions, or want to contribute, please open an Issue or PR and we will get back to you in a timely manner.
[Read on how to use it on yew.rs](https://yew.rs/docs/concepts/router)
12 changes: 0 additions & 12 deletions packages/yew-validation/Cargo.toml

This file was deleted.

0 comments on commit 803e0be

Please sign in to comment.