Adding in with_cfg macro

This commit is contained in:
Pauan 2020-05-05 15:32:20 +02:00
parent cc8989772d
commit 17e5209e58
2 changed files with 28 additions and 1 deletions

View File

@ -1170,7 +1170,7 @@ pub mod __internal {
#[cfg(test)]
mod tests {
use super::{DomBuilder, text_signal, RefFn};
use crate::{html, shadow_root, ShadowRootMode};
use crate::{html, shadow_root, ShadowRootMode, with_cfg};
use futures_signals::signal::{always, SignalExt};
use lazy_static::lazy_static;
use web_sys::HtmlElement;
@ -1316,4 +1316,17 @@ mod tests {
})
});
}
#[test]
fn with_cfg() {
let _a = html!("div", {
.with_cfg!(target_arch = "wasm32", {
.attribute("foo", "bar")
})
.with_cfg!(all(not(foo), bar = "test", feature = "hi"), {
.attribute("foo", "bar")
})
});
}
}

View File

@ -44,6 +44,20 @@ macro_rules! with_node {
}
#[macro_export]
macro_rules! with_cfg {
($this:ident, $cfg:meta, { $($methods:tt)* }) => {{
#[cfg($cfg)]
let this = $crate::apply_methods!($this, { $($methods)* });
#[cfg(not($cfg))]
let this = $this;
this
}};
}
#[macro_export]
macro_rules! shadow_root {
($this:ident, $mode:expr => { $($methods:tt)* }) => {{