Skip to content

Commit

Permalink
Fix some doc sample to make them buildable
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Oct 14, 2023
1 parent 1018767 commit 8d187b8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
10 changes: 7 additions & 3 deletions src/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ impl<'a> FragmentBuilder<'a> {
///
/// You can then insert the fragment into a [`DomBuilder`]:
///
/// ```no_compile
/// ```no_run
/// # use dominator::{html, fragment};
/// # let x = fragment!();
/// html!("div", {
/// .fragment(&x)
/// })
/// });
/// ```
///
/// The fragment is inlined, so it is exactly the same as if you had written this,
Expand Down Expand Up @@ -183,7 +185,9 @@ impl<'a> FragmentBuilder<'a> {
///
/// When returning a fragment from a function, you will usually need to use the `move` syntax:
///
/// ```no_compile
/// ```rust
/// # use dominator::{fragment, Fragment};
/// # fn some_string() -> String { "".to_string() }
/// fn my_fragment() -> impl Fragment {
/// let x = some_string();
///
Expand Down
56 changes: 45 additions & 11 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ macro_rules! __internal_builder {
/// Sometimes you need to access the real DOM node, for example to call
/// DOM methods. You can use `with_node!` to do that:
///
/// ```no_compile
/// ```no_run
/// # use dominator::{html, with_node, events};
/// # fn test() -> dominator::Dom {
/// html!("input" => web_sys::HtmlInputElement, {
/// .with_node!(element => {
/// .event(move |_: events::Input| {
Expand All @@ -224,6 +226,7 @@ macro_rules! __internal_builder {
/// })
/// })
/// })
/// # }
/// ```
#[macro_export]
macro_rules! with_node {
Expand Down Expand Up @@ -579,12 +582,16 @@ macro_rules! __internal_clone_split {
///
/// You can achieve the same thing by using the `clone!` macro instead:
///
/// ```no_compile
/// ```no_run
/// # use dominator::{html, events, clone};
/// # fn test() -> dominator::Dom {
/// # let (app, state, other_state) = (true, true, true);
/// html!("div", {
/// .event(clone!(app, state, other_state => move |_: events::Click| {
/// // Use app, state, and other_state
/// }))
/// })
/// # }
/// ```
#[macro_export]
macro_rules! clone {
Expand Down Expand Up @@ -621,35 +628,44 @@ macro_rules! __internal_process_keys {
///
/// Instead of writing this...
///
/// ```no_compile
/// ```no_run
/// # use dominator::html;
/// # fn test() -> dominator::Dom {
/// html!("div", {
/// .attr("foo", "bar")
/// .attr("qux", "corge")
/// .attr("yes", "no")
/// })
/// # }
/// ```
///
/// ...you can instead write this:
///
/// ```no_compile
/// ```no_run
/// # use dominator::{attrs, html};
/// # fn test() -> dominator::Dom {
/// html!("div", {
/// .attrs! {
/// foo: "bar",
/// qux: "corge",
/// yes: "no",
/// }
/// })
/// # }
/// ```
///
/// You can also use string literals as keys:
///
/// ```no_compile
/// ```no_run
/// # use dominator::{attrs, html};
/// # fn test() -> dominator::Dom {
/// html!("div", {
/// .attrs! {
/// foo: "bar",
/// "aria-label": "Qux",
/// }
/// })
/// # }
/// ```
#[macro_export]
macro_rules! attrs {
Expand All @@ -673,35 +689,44 @@ macro_rules! __internal_attrs {
///
/// Instead of writing this...
///
/// ```no_compile
/// ```no_run
/// # use dominator::html;
/// # fn test() -> dominator::Dom {
/// html!("div", {
/// .prop("foo", "bar")
/// .prop("qux", "corge")
/// .prop("yes", "no")
/// })
/// # }
/// ```
///
/// ...you can instead write this:
///
/// ```no_compile
/// ```no_run
/// # use dominator::{html, props};
/// # fn test() -> dominator::Dom {
/// html!("div", {
/// .props! {
/// foo: "bar",
/// qux: "corge",
/// yes: "no",
/// }
/// })
/// # }
/// ```
///
/// You can also use string literals as keys:
///
/// ```no_compile
/// ```no_run
/// # use dominator::{html, props};
/// # fn test() -> dominator::Dom {
/// html!("div", {
/// .props! {
/// foo: "bar",
/// "qux-corge": "Qux",
/// }
/// })
/// # }
/// ```
#[macro_export]
macro_rules! props {
Expand All @@ -725,35 +750,44 @@ macro_rules! __internal_props {
///
/// Instead of writing this...
///
/// ```no_compile
/// ```no_run
/// # use dominator::html;
/// # fn test() -> dominator::Dom {
/// html!("div", {
/// .style("display", "flex")
/// .style("color", "red")
/// .style("opacity", "0")
/// })
/// # }
/// ```
///
/// ...you can instead write this:
///
/// ```no_compile
/// ```no_run
/// # use dominator::{html, styles};
/// # fn test() -> dominator::Dom {
/// html!("div", {
/// .styles! {
/// display: "flex",
/// color: "red",
/// opacity: "0",
/// }
/// })
/// # }
/// ```
///
/// You can also use string literals as keys:
///
/// ```no_compile
/// ```no_run
/// # use dominator::{html, styles};
/// # fn test() -> dominator::Dom {
/// html!("div", {
/// .styles! {
/// color: "red",
/// "background-color": "green",
/// }
/// })
/// # }
/// ```
#[macro_export]
macro_rules! styles {
Expand Down

0 comments on commit 8d187b8

Please sign in to comment.