Adding in with_cfg macro
This commit is contained in:
parent
cc8989772d
commit
17e5209e58
15
src/dom.rs
15
src/dom.rs
|
@ -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")
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)* }) => {{
|
||||
|
|
Loading…
Reference in New Issue