[−][src]Type Definition bloguen::ops::ScriptElement
type ScriptElement = WrappedElementImpl<WrappedElementImplDataScript>;
A script 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 ScriptContainer { pub script: Vec<ScriptElement>, } let script_toml = "[[script]] class = 'link' data = '/content/assets/syllable.js' [[script]] class = 'literal' data = 'document.getElementById(\"title\").innerText = \"Наган\";' [[script]] class = 'file' data = 'MathJax-config.js'"; let ScriptContainer { script } = toml::from_str(script_toml).unwrap(); assert_eq!(&script, &[ScriptElement::from_link("/content/assets/syllable.js"), ScriptElement::from_literal("document.getElementById(\"title\").innerText = \"Наган\";"), ScriptElement::from_path("MathJax-config.js")]);
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 ScriptContainer { pub scripts: Vec<ScriptElement>, } let scripts_toml = "scripts = [ 'link:/content/assets/syllable.js', 'literal:document.getElementById(\"title\").innerText = \"Наган\";', 'file:MathJax-config.js', ]"; let ScriptContainer { scripts } = toml::from_str(scripts_toml).unwrap(); assert_eq!(&scripts, &[ScriptElement::from_link("/content/assets/syllable.js"), ScriptElement::from_literal("document.getElementById(\"title\").innerText = \"Наган\";"), ScriptElement::from_path("MathJax-config.js")]);