Skip to content

Commit

Permalink
refactor: minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Dec 17, 2024
1 parent 36e25f7 commit ecba2dc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions jinja_autodoc/autotemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,19 @@ def autotemplate_directive(path, content):
yield ""


def parse_templates(
def parse_template_paths(
path: str, filename_filter: Optional[str] = None
) -> list[Optional[str]]:
if not os.path.isdir(path):
return [parse_jinja_comment(path)]
return [path]

filepath_collections = [
os.path.join(dirpath, filename)
for dirpath, _, filenames in os.walk(path)
for filename in filenames
if (not filename_filter or re.match(filename_filter, filename))
]
template_paths = itertools.chain(filepath_collections)
return [parse_jinja_comment(path) for path in template_paths]
return list(itertools.chain(filepath_collections))


def parse_jinja_comment(path: str) -> Optional[str]:
Expand All @@ -63,12 +62,15 @@ class AutojinjaDirective(Directive):
def make_rst(self):
env = self.state.document.settings.env
path = self.arguments[0]
raw_docstrings = parse_templates(
os.path.join(env.config["jinja_template_path"], path),
env.config["jinja_template_pattern"],
root_path = os.path.join(env.config["jinja_template_path"], path)
template_paths = parse_template_paths(
root_path, env.config["jinja_template_pattern"]
)
raw_docstrings = [parse_jinja_comment(path) for path in template_paths]
docstrings = [
prepare_docstring(raw_docstring) for raw_docstring in raw_docstrings
prepare_docstring(raw_docstring)
for raw_docstring in raw_docstrings
if raw_docstring is not None
]
if env.config["jinja_template_path"]:
for docstring in docstrings:
Expand Down

0 comments on commit ecba2dc

Please sign in to comment.