mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 10:16:02 +00:00
adding latest
This commit is contained in:
@@ -55,29 +55,24 @@ class PageCreator:
|
||||
def create_page(self, options: PageCreatorOptions) -> Page:
|
||||
raise NotImplementedError
|
||||
|
||||
def _convert_base_path_to_path(self) -> pathlib.Path:
|
||||
# check if Tembo base path exists
|
||||
def _check_base_path_exists(self) -> None:
|
||||
if not pathlib.Path(self.options.base_path).expanduser().exists():
|
||||
raise exceptions.BasePathDoesNotExistError(
|
||||
f"Tembo base path of {self.options.base_path} does not exist."
|
||||
)
|
||||
|
||||
def _convert_base_path_to_path(self) -> pathlib.Path:
|
||||
path_to_file = (
|
||||
pathlib.Path(self.options.base_path).expanduser()
|
||||
/ pathlib.Path(self.options.page_path.replace(" ", "_")).expanduser()
|
||||
/ self.options.filename.replace(" ", "_")
|
||||
)
|
||||
try:
|
||||
# check for existing `.` in the extension
|
||||
extension = (
|
||||
self.options.extension[1:]
|
||||
if self.options.extension[0] == "."
|
||||
else self.options.extension
|
||||
)
|
||||
except IndexError:
|
||||
# REVIEW: try putting a . in the config yaml and see what error is raised
|
||||
# this is no longer generic it just gets the full path to the file.
|
||||
# IndexError means the path is not a file, just a path
|
||||
return path_to_file
|
||||
# check for existing `.` in the extension
|
||||
extension = (
|
||||
self.options.extension[1:]
|
||||
if self.options.extension[0] == "."
|
||||
else self.options.extension
|
||||
)
|
||||
# return path with a file
|
||||
return path_to_file.with_suffix(f".{extension}")
|
||||
|
||||
@@ -126,6 +121,7 @@ class ScopedPageCreator(PageCreator):
|
||||
|
||||
def create_page(self, options: PageCreatorOptions) -> Page:
|
||||
self._options = options
|
||||
self._check_base_path_exists()
|
||||
|
||||
self._all_input_tokens = self._get_input_tokens()
|
||||
self._verify_input_tokens()
|
||||
@@ -145,8 +141,9 @@ class ScopedPageCreator(PageCreator):
|
||||
self.options.base_path,
|
||||
self.options.page_path,
|
||||
self.options.filename,
|
||||
self.options.extension,
|
||||
).expanduser()
|
||||
)
|
||||
.expanduser()
|
||||
.with_suffix(f".{self.options.extension}")
|
||||
)
|
||||
template_contents = self._load_template()
|
||||
# get the input tokens from both the path and the template
|
||||
@@ -295,78 +292,3 @@ class ScopedPage(Page):
|
||||
scoped_page.write(self.page_content)
|
||||
# TODO: pass this back somehow
|
||||
tembo.logger.info("Saved %s to disk", self.path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
c = ScopedPageCreator()
|
||||
# # raises error
|
||||
# # print(c._substitute_tokens("scratchpad/{input0}-{d:DD-MM-YYYY}-{d:dddd}-{d:A}-file.md", None))
|
||||
# print(
|
||||
# c._substitute_tokens(
|
||||
# "scratchpad/{d:A}/{d:DD-MM-YYYY}-{d:dddd}-{d:A}-file-{input0}.md", ("last",)
|
||||
# )
|
||||
# )
|
||||
|
||||
# print(
|
||||
# c.create_page(
|
||||
# "~/tembo",
|
||||
# "{name}",
|
||||
# "{input0}-{input1}-file",
|
||||
# "md",
|
||||
# "scratchpad",
|
||||
# ("first", "second"),
|
||||
# )
|
||||
# )
|
||||
# print(
|
||||
# c.create_page(
|
||||
# "~/tembo",
|
||||
# "{name}/{d:MMMM-YY}",
|
||||
# "{input0}-{d:DD-MM-YYYY}-{d:dddd}-{d:A}-file",
|
||||
# "md",
|
||||
# "scratchpad",
|
||||
# ("first",),
|
||||
# )
|
||||
# )
|
||||
# print(
|
||||
# c.create_page(
|
||||
# "~/tembo",
|
||||
# "{name}/{d:DD-MM-YYYY}-{d:dddd}-{d:A}",
|
||||
# "file",
|
||||
# "md",
|
||||
# "scratchpad",
|
||||
# None,
|
||||
# )
|
||||
# )
|
||||
# print(
|
||||
# c.create_page(
|
||||
# "~/tembo",
|
||||
# "{name}/{d:A}/{d:DD-MM-YYYY}-{d:dddd}-{d:A}",
|
||||
# "file-{input0}-{name}",
|
||||
# ".md",
|
||||
# "meeting",
|
||||
# ("last",),
|
||||
# "scratchpad.md.tpl",
|
||||
# )
|
||||
# )
|
||||
# test_page_with_template = c.create_page(
|
||||
# "~/tembo",
|
||||
# "{name}/{d:A}/{d:DD-MM-YYYY}-{d:dddd}-{d:A}",
|
||||
# "file-{input0}-{name}",
|
||||
# ".md",
|
||||
# "meeting",
|
||||
# ("last",),
|
||||
# "scratchpad.md.tpl",
|
||||
# )
|
||||
# print(test_page_with_template)
|
||||
# test_page_with_template.save_to_disk(False)
|
||||
# print(
|
||||
# c.create_page(
|
||||
# "~/tembo",
|
||||
# "{name}/{d:A}/{d:DD-MM-YYYY}-{d:dddd}-{d:A}",
|
||||
# "file-{input0}-{name}",
|
||||
# ".md",
|
||||
# "meeting",
|
||||
# ("last",),
|
||||
# "scratchpad_templates/scratchpad.md.tpl",
|
||||
# )
|
||||
# )
|
||||
|
||||
Reference in New Issue
Block a user