Skip to content

Commit

Permalink
feat: Support nested assets directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisaha committed Feb 19, 2024
1 parent 9e833db commit a2f5061
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions weasyprint_rest/print/weasyprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def _fix_file_option(options, base_dir, option_name):
options[option_name] = base_dir + options[option_name]


def create_directory_if_not_present(file_path):
directory = os.path.dirname(file_path)
if not os.path.exists(directory):
os.makedirs(directory)


class WeasyPrinter:

def __init__(self, html=None, url=None, template=None):
Expand Down Expand Up @@ -88,10 +94,12 @@ def _prepare_base_dir(self):

if self.template.base_template is not None:
for asset in self.template.base_template.assets:
create_directory_if_not_present(base_dir + asset)
self.template.get_asset(asset).save(base_dir + asset)

for asset in self.template.assets:
if not os.path.exists(base_dir + asset):
create_directory_if_not_present(base_dir + asset)
self.template.get_asset(asset).save(base_dir + asset)

return base_dir
Expand Down

0 comments on commit a2f5061

Please sign in to comment.