[−][src]Struct bloguen::ops::WrappedElementImpl
A semi-generic wrapped data specifier, backing ScriptElement
and
StyleElement
.
Methods
impl<Dt: WrappedElementImplData> WrappedElementImpl<Dt>
[src]
pub fn from_link<DtF: Into<Cow<'static, str>>>(link: DtF) -> Self
[src]
Create an element linking to an external resource.
Examples
let lonk = ScriptElement::from_link("/content/assets/syllable.js"); assert_eq!( format!("{}{}{}", lonk.head(), lonk.content(), lonk.foot()), "<script type=\"text/javascript\" src=\"/content/assets/syllable.js\"></script>\n")
let lonk = StyleElement::from_link("//nabijaczleweli.xyz/kaschism/assets/column.css"); assert_eq!( format!("{}{}{}", lonk.head(), lonk.content(), lonk.foot()), "<link href=\"//nabijaczleweli.xyz/kaschism/assets/column.css\" rel=\"stylesheet\" />\n")
pub fn from_literal<DtF: Into<Cow<'static, str>>>(literal: DtF) -> Self
[src]
Create an element including the specified literal literally.
Examples
let lit = ScriptElement::from_literal("document.getElementById(\"title\").innerText = \"Наган\";"); assert_eq!( format!("{}{}{}", lit.head(), lit.content(), lit.foot()), "<script type=\"text/javascript\">\n\ndocument.getElementById(\"title\").innerText = \"Наган\";\n\n</script>\n")
let lit = StyleElement::from_literal(".indented { text-indent: 1em; }"); assert_eq!( format!("{}{}{}", lit.head(), lit.content(), lit.foot()), "<style type=\"text/css\">\n\n.indented { text-indent: 1em; }\n\n</style>\n")
pub fn from_path<DtF: Into<Cow<'static, str>>>(path: DtF) -> Self
[src]
Create an element pointing to the specified relative path.
Consult load()
documentation for more data.
Examples
Given $ROOT/MathJax-config.js
containing:
MathJax.Hub.Config({
jax: ["input/AsciiMath", "output/HTML-CSS"],
extensions: ["asciimath2jax.js"],
asciimath2jax: {
delimiters: [['[[', ']]']],
preview: "[[maths]]"
},
AsciiMath: {
decimal: "."
},
"HTML-CSS": {
undefinedFamily: "STIXGeneral,'DejaVu Sans Mono','Arial Unicode MS',serif"
}
});
The following holds:
let root: PathBuf = /* obtained elsewhere */; let mut lit_p = ScriptElement::from_path("MathJax-config.js"); assert_eq!(lit_p.load(&("$ROOT".to_string(), root.clone())), Ok(())); assert_eq!(format!("{}{}{}", lit_p.head(), lit_p.content(), lit_p.foot()), "<script type=\"text/javascript\">\n\n\ MathJax.Hub.Config({\n\ jax: [\"input/AsciiMath\", \"output/HTML-CSS\"],\n\ extensions: [\"asciimath2jax.js\"],\n\ asciimath2jax: {\n\ delimiters: [['[[', ']]']],\n\ preview: \"[[maths]]\"\n\ },\n\ AsciiMath: {\n\ decimal: \".\"\n\ },\n\ \"HTML-CSS\": {\n\ undefinedFamily: \"STIXGeneral,'DejaVu Sans Mono','Arial Unicode MS',serif\"\n\ }\n\ });\n\ \n\n</script>\n");
Given $ROOT/common.css
containing:
ul, ol {
margin-top: 0;
margin-bottom: 0;
}
a > i.fa {
color: black;
}
The following holds:
let root: PathBuf = /* obtained elsewhere */; let mut lit_p = StyleElement::from_path("common.css"); assert_eq!(lit_p.load(&("$ROOT".to_string(), root.clone())), Ok(())); assert_eq!(format!("{}{}{}", lit_p.head(), lit_p.content(), lit_p.foot()), "<style type=\"text/css\">\n\n\ ul, ol {\n\ margin-top: 0;\n\ margin-bottom: 0;\n\ }\n\ \n\ a > i.fa {\n\ color: black;\n\ }\n\n\ \n\n</style>\n");
pub fn from_file(path: &(String, PathBuf)) -> Result<Self, Error>
[src]
Create a literal script element from the contents of the specified file.
Examples
Given $ROOT/MathJax-config.js
containing:
MathJax.Hub.Config({
jax: ["input/AsciiMath", "output/HTML-CSS"],
extensions: ["asciimath2jax.js"],
asciimath2jax: {
delimiters: [['[[', ']]']],
preview: "[[maths]]"
},
AsciiMath: {
decimal: "."
},
"HTML-CSS": {
undefinedFamily: "STIXGeneral,'DejaVu Sans Mono','Arial Unicode MS',serif"
}
});
The following holds:
let root: PathBuf = /* obtained elsewhere */; let lit_p = ScriptElement::from_file(&("$ROOT/MathJax-config.js".to_string(), root.join("MathJax-config.js"))).unwrap(); assert_eq!(format!("{}{}{}", lit_p.head(), lit_p.content(), lit_p.foot()), "<script type=\"text/javascript\">\n\n\ MathJax.Hub.Config({\n\ jax: [\"input/AsciiMath\", \"output/HTML-CSS\"],\n\ extensions: [\"asciimath2jax.js\"],\n\ asciimath2jax: {\n\ delimiters: [['[[', ']]']],\n\ preview: \"[[maths]]\"\n\ },\n\ AsciiMath: {\n\ decimal: \".\"\n\ },\n\ \"HTML-CSS\": {\n\ undefinedFamily: \"STIXGeneral,'DejaVu Sans Mono','Arial Unicode MS',serif\"\n\ }\n\ });\n\ \n\n</script>\n");
Given $ROOT/common.css
containing:
ul, ol {
margin-top: 0;
margin-bottom: 0;
}
a > i.fa {
color: black;
}
The following holds:
let root: PathBuf = /* obtained elsewhere */; let lit_p = StyleElement::from_file(&("$ROOT/common.css".to_string(), root.join("common.css"))).unwrap(); assert_eq!(format!("{}{}{}", lit_p.head(), lit_p.content(), lit_p.foot()), "<style type=\"text/css\">\n\n\ ul, ol {\n\ margin-top: 0;\n\ margin-bottom: 0;\n\ }\n\ \n\ a > i.fa {\n\ color: black;\n\ }\n\n\ \n\n</style>\n");
pub fn load(&mut self, base: &(String, PathBuf)) -> Result<(), Error>
[src]
Read data from the filesystem, if appropriate.
Path elements are concatenated with the specified root, then read_file()
d in, becoming
literals.
Non-path elements are unaffected.
Examples
Given the following directory layout:
$ROOT
MathJax-config.js
assets
octicons.js
Given $ROOT/MathJax-config.js
containing:
MathJax.Hub.Config({
jax: ["input/AsciiMath", "output/HTML-CSS"],
extensions: ["asciimath2jax.js"],
asciimath2jax: {
delimiters: [['[[', ']]']],
preview: "[[maths]]"
},
AsciiMath: {
decimal: "."
},
"HTML-CSS": {
undefinedFamily: "STIXGeneral,'DejaVu Sans Mono','Arial Unicode MS',serif"
}
});
Given $ROOT/assets/octicons.js
containing:
window.addEventListener("load", function() {
const PLACEHOLDER = document.getElementById("octicons-placeholder");
const request = new XMLHttpRequest();
request.open("GET", "/content/assets/octicons/sprite.octicons.svg");
request.onload = function(load) {
PLACEHOLDER.outerHTML = load.target.responseText.replace("<svg", "<svg class=\"hidden\"");
};
request.send();
});
The following holds:
function() {\n\
let root: PathBuf = /* obtained elsewhere */;
let mut elem = ScriptElement::from_path("MathJax-config.js");
assert_eq!(elem.load(&("$ROOT".to_string(), root.clone())), Ok(()));
assert_eq!(elem, ScriptElement::from_literal("\
MathJax.Hub.Config({\n\
jax: [\"input/AsciiMath\", \"output/HTML-CSS\"],\n\
extensions: [\"asciimath2jax.js\"],\n\
asciimath2jax: {\n\
delimiters: [['[[', ']]']],\n\
preview: \"[[maths]]\"\n\
},\n\
AsciiMath: {\n\
decimal: \".\"\n\
},\n\
\"HTML-CSS\": {\n\
undefinedFamily: \"STIXGeneral,'DejaVu Sans Mono','Arial Unicode MS',serif\"\n\
}\n\
});\n\
"));
let mut elem = ScriptElement::from_path("assets/.././assets/octicons.js");
assert_eq!(elem.load(&("$ROOT".to_string(), root.clone())), Ok(()));
assert_eq!(elem, ScriptElement::from_literal("\
window.addEventListener(\"load\", function() {\n\
const PLACEHOLDER = document.getElementById(\"octicons-placeholder\");\n\
\n\
const request = new XMLHttpRequest();\n\
request.open(\"GET\", \"/content/assets/octicons/sprite.octicons.svg\");\n\
request.onload = function(load) {\n\
PLACEHOLDER.outerHTML = load.target.responseText.replace(\"
Given the following directory layout:
$ROOT
common.css
assets
effects.css
Given $ROOT/common.css
containing:
ul, ol {
margin-top: 0;
margin-bottom: 0;
}
a > i.fa {
color: black;
}
Given $ROOT/assets/effects.css
containing:
.ruby {
/* That's Ruby according to https://en.wikipedia.org/wiki/Ruby_(color). */
color: #E0115F;
}
The following holds:
let root: PathBuf = /* obtained elsewhere */; let mut elem = StyleElement::from_path("common.css"); assert_eq!(elem.load(&("$ROOT".to_string(), root.clone())), Ok(())); assert_eq!(elem, StyleElement::from_literal("\ ul, ol {\n\ margin-top: 0;\n\ margin-bottom: 0;\n\ }\n\ \n\ a > i.fa {\n\ color: black;\n\ }\n ")); let mut elem = StyleElement::from_path("assets/.././assets/effects.css"); assert_eq!(elem.load(&("$ROOT".to_string(), root.clone())), Ok(())); assert_eq!(elem, StyleElement::from_literal("\ .ruby {\n\ /* That's Ruby according to https://en.wikipedia.org/wiki/Ruby_(color). */\n\ color: #E0115F;\n\ }\n ")); let mut elem = StyleElement::from_path("assets/nonexistant.css"); assert_eq!(elem.load(&("$ROOT".to_string(), root.clone())), Err(Error::FileNotFound { who: "file style element", path: "$ROOT/assets/nonexistant.css".into(), })); assert_eq!(elem, StyleElement::from_path("assets/nonexistant.css"));
Trait Implementations
impl<Dt: WrappedElementImplData> WrappedElement for WrappedElementImpl<Dt>
[src]
fn head(&self) -> &str
[src]
fn content(&self) -> &str
[src]
fn foot(&self) -> &str
[src]
fn head_b(&self) -> &[u8]
[src]
fn content_b(&self) -> &[u8]
[src]
fn foot_b(&self) -> &[u8]
[src]
impl<Dt: Eq + WrappedElementImplData> Eq for WrappedElementImpl<Dt>
[src]
impl<Dt: Clone + WrappedElementImplData> Clone for WrappedElementImpl<Dt>
[src]
fn clone(&self) -> WrappedElementImpl<Dt>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Dt: PartialOrd + WrappedElementImplData> PartialOrd<WrappedElementImpl<Dt>> for WrappedElementImpl<Dt>
[src]
fn partial_cmp(&self, other: &WrappedElementImpl<Dt>) -> Option<Ordering>
[src]
fn lt(&self, other: &WrappedElementImpl<Dt>) -> bool
[src]
fn le(&self, other: &WrappedElementImpl<Dt>) -> bool
[src]
fn gt(&self, other: &WrappedElementImpl<Dt>) -> bool
[src]
fn ge(&self, other: &WrappedElementImpl<Dt>) -> bool
[src]
impl<Dt: PartialEq + WrappedElementImplData> PartialEq<WrappedElementImpl<Dt>> for WrappedElementImpl<Dt>
[src]
fn eq(&self, other: &WrappedElementImpl<Dt>) -> bool
[src]
fn ne(&self, other: &WrappedElementImpl<Dt>) -> bool
[src]
impl<Dt: Ord + WrappedElementImplData> Ord for WrappedElementImpl<Dt>
[src]
fn cmp(&self, other: &WrappedElementImpl<Dt>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<Dt: Hash + WrappedElementImplData> Hash for WrappedElementImpl<Dt>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<Dt: Debug + WrappedElementImplData> Debug for WrappedElementImpl<Dt>
[src]
impl<'de, Dt: WrappedElementImplData> Deserialize<'de> for WrappedElementImpl<Dt>
[src]
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
[src]
Auto Trait Implementations
impl<Dt> Send for WrappedElementImpl<Dt> where
Dt: Send,
Dt: Send,
impl<Dt> Unpin for WrappedElementImpl<Dt> where
Dt: Unpin,
Dt: Unpin,
impl<Dt> Sync for WrappedElementImpl<Dt> where
Dt: Sync,
Dt: Sync,
impl<Dt> UnwindSafe for WrappedElementImpl<Dt> where
Dt: UnwindSafe,
Dt: UnwindSafe,
impl<Dt> RefUnwindSafe for WrappedElementImpl<Dt> where
Dt: RefUnwindSafe,
Dt: RefUnwindSafe,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,