Skip to content

Commit

Permalink
Merge branch 'main' into action-form-error
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessOne1917 committed Jan 2, 2024
2 parents 109d13d + 16cf3c4 commit 3b2e898
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 112 deletions.
27 changes: 14 additions & 13 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@

The examples in this directory are all built and tested against the current `main` branch.

To the extent that new features have been released or breaking changes have been made since the previous release, the examples are compatible with the `main` branch but not the current release.
To the extent that new features have been released or breaking changes have been made since the previous release, the examples are compatible with the `main` branch and not the current release.

To see the examples as they were at the time of the `0.5.0` release, [click here](https://github.com/leptos-rs/leptos/tree/v0.5.0/examples).

## Cargo Make

[Cargo Make](https://sagiegurari.github.io/cargo-make/) is used to build, test, and run examples.
## Getting Started

Here are the highlights.
The simplest way to get started with any example is to use the “quick start” command found in the README for each example. Most of the examples use either [`trunk`](https://trunkrs.dev/) (a simple build system and dev server for client-side-rendered apps) or [`cargo-leptos`](https://github.com/leptos-rs/cargo-leptos) (a build system for server-rendered and client-hydrated apps).

- Extendable custom task files are located in the [cargo-make](./cargo-make/) directory
- Running a task will automatically install `cargo` dependencies
- Each `Makefile.toml` file must extend the [cargo-make/main.toml](./cargo-make/main.toml) file
- [cargo-make](./cargo-make/) files that end in `*-test.toml` configure web testing strategies
- Run `cargo make test-report` to learn which examples have web tests
## Using Cargo Make

## Getting Started
You can also run any of the examples using [`cargo-make`](https://github.com/sagiegurari/cargo-make). Note that this is completely optional. We use it for CI, and it can be convenient for running the examples, but is not required.

Follow these steps to get any example up and running.

1. `cd` to the example root directory
2. Run `cargo make ci` to setup and test the example
3. Run `cargo make start` to run the example
4. Open the client URL in the console output (<http://127.0.0.1:8080> or <http://127.0.0.1:3000> by default)
5. Run `cargo make stop` to end any processes started by `cargo make start`.

Here are a few additional notes:

- Extendable custom task files are located in the [cargo-make](./cargo-make/) directory
- Running a task will automatically install `cargo` dependencies
- Each `Makefile.toml` file must extend the [cargo-make/main.toml](./cargo-make/main.toml) file
- [cargo-make](./cargo-make/) files that end in `*-test.toml` configure web testing strategies
- Run `cargo make test-report` to learn which examples have web tests

## Prerequisites

Expand Down
4 changes: 2 additions & 2 deletions leptos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
//! [`todo_app_sqlite_axum`](https://github.com/leptos-rs/leptos/tree/main/examples/todo_app_sqlite_axum), and
//! [`todo_app_sqlite_viz`](https://github.com/leptos-rs/leptos/tree/main/examples/todo_app_sqlite_viz)
//! show how to build a full-stack app using server functions and database connections.
//! - [`tailwind`](https://github.com/leptos-rs/leptos/tree/main/examples/tailwind) shows how to integrate
//! TailwindCSS with `cargo-leptos`.
//! - [`tailwind`](https://github.com/leptos-rs/leptos/tree/main/examples/tailwind_csr) shows how to integrate
//! TailwindCSS with `trunk` for CSR.
//!
//! Details on how to run each example can be found in its README.
//!
Expand Down
80 changes: 3 additions & 77 deletions leptos_dom/src/macro_helpers/into_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,6 @@ macro_rules! impl_into_attr_boxed {
};
}

impl IntoAttribute for Option<Attribute> {
#[inline(always)]
fn into_attribute(self) -> Attribute {
self.unwrap_or(Attribute::Option(None))
}

impl_into_attr_boxed! {}
}

impl IntoAttribute for String {
#[inline(always)]
fn into_attribute(self) -> Attribute {
Expand Down Expand Up @@ -201,46 +192,10 @@ impl IntoAttribute for bool {
impl_into_attr_boxed! {}
}

impl IntoAttribute for Option<String> {
#[inline(always)]
fn into_attribute(self) -> Attribute {
Attribute::Option(self.map(Oco::Owned))
}

impl_into_attr_boxed! {}
}

impl IntoAttribute for Option<&'static str> {
#[inline(always)]
fn into_attribute(self) -> Attribute {
Attribute::Option(self.map(Oco::Borrowed))
}

impl_into_attr_boxed! {}
}

impl IntoAttribute for Option<Rc<str>> {
impl<T: IntoAttribute> IntoAttribute for Option<T> {
#[inline(always)]
fn into_attribute(self) -> Attribute {
Attribute::Option(self.map(Oco::Counted))
}

impl_into_attr_boxed! {}
}

impl IntoAttribute for Option<Cow<'static, str>> {
#[inline(always)]
fn into_attribute(self) -> Attribute {
Attribute::Option(self.map(Oco::from))
}

impl_into_attr_boxed! {}
}

impl IntoAttribute for Option<Oco<'static, str>> {
#[inline(always)]
fn into_attribute(self) -> Attribute {
Attribute::Option(self)
self.map_or(Attribute::Option(None), IntoAttribute::into_attribute)
}

impl_into_attr_boxed! {}
Expand Down Expand Up @@ -310,17 +265,6 @@ macro_rules! attr_type {
self.into_attribute()
}
}

impl IntoAttribute for Option<$attr_type> {
fn into_attribute(self) -> Attribute {
Attribute::Option(self.map(|n| n.to_string().into()))
}

#[inline]
fn into_attribute_boxed(self: Box<Self>) -> Attribute {
self.into_attribute()
}
}
};
}

Expand All @@ -341,24 +285,6 @@ macro_rules! attr_signal_type {
};
}

macro_rules! attr_signal_type_optional {
($signal_type:ty) => {
#[cfg(not(feature = "nightly"))]
impl<T> IntoAttribute for $signal_type
where
T: Clone,
Option<T>: IntoAttribute,
{
fn into_attribute(self) -> Attribute {
let modified_fn = Rc::new(move || self.get().into_attribute());
Attribute::Fn(modified_fn)
}

impl_into_attr_boxed! {}
}
};
}

attr_type!(&String);
attr_type!(usize);
attr_type!(u8);
Expand All @@ -381,7 +307,7 @@ attr_signal_type!(RwSignal<T>);
attr_signal_type!(Memo<T>);
attr_signal_type!(Signal<T>);
attr_signal_type!(MaybeSignal<T>);
attr_signal_type_optional!(MaybeProp<T>);
attr_signal_type!(MaybeProp<T>);

#[cfg(all(target_arch = "wasm32", feature = "web"))]
#[doc(hidden)]
Expand Down
10 changes: 0 additions & 10 deletions leptos_dom/src/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,6 @@ impl IntoAttribute for Nonce {
}
}

