Skip to content

Commit

Permalink
Add doc test, and disable test that do not compile
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Oct 14, 2023
1 parent bd06c90 commit 1018767
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ jobs:
run: cargo build --all-targets --target wasm32-unknown-unknown
- name: Doc
run: cargo doc --no-deps --target wasm32-unknown-unknown
- name: Doc test
run: cargo test --doc
12 changes: 6 additions & 6 deletions src/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<'a> FragmentBuilder<'a> {
///
/// A fragment is a collection of children, you can use all of the methods in [`FragmentBuilder`]:
///
/// ```rust
/// ```no_compile
/// let x = fragment!({
/// .text("foo")
/// .child(html!("div", { ... }))
Expand All @@ -139,7 +139,7 @@ impl<'a> FragmentBuilder<'a> {
///
/// You can then insert the fragment into a [`DomBuilder`]:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .fragment(&x)
/// })
Expand All @@ -148,7 +148,7 @@ impl<'a> FragmentBuilder<'a> {
/// The fragment is inlined, so it is exactly the same as if you had written this,
/// there is no performance cost:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .text("foo")
/// .child(html!("div", ...))
Expand All @@ -161,7 +161,7 @@ impl<'a> FragmentBuilder<'a> {
///
/// Fragments are very useful for passing children into another component:
///
/// ```rust
/// ```no_compile
/// Foo::render(&state.foo, fragment!({
/// .text("Hello!")
/// }))
Expand All @@ -183,7 +183,7 @@ impl<'a> FragmentBuilder<'a> {
///
/// When returning a fragment from a function, you will usually need to use the `move` syntax:
///
/// ```rust
/// ```no_compile
/// fn my_fragment() -> impl Fragment {
/// let x = some_string();
///
Expand All @@ -210,7 +210,7 @@ macro_rules! fragment {
///
/// A [`BoxFragment`] can be stored in a `struct` or `static`:
///
/// ```rust
/// ```no_compile
/// static FOO: Lazy<BoxFragment> = Lazy::new(|| box_fragment!({ ... }));
/// ```
///
Expand Down
72 changes: 36 additions & 36 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ macro_rules! __internal_apply_methods_loop {
///
/// Normally you would chain method calls like this:
///
/// ```rust
/// ```no_compile
/// foo
/// .bar()
/// .qux(5)
Expand All @@ -58,7 +58,7 @@ macro_rules! __internal_apply_methods_loop {
///
/// But with `apply_methods!` you can instead do this:
///
/// ```rust
/// ```no_compile
/// apply_methods!(foo, {
/// .bar()
/// .qux(5)
Expand All @@ -69,7 +69,7 @@ macro_rules! __internal_apply_methods_loop {
/// In addition to looking nicer, it has another benefit, which is
/// that it supports macros:
///
/// ```rust
/// ```no_compile
/// apply_methods!(foo, {
/// .bar!()
/// .qux!(5)
Expand All @@ -80,13 +80,13 @@ macro_rules! __internal_apply_methods_loop {
/// If you didn't use `apply_methods!` then you would have to write
/// this instead, which is a lot less readable:
///
/// ```rust
/// ```no_compile
/// corge!(qux!(bar!(foo), 5), "yes", "no")
/// ```
///
/// It also supports macro paths:
///
/// ```rust
/// ```no_compile
/// apply_methods!(foo, {
/// .some_crate::bar!()
/// .other_crate::qux!(5)
Expand All @@ -96,7 +96,7 @@ macro_rules! __internal_apply_methods_loop {
///
/// And it supports specifying the type for method calls:
///
/// ```rust
/// ```no_compile
/// apply_methods!(foo, {
/// .bar::<String>()
/// .qux::<i32, i32>(5)
Expand All @@ -109,7 +109,7 @@ macro_rules! __internal_apply_methods_loop {
/// When using macros inside of `apply_methods!`, the object is
/// always passed as the first argument to the macro:
///
/// ```rust
/// ```no_compile
/// macro_rules! my_macro {
/// ($this:ident, $first:expr, $second:expr) => {
/// ...
Expand Down Expand Up @@ -141,7 +141,7 @@ macro_rules! __internal_apply_methods_loop {
///
/// And the macro can have whatever syntax it wants, because it's a macro:
///
/// ```rust
/// ```no_compile
/// apply_methods!(foo, {
/// .my_macro!(5; 10 => 15)
///
Expand All @@ -158,15 +158,15 @@ macro_rules! __internal_apply_methods_loop {
///
/// Rust has a limitation where you cannot use `$crate` inside of macros, which means this does not work:
///
/// ```rust
/// ```no_compile
/// apply_methods!(foo, {
/// .$crate::my_macro!(5, 10)
/// })
/// ```
///
/// Instead you can workaround that by doing this:
///
/// ```rust
/// ```no_compile
/// extern crate self as my_crate;
///
/// apply_methods!(foo, {
Expand All @@ -176,7 +176,7 @@ macro_rules! __internal_apply_methods_loop {
///
/// Alternatively, if you are using the [`html!`](crate::html) or [`svg!`](crate::svg) macros then you can use the [`apply`](DomBuilder::apply) method:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .apply(|dom| $crate::my_macro!(dom, 5, 10))
/// })
Expand Down Expand Up @@ -214,7 +214,7 @@ 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:
///
/// ```rust
/// ```no_compile
/// html!("input" => web_sys::HtmlInputElement, {
/// .with_node!(element => {
/// .event(move |_: events::Input| {
Expand All @@ -240,7 +240,7 @@ macro_rules! with_node {
///
/// For example, you might have some client-only code, and some server-only code. So you can do this:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// // This runs on both the client and server
/// .class("both")
Expand Down Expand Up @@ -286,7 +286,7 @@ macro_rules! with_cfg {
///
/// The second argument is a block of method calls. Inside of the block you can use [`DomBuilder<web_sys::ShadowRoot>`] methods:
///
/// ```rust
/// ```no_compile
/// use web_sys::ShadowRootMode;
///
/// html!("div", {
Expand Down Expand Up @@ -317,7 +317,7 @@ macro_rules! shadow_root {
///
/// Inside of the block you can use [`DomBuilder<web_sys::HtmlElement>`] methods:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .class("foo")
/// .style("color", "green")
Expand All @@ -329,7 +329,7 @@ macro_rules! shadow_root {
///
/// You can also specify the static type of the HTML element:
///
/// ```rust
/// ```no_compile
/// html!("div" => web_sys::HtmlDivElement, {
/// ...
/// })
Expand All @@ -350,7 +350,7 @@ macro_rules! html {
///
/// Inside of the block you can use [`DomBuilder<web_sys::SvgElement>`] methods:
///
/// ```rust
/// ```no_compile
/// svg!("line", {
/// .class("foo")
/// .attr("x1", "5")
Expand All @@ -362,7 +362,7 @@ macro_rules! html {
///
/// You can also specify the static type of the SVG element:
///
/// ```rust
/// ```no_compile
/// html!("line" => web_sys::SvgLineElement, {
/// ...
/// })
Expand All @@ -385,7 +385,7 @@ macro_rules! svg {
///
/// Inside of the block you can use [`DomBuilder`] methods:
///
/// ```rust
/// ```no_compile
/// dom_builder!(my_dom_node, {
/// .class("foo")
/// .style("color", "green")
Expand Down Expand Up @@ -413,7 +413,7 @@ macro_rules! dom_builder {
///
/// Inside of the block you can use [`StylesheetBuilder`] methods:
///
/// ```rust
/// ```no_compile
/// stylesheet!("div.foo > span:nth-child(5):hover", {
/// .style("color", "green")
/// .style("background-color", "blue")
Expand Down Expand Up @@ -446,7 +446,7 @@ macro_rules! stylesheet {
///
/// The `class!` macro accepts a block of method calls. Inside of the block you can use [`ClassBuilder`] methods:
///
/// ```rust
/// ```no_compile
/// class! {
/// .style("color", "green")
/// .style("background-color", "blue")
Expand All @@ -459,7 +459,7 @@ macro_rules! stylesheet {
/// The `class!` macro returns a `String`, which is a unique class name. You can then assign that class
/// name to a [`DomBuilder`]:
///
/// ```rust
/// ```no_compile
/// use once_cell::sync::Lazy;
///
/// // This uses a `static` so that it only creates the `class!` a single time.
Expand All @@ -484,7 +484,7 @@ macro_rules! stylesheet {
///
/// But you can use `pub` to export it so it can be used by other modules:
///
/// ```rust
/// ```no_compile
/// pub static MY_CLASS: Lazy<String> = Lazy::new(|| class! {
/// ...
/// });
Expand All @@ -510,7 +510,7 @@ macro_rules! class {
///
/// The second argument is a block of method calls. Inside of the block you can use [`ClassBuilder`] methods:
///
/// ```rust
/// ```no_compile
/// class! {
/// .pseudo!(":hover", {
/// .style("color", "green")
Expand All @@ -526,7 +526,7 @@ macro_rules! class {
///
/// This is useful for using browser prefixes:
///
/// ```rust
/// ```no_compile
/// class! {
/// .pseudo!([":any-link", ":-webkit-any-link"], {
/// ...
Expand Down Expand Up @@ -565,7 +565,7 @@ macro_rules! __internal_clone_split {
///
/// When you use event listeners, you often need to [`clone`](std::clone::Clone::clone) some state:
///
/// ```rust
/// ```no_compile
/// let app = app.clone();
/// let state = state.clone();
/// let other_state = other_state.clone();
Expand All @@ -579,7 +579,7 @@ macro_rules! __internal_clone_split {
///
/// You can achieve the same thing by using the `clone!` macro instead:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .event(clone!(app, state, other_state => move |_: events::Click| {
/// // Use app, state, and other_state
Expand Down Expand Up @@ -621,7 +621,7 @@ macro_rules! __internal_process_keys {
///
/// Instead of writing this...
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .attr("foo", "bar")
/// .attr("qux", "corge")
Expand All @@ -631,7 +631,7 @@ macro_rules! __internal_process_keys {
///
/// ...you can instead write this:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .attrs! {
/// foo: "bar",
Expand All @@ -643,7 +643,7 @@ macro_rules! __internal_process_keys {
///
/// You can also use string literals as keys:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .attrs! {
/// foo: "bar",
Expand Down Expand Up @@ -673,7 +673,7 @@ macro_rules! __internal_attrs {
///
/// Instead of writing this...
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .prop("foo", "bar")
/// .prop("qux", "corge")
Expand All @@ -683,7 +683,7 @@ macro_rules! __internal_attrs {
///
/// ...you can instead write this:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .props! {
/// foo: "bar",
Expand All @@ -695,7 +695,7 @@ macro_rules! __internal_attrs {
///
/// You can also use string literals as keys:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .props! {
/// foo: "bar",
Expand Down Expand Up @@ -725,7 +725,7 @@ macro_rules! __internal_props {
///
/// Instead of writing this...
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .style("display", "flex")
/// .style("color", "red")
Expand All @@ -735,7 +735,7 @@ macro_rules! __internal_props {
///
/// ...you can instead write this:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .styles! {
/// display: "flex",
Expand All @@ -747,7 +747,7 @@ macro_rules! __internal_props {
///
/// You can also use string literals as keys:
///
/// ```rust
/// ```no_compile
/// html!("div", {
/// .styles! {
/// color: "red",
Expand Down
4 changes: 2 additions & 2 deletions src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn link<A, F>(url: A, f: F) -> Dom
///
/// The `on_click_go_to_url!` macro disables the browser routing for the `<a>`, so your app remains in control of routing:
///
/// ```rust
/// ```no_compile
/// html!("a", {
/// .on_click_go_to_url!("/my-url/foo")
/// })
Expand Down Expand Up @@ -148,7 +148,7 @@ macro_rules! on_click_go_to_url {
///
/// The `link!` macro creates an `<a>` element which disables browser routing, so your app remains in control of routing:
///
/// ```rust
/// ```no_compile
/// link!("/my-url/foo", {
/// .class(...)
/// .style(...)
Expand Down

0 comments on commit 1018767

Please sign in to comment.