Skip to content

Commit

Permalink
fiz import of custom functions module (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
purajit authored Mar 9, 2023
1 parent 6cc336e commit ecfd906
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions generate_site.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import importlib.util
import json
import logging
import os
Expand All @@ -21,7 +22,7 @@
"static_dir": f"./docs/static",
"static_url": "",
"templates_dir": "./templates",
"template_functions_module": None,
"template_functions_file": None,
}

def read_json_file(filename):
Expand Down Expand Up @@ -113,8 +114,13 @@ def create_template_env(yass_config):
template_env = Environment(
loader=FileSystemLoader(searchpath=yass_config["templates_dir"])
)
if yass_config["template_functions_module"]:
template_functions_module = __import__(yass_config["template_functions_module"])
if yass_config["template_functions_file"]:
spec = importlib.util.spec_from_file_location(
"yass_custom",
yass_config["template_functions_file"]
)
template_functions_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(template_functions_module)
for (name, component) in template_functions_module.__dict__.items():
if callable(component) and name.startswith('yass_'):
template_env.globals[name[len('yass_'):]] = component
Expand Down

0 comments on commit ecfd906

Please sign in to comment.