use crate::assert_element;
use kuchikikiki::{Attribute, ExpandedName, NodeRef};
#[derive(Debug, Clone)]
pub struct BehaviorSwitch(pub(crate) NodeRef);
impl BehaviorSwitch {
pub fn new(property: &str) -> Self {
let attributes = vec![(
ExpandedName::new(ns!(), local_name!("property")),
Attribute {
prefix: None,
value: format!("mw:PageProp/{property}"),
},
)];
let element = NodeRef::new_element(
crate::build_qual_name(local_name!("meta")),
attributes,
);
Self(element)
}
pub(crate) fn new_from_node(element: &NodeRef) -> Self {
assert_element(element);
Self(element.clone())
}
pub fn property(&self) -> String {
self.as_element()
.unwrap()
.attributes
.borrow()
.get("property")
.unwrap()
.trim_start_matches("mw:PageProp/")
.to_string()
}
}