fixed examples

This commit is contained in:
Maccesch 2024-07-27 18:35:19 +01:00
parent 90399ee313
commit b28f1b3e11
9 changed files with 21 additions and 16 deletions

View file

@ -13,8 +13,8 @@ def main():
if os.path.isdir(category_dir): if os.path.isdir(category_dir):
for file in os.listdir(category_dir): for file in os.listdir(category_dir):
if file.endswith(".md") and (len(sys.argv) == 1 or (sys.argv[1] in file)): if file.endswith(".md") and (len(sys.argv) == 1 or (sys.argv[1] in file)):
build_and_copy_demo(category, file) if build_and_copy_demo(category, file):
rewrite_links(category, file) rewrite_links(category, file)
def build_and_copy_demo(category, md_name): def build_and_copy_demo(category, md_name):
@ -51,7 +51,7 @@ def build_and_copy_demo(category, md_name):
with open(book_html_path, "w") as f: with open(book_html_path, "w") as f:
f.write( f.write(
f"""{head_split[0]} f"""{head_split[0]}
<head> <head>
{demo_head} {demo_head}
{target_head} {target_head}
@ -62,6 +62,10 @@ def build_and_copy_demo(category, md_name):
</body> </body>
{body_split[1]}""") {body_split[1]}""")
return True
return False
def rewrite_links(category, md_name): def rewrite_links(category, md_name):
"""Rewrite links in generated documentation to make them """Rewrite links in generated documentation to make them

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
leptos = { version = "0.6", features = ["nightly", "csr"] } leptos = { version = "0.6", features = ["nightly", "csr"] }
codee = "0.1"
console_error_panic_hook = "0.1" console_error_panic_hook = "0.1"
console_log = "1" console_log = "1"
log = "0.4" log = "0.4"

View file

@ -1,6 +1,6 @@
use codee::string::FromToStringCodec;
use leptos::*; use leptos::*;
use leptos_use::docs::demo_or_body; use leptos_use::docs::demo_or_body;
use leptos_use::utils::FromToStringCodec;
use leptos_use::{use_broadcast_channel, UseBroadcastChannelReturn}; use leptos_use::{use_broadcast_channel, UseBroadcastChannelReturn};
#[component] #[component]
@ -46,8 +46,8 @@ fn Demo() -> impl IntoView {
<p>"Received message: " {move || message().as_ref().unwrap().to_string()}</p> <p>"Received message: " {move || message().as_ref().unwrap().to_string()}</p>
</Show> </Show>
<Show when=move || error().is_some()> <Show when=move || error.with(|e| e.is_some())>
<p>"Error: " {move || format!("{:?}", error().as_ref().unwrap())}</p> <p>"Error: " {move || error.with(|e| format!("{:?}", e.as_ref().unwrap()))}</p>
</Show> </Show>
</Show> </Show>
} }

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
leptos = { version = "0.6", features = ["nightly", "csr"] } leptos = { version = "0.6", features = ["nightly", "csr"] }
codee = "0.1"
console_error_panic_hook = "0.1" console_error_panic_hook = "0.1"
console_log = "1" console_log = "1"
log = "0.4" log = "0.4"

View file

@ -1,7 +1,7 @@
use leptos::*; use leptos::*;
use leptos_use::docs::demo_or_body; use leptos_use::docs::demo_or_body;
use leptos_use::use_cookie; use leptos_use::use_cookie;
use leptos_use::utils::FromToStringCodec; use codee::string::FromToStringCodec;
use rand::prelude::*; use rand::prelude::*;
#[component] #[component]

View file

@ -4,14 +4,14 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
codee = { path = "../../../codee", features = ["json_serde"] } codee = { version = "0.1", features = ["json_serde"] }
leptos = { version = "0.6", features = ["nightly", "csr"] }
console_error_panic_hook = "0.1" console_error_panic_hook = "0.1"
console_log = "1" console_log = "1"
log = "0.4" leptos = { version = "0.6", features = ["nightly", "csr"] }
leptos-use = { path = "../..", features = ["docs"] } leptos-use = { path = "../..", features = ["docs"] }
web-sys = "0.3" log = "0.4"
serde = "1.0.163" serde = "1.0.163"
web-sys = "0.3"
[dev-dependencies] [dev-dependencies]
wasm-bindgen = "0.2" wasm-bindgen = "0.2"

View file

@ -1,7 +1,7 @@
use leptos::*; use leptos::*;
use leptos_use::docs::{demo_or_body, Note}; use leptos_use::docs::{demo_or_body, Note};
use leptos_use::storage::use_local_storage; use leptos_use::storage::use_local_storage;
use leptos_use::utils::JsonCodec; use codee::string::JsonSerdeCodec;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
@ -25,8 +25,8 @@ impl Default for BananaState {
#[component] #[component]
fn Demo() -> impl IntoView { fn Demo() -> impl IntoView {
let (state, set_state, reset) = use_local_storage::<BananaState, JsonCodec>("banana-state"); let (state, set_state, reset) = use_local_storage::<BananaState, JsonSerdeCodec>("banana-state");
let (state2, _, _) = use_local_storage::<BananaState, JsonCodec>("banana-state"); let (state2, _, _) = use_local_storage::<BananaState, JsonSerdeCodec>("banana-state");
view! { view! {
<input <input

View file

@ -5,7 +5,7 @@ edition = "2021"
[dependencies] [dependencies]
leptos = { version = "0.6", features = ["nightly", "csr"] } leptos = { version = "0.6", features = ["nightly", "csr"] }
codee = { path = "../../../codee", features = ["msgpack_serde"] } codee = { version = "0.1", features = ["msgpack_serde"] }
console_error_panic_hook = "0.1" console_error_panic_hook = "0.1"
console_log = "1" console_log = "1"
log = "0.4" log = "0.4"

View file

@ -24,7 +24,6 @@ use thiserror::Error;
/// > Please check [the codec chapter](https://leptos-use.rs/codecs.html) to see what codecs are /// > Please check [the codec chapter](https://leptos-use.rs/codecs.html) to see what codecs are
/// > available and what feature flags they require. /// > available and what feature flags they require.
/// ///
///
/// ``` /// ```
/// # use leptos::*; /// # use leptos::*;
/// # use leptos_use::{use_event_source, UseEventSourceReturn}; /// # use leptos_use::{use_event_source, UseEventSourceReturn};