Enum gen_epub_book::ops::IncludeDirectory
[−]
[src]
pub enum IncludeDirectory { Unnamed { dir: (String, PathBuf), }, Named { name: String, dir: (String, PathBuf), }, }
Representation of an
-I
nclude directory.
Textually,
unnamed -I
nclude directories take the form of "path"
, and
named -I
nclude 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 |
|
dir: (String, PathBuf) | Directory path. |
Methods
impl IncludeDirectory
[src]
fn directory_name(&self) -> &str
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");
fn packed_name<P: AsRef<Path>>(&self, f: P) -> PathBuf
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()));
fn packed_id(&self, f: &Path) -> String
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)));
fn resolve<P: AsRef<Path>>(&self, relpath: P) -> Option<PathBuf>
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]
impl Clone for IncludeDirectory
[src]
fn clone(&self) -> IncludeDirectory
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Hash for IncludeDirectory
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Eq for IncludeDirectory
[src]
impl PartialEq for IncludeDirectory
[src]
fn eq(&self, __arg_0: &IncludeDirectory) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &IncludeDirectory) -> bool
This method tests for !=
.
impl Ord for IncludeDirectory
[src]
fn cmp(&self, __arg_0: &IncludeDirectory) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
ord_max_min
)Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
ord_max_min
)Compares and returns the minimum of two values. Read more
impl PartialOrd for IncludeDirectory
[src]
fn partial_cmp(&self, __arg_0: &IncludeDirectory) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &IncludeDirectory) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &IncludeDirectory) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &IncludeDirectory) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &IncludeDirectory) -> bool
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]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<IncludeDirectory, Error>
Parses a string s
to return a value of this type. Read more