__init__¶
-
EditFrontMatter.
__init__
(*, file_path=None, jinja2_env=<jinja2.environment.Environment object>, template_str='', yaml_delim='---', keys_toDelete=[], do_readFile=True)[source]¶ Main class for the module. Programmatically Adds / Updates / Deletes yaml front matter elements embedded in text/markdown files.
Hint
This class uses keyword only arguments. Inheriting this class would look something like the following:
class Derived_EditFrontMatter (EditFrontMatter): def __init__(self,**kwargs): EditFrontMatter.__init__(self, **kwargs)
- Parameters
yaml_delim (str) – yaml file section delimiter (i.e. “—”)used to locate the source file’s embedded yaml section.
do_readFile (bool) – allow instantiation without implicit
readFile()
call
- Variables
self.file_lines (list) – Lines from the data source file. Must be managed after creating the class object if __init__(do_readFile=False)
self.file_path (str) – Path of source data file. Superfluous if
readFile()
is never calledself.fmatter (yaml) – [default: empty
dict
if yaml not found] Front matter as a yaml object. Set inreadFile()
.self.yaml_delim (str) – [default:”—”] Front matter delimiter. Can be used to change front matter delimter between reading the source file into
file_lines
and executingdumpFrontMatter()
/writeFile()
.self.yamlSeperator_pattern (
re.compile()
) – Regex patten for the yaml line delimiter. only used ifreadFile()
is calledself.yaml_start (int) – Beginning of the yaml blob in the original source file. Set in
readFile()
self.yaml_end (int) – End of the yaml blob in the origional source file. Set in
readFile()
self.template_str (str) – Contains the jinja2 template. Can be manipulated between class instantiation and executing
run()
self.jinja2_env (jinja2.Environment) – This object can be specified during class instantiation if greater control is required
self.keys_toDelete (list) – keys to be deleted from
fmatter
object. Utilized at the end of therun()
method
- Throws: