[][src]Struct bloguen::ops::WrappedElementImpl

pub struct WrappedElementImpl<Dt: WrappedElementImplData>(_, _);

A semi-generic wrapped data specifier, backing ScriptElement and StyleElement.

Methods

impl<Dt: WrappedElementImplData> WrappedElementImpl<Dt>[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]

impl<Dt: Eq + WrappedElementImplData> Eq for WrappedElementImpl<Dt>[src]

impl<Dt: Clone + WrappedElementImplData> Clone for WrappedElementImpl<Dt>[src]

impl<Dt: PartialOrd + WrappedElementImplData> PartialOrd<WrappedElementImpl<Dt>> for WrappedElementImpl<Dt>[src]

impl<Dt: PartialEq + WrappedElementImplData> PartialEq<WrappedElementImpl<Dt>> for WrappedElementImpl<Dt>[src]

impl<Dt: Ord + WrappedElementImplData> Ord for WrappedElementImpl<Dt>[src]

impl<Dt: Hash + WrappedElementImplData> Hash for WrappedElementImpl<Dt>[src]

impl<Dt: Debug + WrappedElementImplData> Debug for WrappedElementImpl<Dt>[src]

impl<'de, Dt: WrappedElementImplData> Deserialize<'de> for WrappedElementImpl<Dt>[src]

Auto Trait Implementations

impl<Dt> Send for WrappedElementImpl<Dt> where
    Dt: Send

impl<Dt> Unpin for WrappedElementImpl<Dt> where
    Dt: Unpin

impl<Dt> Sync for WrappedElementImpl<Dt> where
    Dt: Sync

impl<Dt> UnwindSafe for WrappedElementImpl<Dt> where
    Dt: UnwindSafe

impl<Dt> RefUnwindSafe for WrappedElementImpl<Dt> where
    Dt: RefUnwindSafe

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]