Skip to content

Commit

Permalink
Add user static dir option
Browse files Browse the repository at this point in the history
  • Loading branch information
amykyta3 committed Sep 2, 2019
1 parent 9d2a2ae commit e112447
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Constructor for the HTML exporter class
for more details.
* `user_template_dir`
* Path to a directory where user-defined template overrides are stored.
* `user_static_dir`
* Path to user-defined static content to copy to output directory.
* `user_context`
* Additional context variables to load into the template namespace.

Expand Down
10 changes: 9 additions & 1 deletion ralbot/html/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from systemrdl.node import RootNode, AddressableNode, RegNode, RegfileNode, AddrmapNode, MemNode

class HTMLExporter:
def __init__(self, markdown_inst=None, user_template_dir=None, user_context={}):
def __init__(self, markdown_inst=None, user_template_dir=None, user_static_dir=None, user_context=None):
"""
Constructor for the HTML exporter class
Expand All @@ -26,6 +26,8 @@ def __init__(self, markdown_inst=None, user_template_dir=None, user_context={}):
for more details.
user_template_dir: str
Path to a directory where user-defined template overrides are stored.
user_static_dir: str
Path to user-defined static content to copy to output directory.
user_context: dict
Additional context variables to load into the template namespace.
"""
Expand All @@ -35,6 +37,10 @@ def __init__(self, markdown_inst=None, user_template_dir=None, user_context={}):
self.footer = None
self.title = None
self.home_url = None
self.user_static_dir = user_static_dir

if user_context is None:
user_context = {}
self.user_context = user_context

if markdown_inst is None:
Expand Down Expand Up @@ -95,6 +101,8 @@ def export(self, node, output_dir, **kwargs):
# Copy static files
static_dir = os.path.join(os.path.dirname(__file__), "static")
distutils.dir_util.copy_tree(static_dir, self.output_dir, preserve_mode=0, preserve_times=0)
if self.user_static_dir:
distutils.dir_util.copy_tree(self.user_static_dir, self.output_dir, preserve_mode=0, preserve_times=0)

# Make sure output directory structure exists
os.makedirs(self.output_dir, exist_ok=True)
Expand Down

0 comments on commit e112447

Please sign in to comment.