From 0ae67cf12280275fed4b0b8369a0a3afb6cc8537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 6 Aug 2024 03:23:17 +0200 Subject: [PATCH] chore: clean up examples (#2779) --- .../action-form-error-handling/Cargo.toml | 1 - examples/action-form-error-handling/README.md | 69 ++----------------- .../action-form-error-handling/src/main.rs | 15 +--- examples/hackernews/Cargo.toml | 1 + examples/hackernews_islands_axum/Cargo.toml | 1 - examples/js-framework-benchmark/Cargo.toml | 2 +- examples/suspense_tests/e2e/README.md | 4 +- examples/timer/Cargo.toml | 2 +- examples/todomvc/Cargo.toml | 6 +- leptos_macro/src/view/component_builder.rs | 2 - 10 files changed, 12 insertions(+), 91 deletions(-) diff --git a/examples/action-form-error-handling/Cargo.toml b/examples/action-form-error-handling/Cargo.toml index 5c90f1665..7645095b9 100644 --- a/examples/action-form-error-handling/Cargo.toml +++ b/examples/action-form-error-handling/Cargo.toml @@ -19,7 +19,6 @@ wasm-bindgen = "0.2" serde = { version = "1", features = ["derive"] } [features] -csr = ["leptos/csr"] hydrate = ["leptos/hydrate"] ssr = [ "dep:actix-files", diff --git a/examples/action-form-error-handling/README.md b/examples/action-form-error-handling/README.md index e85b41b2c..c33bae082 100644 --- a/examples/action-form-error-handling/README.md +++ b/examples/action-form-error-handling/README.md @@ -1,68 +1,9 @@ - - - Leptos Logo - +# Action Form Error Handling Example -# Leptos Starter Template +## Getting Started -This is a template for use with the [Leptos](https://github.com/leptos-rs/leptos) web framework and the [cargo-leptos](https://github.com/akesson/cargo-leptos) tool. +See the [Examples README](../README.md) for setup and run instructions. -## Creating your template repo +## Quick Start -If you don't have `cargo-leptos` installed you can install it with - -`cargo install cargo-leptos` - -Then run - -`cargo leptos new --git leptos-rs/start` - -to generate a new project template (you will be prompted to enter a project name). - -`cd {projectname}` - -to go to your newly created project. - -Of course, you should explore around the project structure, but the best place to start with your application code is in `src/app.rs`. - -## Running your project - -`cargo leptos watch` -By default, you can access your local project at `http://localhost:3000` - -## Installing Additional Tools - -By default, `cargo-leptos` uses `nightly` Rust, `cargo-generate`, and `sass`. If you run into any trouble, you may need to install one or more of these tools. - -1. `rustup toolchain install nightly --allow-downgrade` - make sure you have Rust nightly -2. `rustup target add wasm32-unknown-unknown` - add the ability to compile Rust to WebAssembly -3. `cargo install cargo-generate` - install `cargo-generate` binary (should be installed automatically in future) -4. `npm install -g sass` - install `dart-sass` (should be optional in future) - -## Executing a Server on a Remote Machine Without the Toolchain -After running a `cargo leptos build --release` the minimum files needed are: - -1. The server binary located in `target/server/release` -2. The `site` directory and all files within located in `target/site` - -Copy these files to your remote server. The directory structure should be: -```text -leptos_start -site/ -``` -Set the following environment variables (updating for your project as needed): -```sh -export LEPTOS_OUTPUT_NAME="leptos_start" -export LEPTOS_SITE_ROOT="site" -export LEPTOS_SITE_PKG_DIR="pkg" -export LEPTOS_SITE_ADDR="127.0.0.1:3000" -export LEPTOS_RELOAD_PORT="3001" -``` -Finally, run the server binary. - -## Notes about CSR and Trunk: -Although it is not recommended, you can also run your project without server integration using the feature `csr` and `trunk serve`: - -`trunk serve --open --features csr` - -This may be useful for integrating external tools which require a static site, e.g. `tauri`. +Execute `cargo leptos watch` to run this example. diff --git a/examples/action-form-error-handling/src/main.rs b/examples/action-form-error-handling/src/main.rs index 244cf1e82..615021caf 100644 --- a/examples/action-form-error-handling/src/main.rs +++ b/examples/action-form-error-handling/src/main.rs @@ -52,23 +52,10 @@ async fn main() -> std::io::Result<()> { .await } -#[cfg(not(any(feature = "ssr", feature = "csr")))] +#[cfg(not(feature = "ssr"))] pub fn main() { // no client-side main function // unless we want this to work with e.g., Trunk for pure client-side testing // see lib.rs for hydration function instead // see optional feature `csr` instead } - -#[cfg(all(not(feature = "ssr"), feature = "csr"))] -pub fn main() { - // a client-side main function is required for using `trunk serve` - // prefer using `cargo leptos serve` instead - // to run: `trunk serve --open --features csr` - use action_form_error_handling::app::*; - use leptos::prelude::*; - - console_error_panic_hook::set_once(); - - mount_to_body(App); -} diff --git a/examples/hackernews/Cargo.toml b/examples/hackernews/Cargo.toml index f52ab6fe3..dd6b8c329 100644 --- a/examples/hackernews/Cargo.toml +++ b/examples/hackernews/Cargo.toml @@ -30,6 +30,7 @@ web-sys = { version = "0.3", features = ["AbortController", "AbortSignal"] } send_wrapper = "0.6.0" [features] +default = ["csr"] csr = ["leptos/csr"] hydrate = ["leptos/hydrate"] ssr = ["dep:actix-files", "dep:actix-web", "dep:leptos_actix", "leptos/ssr"] diff --git a/examples/hackernews_islands_axum/Cargo.toml b/examples/hackernews_islands_axum/Cargo.toml index 241a2f5fa..65047f152 100644 --- a/examples/hackernews_islands_axum/Cargo.toml +++ b/examples/hackernews_islands_axum/Cargo.toml @@ -40,7 +40,6 @@ rust-embed = { version = "8", features = [ mime_guess = { version = "2.0.4", optional = true } [features] -default = [] csr = ["leptos/csr"] hydrate = ["leptos/hydrate"] ssr = [ diff --git a/examples/js-framework-benchmark/Cargo.toml b/examples/js-framework-benchmark/Cargo.toml index 1fd6d846a..0dd76d642 100644 --- a/examples/js-framework-benchmark/Cargo.toml +++ b/examples/js-framework-benchmark/Cargo.toml @@ -8,7 +8,7 @@ codegen-units = 1 lto = true [dependencies] -leptos = { path = "../../leptos", features = ["csr"] } # for actual benchmarking, add `nightly` and `event-delegation` features +leptos = { path = "../../leptos", features = ["csr"] } # for actual benchmarking, add `nightly` and `delegation` features # used in rand, but we need to enable js feature getrandom = { version = "0.2.7", features = ["js"] } rand = { version = "0.8.5", features = ["small_rng"] } diff --git a/examples/suspense_tests/e2e/README.md b/examples/suspense_tests/e2e/README.md index 026f2befd..3c3ab2c7c 100644 --- a/examples/suspense_tests/e2e/README.md +++ b/examples/suspense_tests/e2e/README.md @@ -8,8 +8,8 @@ This example demonstrates e2e testing with Rust using executable requirements. |---|---|---| | [Cucumber](https://github.com/cucumber-rs/cucumber/tree/main) | Test Runner | Run [Gherkin](https://cucumber.io/docs/gherkin/reference/) specifications as Rust tests | | [Fantoccini](https://github.com/jonhoo/fantoccini/tree/main) | Browser Client | Interact with web pages through WebDriver | -| [Cargo Leptos ](https://github.com/leptos-rs/cargo-leptos) | Build Tool | Compile example and start the server and end-2-end tests | -| [chromedriver](https://chromedriver.chromium.org/downloads) | WebDriver | Provide WebDriver for Chrome +| [Cargo Leptos](https://github.com/leptos-rs/cargo-leptos) | Build Tool | Compile example and start the server and end-2-end tests | +| [chromedriver](https://chromedriver.chromium.org/downloads) | WebDriver | Provide WebDriver for Chrome | ## Testing Organization diff --git a/examples/timer/Cargo.toml b/examples/timer/Cargo.toml index 84e7b7938..5de8194da 100644 --- a/examples/timer/Cargo.toml +++ b/examples/timer/Cargo.toml @@ -8,7 +8,7 @@ codegen-units = 1 lto = true [dependencies] -leptos = { path = "../../leptos" } +leptos = { path = "../../leptos", features = ["csr"] } console_log = "1" log = "0.4" console_error_panic_hook = "0.1.7" diff --git a/examples/todomvc/Cargo.toml b/examples/todomvc/Cargo.toml index 7ea69921b..f870391f5 100644 --- a/examples/todomvc/Cargo.toml +++ b/examples/todomvc/Cargo.toml @@ -8,7 +8,7 @@ codegen-units = 1 lto = true [dependencies] -leptos = { path = "../../leptos" } +leptos = { path = "../../leptos", features = ["csr"] } console_error_panic_hook = "0.1.7" uuid = { version = "1", features = ["v4", "js", "serde"] } serde = { version = "1", features = ["derive"] } @@ -18,9 +18,5 @@ web-sys = { version = "0.3.60", features = ["Storage"] } [dev-dependencies] wasm-bindgen-test = "0.3.0" -[features] -default = ["csr"] -csr = ["leptos/csr"] - [package.metadata.cargo-all-features] skip_feature_sets = [["csr", "ssr"], ["csr", "hydrate"], ["ssr", "hydrate"]] diff --git a/leptos_macro/src/view/component_builder.rs b/leptos_macro/src/view/component_builder.rs index 77ab9ebdd..129388824 100644 --- a/leptos_macro/src/view/component_builder.rs +++ b/leptos_macro/src/view/component_builder.rs @@ -129,8 +129,6 @@ pub(crate) fn component_to_tokens( if idx == spread_marker { return None; } - use rstml::node::NodeBlock; - use syn::{Expr, ExprRange, RangeLimits, Stmt}; if let NodeAttribute::Block(block) = attr { let dotted = if let NodeBlock::ValidBlock(block) = block {