14 releases

0.3.1 May 21, 2024
0.3.0 Sep 18, 2023
0.2.0 Sep 17, 2023
0.1.10 Sep 17, 2023
0.1.8 Jan 12, 2023

#8 in #selector

Download history 22/week @ 2024-03-22 3/week @ 2024-03-29 145/week @ 2024-05-17 16/week @ 2024-05-24

904 downloads per month

MIT/Apache

50KB
1K SLoC

Statue

Easier way to query selectors for static HTML pages.

Crates.io Docs.rs License

User guide

Spare yourself from writing

let window = web_sys::window().unwrap();
let document = window.document().unwrap();

let work_area = document
    .query_selector("#work-area")
    .unwrap()
    .unwrap()
    .dyn_into::<HtmlDivElement>()
    .unwrap();

let layer_list_div = document
    .query_selector("#layer-list")
    .unwrap()
    .unwrap()
    .dyn_into::<HtmlDivElement>()
    .unwrap();

let save_files_btn: Rc<HtmlButtonElement> = document
    .query_selector("#save-files")
    .unwrap()
    .unwrap()
    .dyn_into::<HtmlButtonElement>()
    .unwrap()
    .into();

and write

initialize_elements!(
    html: "index.html", elements: {
        let work_area = Single("#work-area");
        let layer_list_div = Single("#layer-list");   
        let save_files_btn = Single("#save-files", RcT);
    }
);

instead.

If you want to have Rc<Window> or Rc<Documemt>, or maybe hide them afterwards, you can do so by supplying optional opts argument:

initialize_elements!(
    html: "index.html",
    elements: {
        let work_area = Single("#work-area");
        let layer_list_div = Single("#layer-list");   
        let save_files_btn = Single("#save-files", RcT);
    },
    opts: {
        window_ret_ty: Some(RcT),
        document_ret_ty: None
    }
);

If you want to invoke Document::query_selector_all, you can use Multi selector query, though this functionality hasn't been tested thoroughly.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~145KB