make examples/html.rs use scraping::get_classes

This commit is contained in:
annieversary 2022-08-16 23:42:45 +01:00
parent 11f2819ec8
commit fbca56d791
4 changed files with 27 additions and 26 deletions

View File

@ -17,3 +17,7 @@ tracing = "0.1.35"
[[example]]
name = "inventory"
required-features = ["inventory"]
[[example]]
name = "html"
required-features = ["scraping"]

View File

@ -1,34 +1,29 @@
fn main() {
// 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",
];
use zephyr::{scraping::*, Zephyr};
let z = zephyr::Zephyr::new();
let css = z.generate_classes(classes);
fn main() {
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!(
r#"
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>{css}</style>
</head>
<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>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>{css}</style>
</head>
{body}
</html>
"#
);

View File

@ -120,7 +120,7 @@ impl<'a> Class<'a> {
))
} else {
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) {

View File

@ -45,6 +45,8 @@ pub(crate) fn default_properties() -> HashMap<String, String> {
("tt", "text-transform"),
("td", "text-decoration"),
("fw", "font-weight"),
("ff", "font-family"),
("fs", "font-size"),
// TODO
])
}