Skip to content

Commit

Permalink
refactor: rename autojinja in autotemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Dec 17, 2024
1 parent 765d945 commit 6beacde
Show file tree
Hide file tree
Showing 26 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ will be rendered as:
Automatic documentation
-----------------------

The ``autojinja`` directive generates Jinja reference documentation from a start comment in jinja template.
The ``autotemplate`` directive generates Jinja reference documentation from a start comment in jinja template.
Basicly it just takes `docstring` between `{#` and `#}` and inserts it where you
specified `autojinja` directive.
specified `autotemplate` directive.

To make everything work you also have to specify relative or absolute path
to your templates. If this option is not specified templates won't be displayed
Expand All @@ -68,11 +68,11 @@ the following documentation:
.. sourcecode:: rst
:caption: templates_doc.rst

.. autojinja:: sample_template.in
.. autotemplate:: sample_template.in

will be rendered as:

.. autojinja:: sample_template.in
.. autotemplate:: sample_template.in

If the path is a directory, all the templates inside this directory will be rendered.
To restrict the discovery to a subset of files, you can use the ``jinja_template_pattern`` to set a pattern to recognize template filenames.
Expand All @@ -88,7 +88,7 @@ Directives
Describes an jinja template.

.. rst:directive:: .. jinja:autojinja:: path
.. rst:directive:: .. jinja:autotemplate:: path
Reads the first comment of a file and dynamically builds a Jinja documentation.
If the path is a directory, the templates in the directory will be documented.
Expand Down
4 changes: 2 additions & 2 deletions jinja_autodoc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from sphinx.application import Sphinx
from sphinx.util.typing import ExtensionMetadata

from .autojinja import AutojinjaDirective
from .autotemplate import AutojinjaDirective
from .domain import JinjaDomain


def setup(app: Sphinx) -> ExtensionMetadata:
app.add_domain(JinjaDomain)

app.add_directive("autojinja", AutojinjaDirective)
app.add_directive("autotemplate", AutojinjaDirective)
app.add_config_value("jinja_template_path", "", "")
app.add_config_value("jinja_template_pattern", "", "")

Expand Down
8 changes: 4 additions & 4 deletions jinja_autodoc/autojinja.py → jinja_autodoc/autotemplate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""The autojinja directive.
"""The autotemplate directive.
:copyright: Copyright 2012 by Jaka Hudoklin
:license: BSD, see LICENSE for details.
Expand All @@ -16,7 +16,7 @@
from sphinx.util.nodes import nested_parse_with_titles


def autojinja_directive(path, content):
def autotemplate_directive(path, content):
content = content.splitlines() if isinstance(content, str) else content
yield ""
yield f".. jinja:template:: {path}"
Expand Down Expand Up @@ -73,14 +73,14 @@ def make_rst(self):
if env.config["jinja_template_path"]:
for docstring in docstrings:
if docstring is not None:
yield from autojinja_directive(path, docstring)
yield from autotemplate_directive(path, docstring)
yield ""

def run(self) -> list[nodes.Node]:
node = nodes.section()
node.document = self.state.document
result = StringList()
for line in self.make_rst():
result.append(line, "<autojinja>")
result.append(line, "<autotemplate>")
nested_parse_with_titles(self.state, result, node)
return node.children
4 changes: 0 additions & 4 deletions tests/roots/test-autojinja-pattern/conf.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/roots/test-autojinja-pattern/index.rst

This file was deleted.

3 changes: 0 additions & 3 deletions tests/roots/test-autojinja/conf.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/roots/test-autojinja/index.rst

This file was deleted.

1 change: 0 additions & 1 deletion tests/roots/test-autojinja/multiple_comments.rst

This file was deleted.

1 change: 0 additions & 1 deletion tests/roots/test-autojinja/templatedir.rst

This file was deleted.

4 changes: 4 additions & 0 deletions tests/roots/test-autotemplate-pattern/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project = "test-autotemplate"
extensions = ["jinja_autodoc"]
jinja_template_path = "tests/roots/test-autotemplate"
jinja_template_pattern = "^template1"
1 change: 1 addition & 0 deletions tests/roots/test-autotemplate-pattern/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. autotemplate:: templatedir
3 changes: 3 additions & 0 deletions tests/roots/test-autotemplate/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
project = "test-autotemplate"
extensions = ["jinja_autodoc"]
jinja_template_path = "tests/roots/test-autotemplate"
1 change: 1 addition & 0 deletions tests/roots/test-autotemplate/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. autotemplate:: sample_template.in
1 change: 1 addition & 0 deletions tests/roots/test-autotemplate/multiple_comments.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. autotemplate:: multiple_comments_template.in
1 change: 1 addition & 0 deletions tests/roots/test-autotemplate/templatedir.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. autotemplate:: templatedir
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from . import fmt


@pytest.mark.sphinx("html", testroot="autojinja")
@pytest.mark.sphinx("html", testroot="autotemplate")
def test_jinja_directive_html(app, status, warning, file_regression):
"""Nominal test case."""
app.builder.build_all()
Expand All @@ -14,7 +14,7 @@ def test_jinja_directive_html(app, status, warning, file_regression):
file_regression.check(role, extension=".html")


@pytest.mark.sphinx("html", testroot="autojinja")
@pytest.mark.sphinx("html", testroot="autotemplate")
def test_several_comments(app, status, warning, file_regression):
"""Test a file with several comments."""
app.builder.build_all()
Expand All @@ -24,19 +24,19 @@ def test_several_comments(app, status, warning, file_regression):
file_regression.check(role, extension=".html")


@pytest.mark.sphinx("html", testroot="autojinja")
@pytest.mark.sphinx("html", testroot="autotemplate")
def test_templatedir(app, status, warning, file_regression):
"""Test using autojinja on a directory."""
"""Test using autotemplate on a directory."""
app.builder.build_all()
html = (app.outdir / "templatedir.html").read_text(encoding="utf8")
html = BeautifulSoup(html, "html.parser")
roles = "\n".join(role.prettify(formatter=fmt) for role in html.select("dl.jinja"))
file_regression.check(roles, extension=".html")


@pytest.mark.sphinx("html", testroot="autojinja-pattern")
@pytest.mark.sphinx("html", testroot="autotemplate-pattern")
def test_file_filter(app, status, warning, file_regression):
"""Test using autojinja on a directory with a filename filter."""
"""Test using autotemplate on a directory with a filename filter."""
app.builder.build_all()
html = (app.outdir / "index.html").read_text(encoding="utf8")
html = BeautifulSoup(html, "html.parser")
Expand Down

0 comments on commit 6beacde

Please sign in to comment.