Add rolltable support, fix regions

This commit is contained in:
evilchili
2022-08-06 21:22:47 -07:00
parent 9e960cb251
commit 24a36e3096
10 changed files with 143 additions and 86 deletions
+4 -2
View File
@@ -21,10 +21,12 @@ def create(content_type: str, title: str, template_dir: str,
if not (template_path / template_name).exists():
template_name = 'default.md'
print("Not found. Using default markdown template.")
template_source = Environment(
env = Environment(
loader=FileSystemLoader(template_path),
trim_blocks=True,
).get_template(template_name)
)
env.add_extension('site_tools.extensions.RollTable')
template_source = env.get_template(template_name)
target_filename = _slugify(title) + '.md'
+13
View File
@@ -0,0 +1,13 @@
import textwrap
from rolltable.tables import RollTable as _RT
from jinja2_simple_tags import StandaloneTag
from pathlib import Path
class RollTable(StandaloneTag):
tags = {"rolltable"}
def render(self, sources, frequency='default', die=8, indent=0, **kwargs):
rt = _RT([Path(f'sources/{s}.yaml').read_text() for s in sources],
frequency=frequency, die=die)
return textwrap.indent(rt.as_yaml(), ' ' * indent)