make examples/html.rs use scraping::get_classes
This commit is contained in:
parent
11f2819ec8
commit
fbca56d791
|
@ -17,3 +17,7 @@ tracing = "0.1.35"
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "inventory"
|
name = "inventory"
|
||||||
required-features = ["inventory"]
|
required-features = ["inventory"]
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "html"
|
||||||
|
required-features = ["scraping"]
|
||||||
|
|
|
@ -1,34 +1,29 @@
|
||||||
fn main() {
|
use zephyr::{scraping::*, Zephyr};
|
||||||
// this list of used classes would ideally be parsed out of the written html,
|
|
||||||
// but i don't want to over complicate this example
|
|
||||||
let classes = [
|
|
||||||
"mt[10rem]",
|
|
||||||
"color[#e20f00]",
|
|
||||||
"color[green]hover",
|
|
||||||
"content[attr(after)]$after",
|
|
||||||
"content['*']$before",
|
|
||||||
"color[red]$after",
|
|
||||||
];
|
|
||||||
|
|
||||||
let z = zephyr::Zephyr::new();
|
fn main() {
|
||||||
let css = z.generate_classes(classes);
|
let body = r#"<body>
|
||||||
|
<p class="color[#e20f00] color[green]hover content['*']$before">
|
||||||
|
this text is red, but green on hover
|
||||||
|
</p>
|
||||||
|
<p class="mt[10rem] content[attr(after)]$after color[red]$after" after="hi, this is an after text">
|
||||||
|
this text has a lot of margin
|
||||||
|
</p>
|
||||||
|
</body>"#;
|
||||||
|
|
||||||
|
let classes = get_classes(&body);
|
||||||
|
|
||||||
|
let z = Zephyr::new();
|
||||||
|
let css = z.generate_classes(classes.iter().map(String::as_str));
|
||||||
|
|
||||||
let html = format!(
|
let html = format!(
|
||||||
r#"
|
r#"
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||||
<style>{css}</style>
|
<style>{css}</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
{body}
|
||||||
<p class="color[#e20f00] color[green]hover content['*']$before">
|
|
||||||
this text is red, but green on hover
|
|
||||||
</p>
|
|
||||||
<p class="mt[10rem] content[attr(after)]$after color[red]$after" after="hi, this is an after text">
|
|
||||||
this text has a lot of margin
|
|
||||||
</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl<'a> Class<'a> {
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"{indent}{selector}{space}{{{nl}{indent2}{property}:{val}{nl}{indent}}}{nl}"
|
"{indent}{selector}{space}{{{nl}{indent2}{property}:{space}{val}{nl}{indent}}}{nl}"
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else if let Some(v) = z.declarations.get(property) {
|
} else if let Some(v) = z.declarations.get(property) {
|
||||||
|
|
|
@ -45,6 +45,8 @@ pub(crate) fn default_properties() -> HashMap<String, String> {
|
||||||
("tt", "text-transform"),
|
("tt", "text-transform"),
|
||||||
("td", "text-decoration"),
|
("td", "text-decoration"),
|
||||||
("fw", "font-weight"),
|
("fw", "font-weight"),
|
||||||
|
("ff", "font-family"),
|
||||||
|
("fs", "font-size"),
|
||||||
// TODO
|
// TODO
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue