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

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

An unnamed include directory, acting transparently

Fields of Unnamed

Directory path

A named include directory, saved with prefixes.

Fields of Named

-Include directory name.

Directory path.

Methods

impl IncludeDirectory
[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");

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()));

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)));

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 Debug for IncludeDirectory
[src]

Formats the value using the given formatter.

impl Clone for IncludeDirectory
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Hash for IncludeDirectory
[src]

Feeds this value into the given [Hasher]. Read more

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

impl Eq for IncludeDirectory
[src]

impl PartialEq for IncludeDirectory
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Ord for IncludeDirectory
[src]

This method returns an Ordering between self and other. Read more

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

Compares and returns the maximum of two values. Read more

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

Compares and returns the minimum of two values. Read more

impl PartialOrd for IncludeDirectory
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl FromStr for IncludeDirectory
[src]

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

impl Display for IncludeDirectory
[src]

Formats the value using the given formatter. Read more