[][src]Type Definition bloguen::ops::StyleElement

type StyleElement = WrappedElementImpl<WrappedElementImplDataStyle>;

A style specifier.

Can be a link or a literal, and a literal can be indirectly loaded from a file.

Consult the documentation for load() on handling filesystem interaxion.

Deserialisation

There are two serialised forms, a verbose one:

#[derive(Deserialize, Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
struct StyleContainer {
    pub style: Vec<StyleElement>,
}

let style_toml =
    "[[style]]
     class = 'link'
     data = '//nabijaczleweli.xyz/kaschism/assets/column.css'

     [[style]]
     class = 'literal'
     data = '.indented { text-indent: 1em; }'

     [[style]]
     class = 'file'
     data = 'common.css'";

let StyleContainer { style } = toml::from_str(style_toml).unwrap();
assert_eq!(&style,
           &[StyleElement::from_link("//nabijaczleweli.xyz/kaschism/assets/column.css"),
             StyleElement::from_literal(".indented { text-indent: 1em; }"),
             StyleElement::from_path("common.css")]);

And a compact one (the "literal" tag may be omitted if the content doesn't contain any colons):

#[derive(Deserialize, Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
struct StyleContainer {
    pub styles: Vec<StyleElement>,
}

let styles_toml =
    "styles = [
         'link://nabijaczleweli.xyz/kaschism/assets/column.css',
         'literal:.indented { text-indent: 1em; }',
         'file:common.css',
     ]";

let StyleContainer { styles } = toml::from_str(styles_toml).unwrap();
assert_eq!(&styles,
           &[StyleElement::from_link("//nabijaczleweli.xyz/kaschism/assets/column.css"),
             StyleElement::from_literal(".indented { text-indent: 1em; }"),
             StyleElement::from_path("common.css")]);