Add rolltable support, fix regions
This commit is contained in:
@@ -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'
|
||||
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user