Struct tpnote_lib::note::Note
source · [−]Expand description
Represents a note.
Fields
context: ContextCaptured environment of Tp-Note that is used to fill in templates.
content: ContentThe full text content of the note, including its front matter.
rendered_filename: PathBuf- The
Content’s header is deserialized intoFrontMatter. FrontMatteris stored inContextwith some environment data.Contextdata is filled in some filename template.- The result is stored in
rendered_filename. This field equals toPathBuf::new()untilself.render_filenameis called.
Implementations
sourceimpl Note
impl Note
sourcepub fn from_text_file(
context: Context,
content: Option<Content>,
template_kind: TemplateKind
) -> Result<Self, NoteError>
pub fn from_text_file(
context: Context,
content: Option<Content>,
template_kind: TemplateKind
) -> Result<Self, NoteError>
Constructor, that creates a memory representation of an existing note on disk.
sourcepub fn from_content_template(
context: Context,
template_kind: TemplateKind
) -> Result<Self, NoteError>
pub fn from_content_template(
context: Context,
template_kind: TemplateKind
) -> Result<Self, NoteError>
Constructor that creates a new note by filling in the content template template.
sourcepub fn render_filename(
&mut self,
template_kind: TemplateKind
) -> Result<(), NoteError>
pub fn render_filename(
&mut self,
template_kind: TemplateKind
) -> Result<(), NoteError>
Applies a Tera template to the notes context in order to generate a sanitized filename that is in sync with the note’s meta data stored in its front matter.
sourcepub fn set_next_unused_rendered_filename(&mut self) -> Result<(), NoteError>
pub fn set_next_unused_rendered_filename(&mut self) -> Result<(), NoteError>
Checks if self.rendered_filename is taken already.
If yes, some copy counter is appended/incremented.
Contract: render_filename must have been executed before.
sourcepub fn set_next_unused_rendered_filename_or(
&mut self,
alt_path: &Path
) -> Result<(), NoteError>
pub fn set_next_unused_rendered_filename_or(
&mut self,
alt_path: &Path
) -> Result<(), NoteError>
Checks if alt_path is equal to self.rendered_filename
without considering their copy counter.
If they are similar, self.rendered_filename becomes alt_path.
If they are different, then we continue incrementing the copy
counter in self.rendered_filename until we find a free spot.
(Same as in set_next_unused_rendered_filename()).
Contract: render_filename must have been executed before.
sourcepub fn save(&self) -> Result<(), NoteError>
pub fn save(&self) -> Result<(), NoteError>
Writes the note to disk using the note’s content and the note’s
rendered_filename.
sourcepub fn rename_file_from(&self, from_path: &Path) -> Result<(), NoteError>
pub fn rename_file_from(&self, from_path: &Path) -> Result<(), NoteError>
Rename the file from_path to self.rendered_filename.
Silently fails is source and target are identical.
Contract: render_filename must have been executed before.
sourcepub fn save_and_delete_from(&mut self, from_path: &Path) -> Result<(), NoteError>
pub fn save_and_delete_from(&mut self, from_path: &Path) -> Result<(), NoteError>
Write the note to disk and remove the file at the previous location.
Similar to rename_from(), but the target is replaced by self.content.
Silently fails is source and target are identical.
Contract: render_filename must have been executed before.
sourcepub fn export_html(
&self,
html_template: &str,
export_dir: &Path
) -> Result<(), NoteError>
pub fn export_html(
&self,
html_template: &str,
export_dir: &Path
) -> Result<(), NoteError>
Renders self into HTML and saves the result in export_dir. If
export_dir is the empty string, the directory of note_path is
used. - dumps the rendition to STDOUT.
This function reads self.rendered_filename or - if empty -
self.context.path is used to determine the filename of the
html rendition.
sourcepub fn render_content_to_html(
&self,
file_ext: &str,
tmpl: &str,
java_script_insert: &str
) -> Result<String, NoteError>
pub fn render_content_to_html(
&self,
file_ext: &str,
tmpl: &str,
java_script_insert: &str
) -> Result<String, NoteError>
First, determines the markup language from the file extension or
the fm_file_ext YAML variable, if present.
Then calls the appropriate markup renderer.
Finally the result is rendered with the HTML_VIEWER_TMPL
template.