From 7ce0bd8d3aa8f218cc6da74fad1ece25cfd27cba Mon Sep 17 00:00:00 2001 From: Martin Matusiak Date: Fri, 26 Jun 2020 22:29:58 +1000 Subject: [PATCH] Fix broken examples (#1289) - batch #1 (#1340) * Update run instructions `python3 -m http.server --directory` flag was added in Python 3.7. Change instructions to cd into static and skip the flag instead - makes it work with earlier Pythons too. * Add visual feedback for button click The minimal example has a button, but clicking it does nothing. This makes it hard to tell whether the example works or not. This adds a label that is update when the button is clicked. * Small improvements to crm example * Add a heading to each scene to make it more obvious what the page is for. * Improve layout of input form by stack the inputs vertically. * Add a little space between entries when displaying the list. * Add a hint to the Description input that Markdown can be used. * Add an explanation to the file_upload example * Clarify purpose of var in fragments example * Improve futures_wp example * Add a second button that demonstrates an unsuccessful fetch. * Render the markdown document (since we're fetching markdown after all). * Remove vague comment that's not really helping. * Improve inner_html example * Include a textual explanation of what the example is doing. * Run cargo fmt * Remove 'static lifetime for constant * Improve suggestion in inner_html example * move markdown.rs to a common crate * add description to common Cargo.toml * PR feedback * PR feedback * remove static lifetime annotation --- examples/README.md | 2 +- examples/common/Cargo.toml | 10 ++++++ examples/common/src/lib.rs | 1 + examples/{crm => common}/src/markdown.rs | 0 examples/crm/Cargo.toml | 2 +- examples/crm/src/lib.rs | 24 +++++++++----- examples/file_upload/src/lib.rs | 1 + examples/fragments/src/lib.rs | 6 ++-- examples/futures_wp/Cargo.toml | 1 + examples/futures_wp/src/lib.rs | 42 +++++++++++++++++------- examples/inner_html/src/document.html | 9 +++++ examples/inner_html/src/lib.rs | 10 ++---- examples/minimal/src/lib.rs | 11 +++++-- examples/minimal_wp/src/lib.rs | 11 +++++-- 14 files changed, 93 insertions(+), 37 deletions(-) create mode 100644 examples/common/Cargo.toml create mode 100644 examples/common/src/lib.rs rename examples/{crm => common}/src/markdown.rs (100%) create mode 100644 examples/inner_html/src/document.html diff --git a/examples/README.md b/examples/README.md index 23994c99b83..997b94c9201 100644 --- a/examples/README.md +++ b/examples/README.md @@ -17,7 +17,7 @@ Have a look at Yew's [starter templates](https://yew.rs/docs/getting-started/sta git clone https://github.com/yewstack/yew.git cd yew/examples ./build.sh minimal # example subfolder -python3 -m http.server --directory static # open localhost:8000 in browser +cd static && python3 -m http.server # open localhost:8000 in browser ``` diff --git a/examples/common/Cargo.toml b/examples/common/Cargo.toml new file mode 100644 index 00000000000..c2fa06438f0 --- /dev/null +++ b/examples/common/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "common" +version = "0.1.0" +authors = ["Martin Matusiak "] +edition = "2018" +description="A useful utility for handing markdown which is used by other examples – not an example in itself!" + +[dependencies] +yew = { path = "../../yew" } +pulldown-cmark = { version = "0.7.0", default-features = false } diff --git a/examples/common/src/lib.rs b/examples/common/src/lib.rs new file mode 100644 index 00000000000..163a4fba821 --- /dev/null +++ b/examples/common/src/lib.rs @@ -0,0 +1 @@ +pub mod markdown; diff --git a/examples/crm/src/markdown.rs b/examples/common/src/markdown.rs similarity index 100% rename from examples/crm/src/markdown.rs rename to examples/common/src/markdown.rs diff --git a/examples/crm/Cargo.toml b/examples/crm/Cargo.toml index c440ff5ab34..14032fb4036 100644 --- a/examples/crm/Cargo.toml +++ b/examples/crm/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" serde = "1" serde_derive = "1" yew = { path = "../../yew" } -pulldown-cmark = { version = "0.7.0", default-features = false } +common = { path = "../common" } diff --git a/examples/crm/src/lib.rs b/examples/crm/src/lib.rs index 12ed58982f6..22b0cb8d1f9 100644 --- a/examples/crm/src/lib.rs +++ b/examples/crm/src/lib.rs @@ -1,10 +1,9 @@ -#![recursion_limit = "128"] +#![recursion_limit = "256"] #[macro_use] extern crate serde_derive; -mod markdown; - +use common::markdown; use yew::format::Json; use yew::services::storage::Area; use yew::services::{DialogService, StorageService}; @@ -152,6 +151,7 @@ impl Component for Model { match self.scene { Scene::ClientsList => html! {
+

{"List of clients"}

{ for self.database.clients.iter().map(Renderable::render) }
@@ -161,10 +161,17 @@ impl Component for Model { }, Scene::NewClientForm(ref client) => html! {
+

{"Add a new client"}

- { client.view_first_name_input(&self.link) } - { client.view_last_name_input(&self.link) } - { client.view_description_textarea(&self.link) } +
+ { client.view_first_name_input(&self.link) } +
+
+ { client.view_last_name_input(&self.link) } +
+
+ { client.view_description_textarea(&self.link) } +
@@ -173,6 +180,7 @@ impl Component for Model { }, Scene::Settings => html! {
+

{"Settings"}

@@ -184,7 +192,7 @@ impl Component for Model { impl Renderable for Client { fn render(&self) -> Html { html! { -
+

{ format!("First Name: {}", self.first_name) }

{ format!("Last Name: {}", self.last_name) }

{ "Description:" }

@@ -215,7 +223,7 @@ impl Client { fn view_description_textarea(&self, link: &ComponentLink) -> Html { html! {