impl IntoAttribute for Option<Nonce> {
fn into_attribute(self) -> Attribute {
Attribute::Option(self.map(|n| n.0.into()))
}

fn into_attribute_boxed(self: Box<Self>) -> Attribute {
Attribute::Option(self.map(|n| n.0.into()))
}
}

/// Accesses the nonce that has been generated during the current
/// server response. This can be added to inline `<script>` and
/// `<style>` tags for compatibility with a Content Security Policy.
Expand Down
20 changes: 10 additions & 10 deletions leptos_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,10 +603,12 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
false
};

let mut dummy = syn::parse::<DummyModel>(s.clone());
let Ok(mut dummy) = syn::parse::<DummyModel>(s.clone()) else {
return s;
};
let parse_result = syn::parse::<component::Model>(s);

if let (Ok(ref mut unexpanded), Ok(model)) = (&mut dummy, parse_result) {
if let (ref mut unexpanded, Ok(model)) = (&mut dummy, parse_result) {
let expanded = model.is_transparent(is_transparent).into_token_stream();
unexpanded.sig.ident =
unmodified_fn_name_from_fn_name(&unexpanded.sig.ident);
Expand All @@ -616,15 +618,13 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#unexpanded
}
} else if let Ok(mut dummy) = dummy {
} else {
dummy.sig.ident = unmodified_fn_name_from_fn_name(&dummy.sig.ident);
quote! {
#[doc(hidden)]
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#dummy
}
} else {
quote! {}
}
.into()
}
Expand Down Expand Up @@ -703,10 +703,12 @@ pub fn component(args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
#[proc_macro_error::proc_macro_error]
#[proc_macro_attribute]
pub fn island(_args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
let mut dummy = syn::parse::<DummyModel>(s.clone());
let Ok(mut dummy) = syn::parse::<DummyModel>(s.clone()) else {
return s;
};
let parse_result = syn::parse::<component::Model>(s);

if let (Ok(ref mut unexpanded), Ok(model)) = (&mut dummy, parse_result) {
if let (ref mut unexpanded, Ok(model)) = (&mut dummy, parse_result) {
let expanded = model.is_island().into_token_stream();
if !matches!(unexpanded.vis, Visibility::Public(_)) {
unexpanded.vis = Visibility::Public(Pub {
Expand All @@ -721,15 +723,13 @@ pub fn island(_args: proc_macro::TokenStream, s: TokenStream) -> TokenStream {
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#unexpanded
}
} else if let Ok(mut dummy) = dummy {
} else {
dummy.sig.ident = unmodified_fn_name_from_fn_name(&dummy.sig.ident);
quote! {
#[doc(hidden)]
#[allow(non_snake_case, dead_code, clippy::too_many_arguments)]
#dummy
}
} else {
quote! {}
}
.into()
}
Expand Down

0 comments on commit 3b2e898

Please sign in to comment.