[][src]Enum gen_epub_book::ops::IncludeDirectory

pub enum IncludeDirectory {
    Unnamed {
        dir: (String, PathBuf),
    },
    Named {
        name: String,
        dir: (String, PathBuf),
    },
}

Representation of an -Include directory.

Textually, unnamed -Include directories take the form of "path", and named -Include directories take the form of "name=path".

Variants

Unnamed

An unnamed include directory, acting transparently

Fields of Unnamed

dir: (String, PathBuf)

Directory path

Named

A named include directory, saved with prefixes.

Fields of Named

name: String

-Include directory name.

dir: (String, PathBuf)

Directory path.

Methods

impl IncludeDirectory[src]

pub fn directory_name(&self) -> &str[src]

Get the name of the include directory

(Also known as self.dir.0, but it's a convenience function, because :enums:.)

Examples

assert_eq!(
    IncludeDirectory::Unnamed {
        dir: ("cur-dir".to_string(), PathBuf::from(".")),
    }.directory_name(),
    "cur-dir");
assert_eq!(
    IncludeDirectory::Named {
        name: "dot".to_string(),
        dir: ("named-cur-dir".to_string(), PathBuf::from(".")),
    }.directory_name(),
    "named-cur-dir");

pub fn packed_name<P: AsRef<Path>>(&self, f: P) -> PathBuf[src]

Get packed filename for file specified by path.

Basically optionally prefixes util::book_filename().

Path separator, if any, is always '/'.

Examples

let fname = Path::new("content/ch01.html");
assert_eq!(
    IncludeDirectory::Unnamed {
        dir: ("cur-dir".to_string(), PathBuf::from(".")),
    }.packed_name(&fname),
    book_filename(&fname));
assert_eq!(
    IncludeDirectory::Named {
        name: "dot".to_string(),
        dir: ("named-cur-dir".to_string(), PathBuf::from(".")),
    }.packed_name(&fname).display().to_string(),
    format!("dot/{}", book_filename(&fname).display()));

pub fn packed_id(&self, f: &Path) -> String[src]

Get the (X)HTML ID from a path.

Basically optionally prefixes util::xhtml_path_id().

Examples

let fname = Path::new("content/ch01.html");
assert_eq!(
    IncludeDirectory::Unnamed {
        dir: ("cur-dir".to_string(), PathBuf::from(".")),
    }.packed_id(&fname),
    xhtml_path_id(&fname));
assert_eq!(
    IncludeDirectory::Named {
        name: "dot".to_string(),
        dir: ("named-cur-dir".to_string(), PathBuf::from(".")),
    }.packed_id(&fname),
    format!("dot--{}", xhtml_path_id(&fname)));

pub fn resolve<P: AsRef<Path>>(&self, relpath: P) -> Option<PathBuf>[src]

Resolve the path of the specified file in this include directory, or None if nonexistant or isn't a file.

Examples

let default_dir = special_book.join("gep").join("special");
let previews_dir = special_book.join("previews").join("generated").join("out");
let rendered_dir = special_book.join("rendered").join("output");
let default = IncludeDirectory::Unnamed {
    dir: ("".to_string(), default_dir.clone()),
};
let previews = IncludeDirectory::Named {
    name: "previews".to_string(),
    dir: ("../../previews/generated/out".to_string(), previews_dir.clone()),
};
let rendered = IncludeDirectory::Unnamed {
    dir: ("../../rendered/output".to_string(), rendered_dir.clone()),
};

assert_eq!(default.resolve(Path::new("intro.html")), Some(default_dir.join("intro.html")));
assert_eq!(previews.resolve(Path::new("main.html")), Some(previews_dir.join("main.html")));
assert_eq!(rendered.resolve(Path::new("ending.html")),
           Some(rendered_dir.join("ending.html")));
assert_eq!(default.resolve(Path::new("cover.png")), None);
assert_eq!(default.resolve(Path::new("../special")), None);

Trait Implementations

impl PartialEq<IncludeDirectory> for IncludeDirectory[src]

impl Ord for IncludeDirectory[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Clone for IncludeDirectory[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for IncludeDirectory[src]

impl PartialOrd<IncludeDirectory> for IncludeDirectory[src]

impl Debug for IncludeDirectory[src]

impl Display for IncludeDirectory[src]

impl Hash for IncludeDirectory[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl FromStr for IncludeDirectory[src]

type Err = Error

The associated error which can be returned from parsing.

Auto Trait Implementations

impl Send for IncludeDirectory

impl Sync for IncludeDirectory

Blanket Implementations

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From for T[src]

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

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

type Owned = T

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

impl<Q, K> Equivalent for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> Erased for T[src]