Skip to content

Commit

Permalink
Rename invokePyPage parameter fileNode to pyPageNode
Browse files Browse the repository at this point in the history
  • Loading branch information
arjun-menon committed Jul 25, 2024
1 parent e57a2cb commit 46f8584
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions alteza/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,39 +88,41 @@ def linkObj(self, srcFile: PyPageNode, dstFile: FileNode) -> str:

return relativePathStr

def invokePyPage(self, fileNode: PyPageNode, env: dict[str, Any]) -> None:
print(f"{Fore.gold_1}Processing:{Style.reset}", fileNode.fullPath)
def invokePyPage(self, pyPageNode: PyPageNode, env: dict[str, Any]) -> None:
print(f"{Fore.gold_1}Processing:{Style.reset}", pyPageNode.fullPath)
env = env.copy()

# Enrich with current file:
env |= {"file": fileNode}
env |= {"file": pyPageNode}

toProcessFurther: str
if isinstance(fileNode, (Md, NonMd)):
toProcessFurther = Fs.readfile(fileNode.absoluteFilePath)
if isinstance(pyPageNode, (Md, NonMd)):
toProcessFurther = Fs.readfile(pyPageNode.absoluteFilePath)
else:
raise AltezaException(f"{fileNode} Unsupported type of PyPageNode.")
raise AltezaException(f"{pyPageNode} Unsupported type of PyPageNode.")

def link(name: str) -> str:
dstFile: FileNode = self.nameRegistry.lookup(name)
return self.linkObj(fileNode, dstFile)
return self.linkObj(pyPageNode, dstFile)

def linkObj(dstFile: FileNode) -> str:
return self.linkObj(fileNode, dstFile)
return self.linkObj(pyPageNode, dstFile)

env |= {"link": link}
env |= {"linkObj": linkObj}

env |= {"lastUpdatedObj": fileNode.lastUpdated}
env |= {"lastUpdatedObj": pyPageNode.lastUpdated}
# The formatting below might only work on Linux. https://stackoverflow.com/a/29980406/908430
env |= {"lastUpdated": fileNode.lastUpdated.strftime("%Y %b %-d at %-H:%M %p")}
env |= {
"lastUpdated": pyPageNode.lastUpdated.strftime("%Y %b %-d at %-H:%M %p")
}

if isinstance(fileNode, Md):
env |= {"ideaDateObj": fileNode.ideaDate}
if isinstance(pyPageNode, Md):
env |= {"ideaDateObj": pyPageNode.ideaDate}
env |= {
"ideaDate": (
fileNode.ideaDate.strftime("%Y %b %-d at %-H:%M %p")
if fileNode.ideaDate is not None
pyPageNode.ideaDate.strftime("%Y %b %-d at %-H:%M %p")
if pyPageNode.ideaDate is not None
else ""
)
}
Expand All @@ -129,18 +131,18 @@ def linkObj(dstFile: FileNode) -> str:
pyPageOutput = pypage(toProcessFurther, env)

# Perform Markdown processing
if isinstance(fileNode, Md):
if isinstance(pyPageNode, Md):
mdResult = Md.processMarkdown(pyPageOutput)
env.update(mdResult.metadata)
pyPageOutput = mdResult.html

if "public" in env:
if env["public"] is True:
fileNode.makePublic()
pyPageNode.makePublic()
elif env["public"] is False:
fileNode.shouldPublish = False
pyPageNode.shouldPublish = False

if isinstance(fileNode, Md):
if isinstance(pyPageNode, Md):
print(
f" {Fore.purple_3}Applying template...{Style.reset}"
) # TODO (see ideas.md)
Expand All @@ -150,8 +152,8 @@ def linkObj(dstFile: FileNode) -> str:
pyPageOutput = pypage(templateHtml, env | {"content": pyPageOutput})
self.indentSpaces = 2

fileNode.setPyPageOutput(pyPageOutput)
fileNode.env = env
pyPageNode.setPyPageOutput(pyPageOutput)
pyPageNode.env = env

def process(self) -> None:
def walk(dirNode: DirNode, env: dict[str, Any]) -> None:
Expand Down

0 comments on commit 46f8584

Please sign in to comment.