all: can render basic things
This commit is contained in:
41
src/dom.rs
41
src/dom.rs
@@ -3,10 +3,12 @@ use std;
|
||||
|
||||
use css;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Attr {
|
||||
attrs: HashMap<String, String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct EData {
|
||||
pub name: String,
|
||||
pub attr: Attr,
|
||||
@@ -25,11 +27,13 @@ impl EData {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SData {
|
||||
attr: Attr,
|
||||
content: css::Stylesheet,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum NType {
|
||||
Text(String),
|
||||
Comment(String),
|
||||
@@ -37,6 +41,7 @@ pub enum NType {
|
||||
Stylesheet(SData)
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Node {
|
||||
pub children: Vec<Node>,
|
||||
pub ntype: NType,
|
||||
@@ -101,3 +106,39 @@ impl std::fmt::Display for Attr {
|
||||
return Result::Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn find_node(name: String, node: &Node) -> Option<Node> {
|
||||
match node.ntype {
|
||||
NType::Text(_) | NType::Comment(_) => None,
|
||||
NType::Element(ref d) => {
|
||||
if d.name == name {
|
||||
return Some(node.clone());
|
||||
}
|
||||
for ref child in &node.children {
|
||||
if let Some(n) = find_node(name.clone(), child) {
|
||||
return Some(n);
|
||||
}
|
||||
}
|
||||
return None;
|
||||
},
|
||||
NType::Stylesheet(_) =>
|
||||
if name == "style" {
|
||||
return Some(node.clone());
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_style(node: &Node) -> Option<css::Stylesheet> {
|
||||
match find_node("style".to_string(), node) {
|
||||
Some(n) => {
|
||||
match n.ntype {
|
||||
NType::Stylesheet(d) => Some(d.content),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user