Trait ContextState

Source
pub trait ContextState { }
Expand description

At trait setting up a state machine as described below. Its implementors represent one specific state defining the amount and the type of data the Context type holds at that moment.

Implementors§

Source§

impl ContextState for HasExistingContent

In addition to the HasSettings the YAML headers of all clipboard Content objects are registered as front matter variables fm.fm* in the Context. This stage is also used for the TemplateKind::FromTextFile template. In this case the last inserted Content comes from the text file the command line parameter <path> points to. This adds the following key:

  • TMPL_VAR_DOC

This state can evolve as the insert_front_matter_and_raw_text_from_existing_content() function can be called several times.

State order
Previous stateHasSettings or HasExistingContent
Current stateHasExistingContent
Next stateReadyForContentTemplate
Source§

impl ContextState for HasSettings

The Context has the following initialized and valid fields: path, dir_path, root_path and ct. The context ct contains data from insert_config_vars() and insert_settings(). Context<HasSettings> has the following variables set:

  • TMPL_VAR_CURRENT_SCHEME
  • TMPL_VAR_DIR_PATH in sync with self.dir_path and
  • TMPL_VAR_DOC_FILE_DATE in sync with self.doc_file_date (only if available).
  • TMPL_VAR_EXTENSION_DEFAULT
  • TMPL_VAR_LANG
  • TMPL_VAR_PATH in sync with self.path,
  • TMPL_VAR_ROOT_PATH in sync with self.root_path.
  • TMPL_VAR_SCHEME_SYNC_DEFAULT.
  • TMPL_VAR_USERNAME

The variables are inserted by the following methods: self.from(), self.insert_config_vars() and self.insert_settings(). Once this state is achieved, Context is constant and write protected until the next state transition.

State order
Previous stateInvalid
Current stateHasSettings
Next stateReadyForFilenameTemplate or HasExistingContent
Source§

impl ContextState for Invalid

The Context object is in an invalid state. Either it was not initialized or its data does not correspond any more to the Content it represents.

State order
Previous statenone
Current stateInvalid
Next stateHasSettings
Source§

impl ContextState for ReadyForContentTemplate

This marker state means that enough information have been collected in the HasExistingContent state to be passed to a content template renderer. Once this state is achieved, Context is constant and write protected until the next state transition.

State order
Previous stateHasExistingContent
Current stateReadyForContentTemplate
Next statenone
Source§

impl ContextState for ReadyForFilenameTemplate

In addition to HasSettings, the context.ct contains template variables deserialized from some note’s front matter. E.g. a field named title: appears in the context as fm.fm_title template variable. In Note objects the Content is always associated with a Context<ReadyForFilenameTemplate>. Once this state is achieved, Context is constant and write protected until the next state transition.

State order
Previous stateHasSettings
Current stateReadyForFilenameTemplate
Next statenone or ReadyForHtmlTemplate
Source§

impl ContextState for ReadyForHtmlErrorTemplate

The Context has all data for the intended template.

  • TMPL_HTML_VAR_DOC_ERROR from error_message
  • TMPL_HTML_VAR_DOC_TEXT from note_erroneous_content
  • TMPL_HTML_VAR_VIEWER_DOC_JS from viewer_doc_js

Once this state is achieved, Context is constant and write protected until the next state transition.

State order
Previous stateHasSettings
Current stateReadyForHtmlErrorTemplate
Next statenone
Source§

impl ContextState for ReadyForHtmlTemplate

In addition to the ReadyForFilenameTemplate state this state has the following variables set:

  • TMPL_HTML_VAR_EXPORTER_DOC_CSS
  • TMPL_HTML_VAR_EXPORTER_HIGHLIGHTING_CSS
  • TMPL_HTML_VAR_EXPORTER_HIGHLIGHTING_CSS
  • TMPL_HTML_VAR_VIEWER_DOC_CSS_PATH
  • TMPL_HTML_VAR_VIEWER_DOC_CSS_PATH_VALUE
  • TMPL_HTML_VAR_VIEWER_DOC_JS from viewer_doc_js
  • TMPL_HTML_VAR_VIEWER_HIGHLIGHTING_CSS_PATH
  • TMPL_HTML_VAR_VIEWER_HIGHLIGHTING_CSS_PATH_VALUE
  • TMPL_VAR_DOC

Once this state is achieved, Context is constant and write protected until the next state transition.

State order
Previous stateReadyForFilenameTemplate
Current stateReadyForHtmlTemplate
Next statenone