pub struct Context<S: ContextState + ?Sized> { /* private fields */ }Expand description
Tiny wrapper around “Tera context” with some additional information.
Implementations§
Source§impl<S: ContextState> Context<S>
The methods below are available in all ContentState states.
impl<S: ContextState> Context<S>
The methods below are available in all ContentState states.
Sourcepub fn get_dir_path(&self) -> &Path
pub fn get_dir_path(&self) -> &Path
Getter for self.dir_path.
See from() method for details.
Sourcepub fn get_root_path(&self) -> &Path
pub fn get_root_path(&self) -> &Path
Getter for self.root_path.
See from() method for details.
Sourcepub fn get_doc_file_date(&self) -> Option<SystemTime>
pub fn get_doc_file_date(&self) -> Option<SystemTime>
Getter for self.doc_file_date.
See from() method for details.
Sourcepub fn from_context_path(context: &Context<S>) -> Context<HasSettings>
pub fn from_context_path(context: &Context<S>) -> Context<HasSettings>
Constructor. Unlike from() this constructor does not access
the file system in order to detect dir_path, root_path and
doc_file_date. It copies these values from the passed context.
Use this constructor when you are sure that the above date has
not changed since you instantiated context. In this case you
can avoid repeated file access.
Source§impl Context<Invalid>
The start state of all Context objects.
impl Context<Invalid>
The start state of all Context objects.
Sourcepub fn from(path: &Path) -> Result<Context<HasSettings>, FileError>
pub fn from(path: &Path) -> Result<Context<HasSettings>, FileError>
Constructor: path is Tp-Notes first positional command line parameter
<path> (see man page). path must point to a directory or
a file.
A copy of path is stored in self.ct as key TMPL_VAR_PATH. It
directory path as key TMPL_VAR_DIR_PATH. The root directory, where
the marker file tpnote.toml was found, is stored with the key
TMPL_VAR_ROOT_PATH. If path points to a file, its file creation
date is stored with the key TMPL_VAR_DOC_FILE_DATE.
use std::path::Path;
use tpnote_lib::settings::set_test_default_settings;
use tpnote_lib::config::TMPL_VAR_DIR_PATH;
use tpnote_lib::config::TMPL_VAR_PATH;
use tpnote_lib::context::Context;
set_test_default_settings().unwrap();
let mut context = Context::from(&Path::new("/path/to/mynote.md")).unwrap();
assert_eq!(context.get_path(), Path::new("/path/to/mynote.md"));
assert_eq!(context.get_dir_path(), Path::new("/path/to/"));
assert_eq!(&context.get(TMPL_VAR_PATH).unwrap().to_string(),
r#""/path/to/mynote.md""#);
assert_eq!(&context.get(TMPL_VAR_DIR_PATH).unwrap().to_string(),
r#""/path/to""#);Trait Implementations§
Source§impl<S: ContextState> Deref for Context<S>
Auto dereferences for convenient access to tera::Context.
impl<S: ContextState> Deref for Context<S>
Auto dereferences for convenient access to tera::Context.
impl<S: ContextState + ?Sized> StructuralPartialEq for Context<S>
Auto Trait Implementations§
impl<S> Freeze for Context<S>where
S: ?Sized,
impl<S> RefUnwindSafe for Context<S>where
S: RefUnwindSafe + ?Sized,
impl<S> Send for Context<S>
impl<S> Sync for Context<S>
impl<S> Unpin for Context<S>
impl<S> UnwindSafe for Context<S>where
S: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more