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]]
|
||||
name = "inventory"
|
||||
required-features = ["inventory"]
|
||||
|
||||
[[example]]
|
||||
name = "html"
|
||||
required-features = ["scraping"]
|
||||
|
|
|
@ -1,17 +1,19 @@
|
|||
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#"
|
||||
|
@ -21,14 +23,7 @@ fn main() {
|
|||
<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>
|
||||
{body}
|
||||
</html>
|
||||
"#
|
||||
);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
])
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue