diff --git a/doc/index.rst b/doc/index.rst index efc41f1..580b9c5 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -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 @@ -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. @@ -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. diff --git a/jinja_autodoc/__init__.py b/jinja_autodoc/__init__.py index 2fd1e38..40f5d79 100644 --- a/jinja_autodoc/__init__.py +++ b/jinja_autodoc/__init__.py @@ -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", "", "") diff --git a/jinja_autodoc/autojinja.py b/jinja_autodoc/autotemplate.py similarity index 92% rename from jinja_autodoc/autojinja.py rename to jinja_autodoc/autotemplate.py index 0278113..b168240 100644 --- a/jinja_autodoc/autojinja.py +++ b/jinja_autodoc/autotemplate.py @@ -1,4 +1,4 @@ -"""The autojinja directive. +"""The autotemplate directive. :copyright: Copyright 2012 by Jaka Hudoklin :license: BSD, see LICENSE for details. @@ -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}" @@ -73,7 +73,7 @@ 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]: @@ -81,6 +81,6 @@ def run(self) -> list[nodes.Node]: node.document = self.state.document result = StringList() for line in self.make_rst(): - result.append(line, "") + result.append(line, "") nested_parse_with_titles(self.state, result, node) return node.children diff --git a/tests/roots/test-autojinja-pattern/conf.py b/tests/roots/test-autojinja-pattern/conf.py deleted file mode 100644 index e9acdf0..0000000 --- a/tests/roots/test-autojinja-pattern/conf.py +++ /dev/null @@ -1,4 +0,0 @@ -project = "test-autojinja" -extensions = ["jinja_autodoc"] -jinja_template_path = "tests/roots/test-autojinja" -jinja_template_pattern = "^template1" diff --git a/tests/roots/test-autojinja-pattern/index.rst b/tests/roots/test-autojinja-pattern/index.rst deleted file mode 100644 index 0f23449..0000000 --- a/tests/roots/test-autojinja-pattern/index.rst +++ /dev/null @@ -1 +0,0 @@ -.. autojinja:: templatedir diff --git a/tests/roots/test-autojinja/conf.py b/tests/roots/test-autojinja/conf.py deleted file mode 100644 index dab70e8..0000000 --- a/tests/roots/test-autojinja/conf.py +++ /dev/null @@ -1,3 +0,0 @@ -project = "test-autojinja" -extensions = ["jinja_autodoc"] -jinja_template_path = "tests/roots/test-autojinja" diff --git a/tests/roots/test-autojinja/index.rst b/tests/roots/test-autojinja/index.rst deleted file mode 100644 index 53200bb..0000000 --- a/tests/roots/test-autojinja/index.rst +++ /dev/null @@ -1 +0,0 @@ -.. autojinja:: sample_template.in diff --git a/tests/roots/test-autojinja/multiple_comments.rst b/tests/roots/test-autojinja/multiple_comments.rst deleted file mode 100644 index f334caf..0000000 --- a/tests/roots/test-autojinja/multiple_comments.rst +++ /dev/null @@ -1 +0,0 @@ -.. autojinja:: multiple_comments_template.in diff --git a/tests/roots/test-autojinja/templatedir.rst b/tests/roots/test-autojinja/templatedir.rst deleted file mode 100644 index 0f23449..0000000 --- a/tests/roots/test-autojinja/templatedir.rst +++ /dev/null @@ -1 +0,0 @@ -.. autojinja:: templatedir diff --git a/tests/roots/test-autotemplate-pattern/conf.py b/tests/roots/test-autotemplate-pattern/conf.py new file mode 100644 index 0000000..15d46dc --- /dev/null +++ b/tests/roots/test-autotemplate-pattern/conf.py @@ -0,0 +1,4 @@ +project = "test-autotemplate" +extensions = ["jinja_autodoc"] +jinja_template_path = "tests/roots/test-autotemplate" +jinja_template_pattern = "^template1" diff --git a/tests/roots/test-autotemplate-pattern/index.rst b/tests/roots/test-autotemplate-pattern/index.rst new file mode 100644 index 0000000..ab8a5e7 --- /dev/null +++ b/tests/roots/test-autotemplate-pattern/index.rst @@ -0,0 +1 @@ +.. autotemplate:: templatedir diff --git a/tests/roots/test-autojinja-pattern/templatedir/template1.in b/tests/roots/test-autotemplate-pattern/templatedir/template1.in similarity index 100% rename from tests/roots/test-autojinja-pattern/templatedir/template1.in rename to tests/roots/test-autotemplate-pattern/templatedir/template1.in diff --git a/tests/roots/test-autojinja-pattern/templatedir/template2.in b/tests/roots/test-autotemplate-pattern/templatedir/template2.in similarity index 100% rename from tests/roots/test-autojinja-pattern/templatedir/template2.in rename to tests/roots/test-autotemplate-pattern/templatedir/template2.in diff --git a/tests/roots/test-autotemplate/conf.py b/tests/roots/test-autotemplate/conf.py new file mode 100644 index 0000000..13e0b45 --- /dev/null +++ b/tests/roots/test-autotemplate/conf.py @@ -0,0 +1,3 @@ +project = "test-autotemplate" +extensions = ["jinja_autodoc"] +jinja_template_path = "tests/roots/test-autotemplate" diff --git a/tests/roots/test-autotemplate/index.rst b/tests/roots/test-autotemplate/index.rst new file mode 100644 index 0000000..c3d3356 --- /dev/null +++ b/tests/roots/test-autotemplate/index.rst @@ -0,0 +1 @@ +.. autotemplate:: sample_template.in diff --git a/tests/roots/test-autotemplate/multiple_comments.rst b/tests/roots/test-autotemplate/multiple_comments.rst new file mode 100644 index 0000000..c24afee --- /dev/null +++ b/tests/roots/test-autotemplate/multiple_comments.rst @@ -0,0 +1 @@ +.. autotemplate:: multiple_comments_template.in diff --git a/tests/roots/test-autojinja/multiple_comments_template.in b/tests/roots/test-autotemplate/multiple_comments_template.in similarity index 100% rename from tests/roots/test-autojinja/multiple_comments_template.in rename to tests/roots/test-autotemplate/multiple_comments_template.in diff --git a/tests/roots/test-autojinja/sample_template.in b/tests/roots/test-autotemplate/sample_template.in similarity index 100% rename from tests/roots/test-autojinja/sample_template.in rename to tests/roots/test-autotemplate/sample_template.in diff --git a/tests/roots/test-autotemplate/templatedir.rst b/tests/roots/test-autotemplate/templatedir.rst new file mode 100644 index 0000000..ab8a5e7 --- /dev/null +++ b/tests/roots/test-autotemplate/templatedir.rst @@ -0,0 +1 @@ +.. autotemplate:: templatedir diff --git a/tests/roots/test-autojinja/templatedir/template1.in b/tests/roots/test-autotemplate/templatedir/template1.in similarity index 100% rename from tests/roots/test-autojinja/templatedir/template1.in rename to tests/roots/test-autotemplate/templatedir/template1.in diff --git a/tests/roots/test-autojinja/templatedir/template2.in b/tests/roots/test-autotemplate/templatedir/template2.in similarity index 100% rename from tests/roots/test-autojinja/templatedir/template2.in rename to tests/roots/test-autotemplate/templatedir/template2.in diff --git a/tests/test_autojinja_directive.py b/tests/test_autotemplate_directive.py similarity index 81% rename from tests/test_autojinja_directive.py rename to tests/test_autotemplate_directive.py index 70085f6..0b2cad6 100644 --- a/tests/test_autojinja_directive.py +++ b/tests/test_autotemplate_directive.py @@ -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() @@ -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() @@ -24,9 +24,9 @@ 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") @@ -34,9 +34,9 @@ def test_templatedir(app, status, warning, file_regression): 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") diff --git a/tests/test_autojinja_directive/test_file_filter.html b/tests/test_autotemplate_directive/test_file_filter.html similarity index 100% rename from tests/test_autojinja_directive/test_file_filter.html rename to tests/test_autotemplate_directive/test_file_filter.html diff --git a/tests/test_autojinja_directive/test_jinja_directive_html.html b/tests/test_autotemplate_directive/test_jinja_directive_html.html similarity index 100% rename from tests/test_autojinja_directive/test_jinja_directive_html.html rename to tests/test_autotemplate_directive/test_jinja_directive_html.html diff --git a/tests/test_autojinja_directive/test_several_comments.html b/tests/test_autotemplate_directive/test_several_comments.html similarity index 100% rename from tests/test_autojinja_directive/test_several_comments.html rename to tests/test_autotemplate_directive/test_several_comments.html diff --git a/tests/test_autojinja_directive/test_templatedir.html b/tests/test_autotemplate_directive/test_templatedir.html similarity index 100% rename from tests/test_autojinja_directive/test_templatedir.html rename to tests/test_autotemplate_directive/test_templatedir.html