added book

This commit is contained in:
Maccesch 2023-05-15 01:52:02 +01:00
parent fc4198897c
commit 6a8c24ebbf
10 changed files with 121 additions and 5 deletions

1
docs/book/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
book

11
docs/book/book.toml Normal file
View file

@ -0,0 +1,11 @@
[book]
authors = ["Marc-Stefan Cassola"]
language = "en"
multilingual = false
src = "src"
title = "Leptos-Use Documentation"
[output.html]
no-section-label = true
[preprocessor.cmdrun]

12
docs/book/src/SUMMARY.md Normal file
View file

@ -0,0 +1,12 @@
# Summary
[Introduction]()
# Getting Started
- [Get Started](getting_started/get_started.md)
- [Functions](getting_started/functions.md)
# Browser
- [useEventListener](browser/use_event_listener.md)

View file

@ -0,0 +1,3 @@
# use_event_listener
<!-- cmdrun python3 ../extract_doc_comment.py use_event_listener -->

View file

@ -0,0 +1,21 @@
import sys
def main():
name = sys.argv[1]
file_name = f"../../../../src/{name}.rs"
with open(file_name) as f:
in_code_block = False
for line in f.readlines():
if line.startswith("///"):
line = line.strip().replace("/// ", "").replace("///", "")
if "```" in line:
if not in_code_block:
line = line.replace("```", "```rust,ignore")
in_code_block = not in_code_block
print(line)
if __name__ == '__main__':
main()

View file

@ -0,0 +1,3 @@
# Functions
<!-- cmdrun python3 generate_function_overview.py browser -->

View file

@ -0,0 +1,33 @@
import os
import sys
def main():
for entry in sys.argv[1:]:
generate_function_overview_for_category(entry)
def generate_function_overview_for_category(category):
print(f"## {category.title()}")
listdir = os.listdir(os.path.join(os.getcwd(), "..", category))
listdir.sort()
for name in listdir:
if name.endswith(".md"):
generate_function_overview(category, name[:-3])
def generate_function_overview(category, name):
file_name = f"../../../../src/{name}.rs"
with open(file_name) as f:
in_code_block = False
for line in f.readlines():
if line.startswith("///"):
line = line.strip().replace("/// ", "")
print(f"- [{name}](/{category}/{name}.md) {line}")
return
if __name__ == '__main__':
main()

View file

@ -0,0 +1,31 @@
# Get Started
## Installation
```shell
cargo add leptos-use
```
## Examples
- [Examples Directory](https://github.com/Synphonyte/leptos-use/tree/master/examples)
## Usage Example
Simply import the functions you need from `leptos-use`
```rust,noplayground
# use leptos::*;
use leptos_use::use_mouse::*;
#[component]
pub fn Demo(cx: Scope) -> into ImplView {
let UseMouseReturn { x, y, .. } = use_mouse(cx);
view! { cx,
{x} "x" {y}
}
}
```
Please refer to the [functions list](functions.md) for more details.

View file

@ -1,6 +1,6 @@
pub mod core;
mod use_event_listener;
mod use_scroll;
pub mod use_event_listener;
pub mod use_scroll;
pub use use_event_listener::*;
pub use use_scroll::*;
pub use use_event_listener::use_event_listener;
pub use use_scroll::use_scroll;

View file

@ -8,7 +8,8 @@ use std::rc::Rc;
use wasm_bindgen::closure::Closure;
use wasm_bindgen::JsCast;
/// Use EventListener with ease. Register using [addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) on mounted,
/// Use EventListener with ease.
/// Register using [addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) on mounted,
/// and [removeEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener) automatically on cleanup.
///
/// ## Usage