Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better examples #62

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions sphinx_js/templates/common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

{% macro examples(items) %}
{% if items -%}
**Examples:**
.. admonition:: Example {%- if items|length > 1 -%} s {%- endif %}

{% for example in items -%}
.. code-block:: js
{% for example in items -%}
.. code-block:: js

{{ example|indent(3) }}
{{ example|indent(6) }}

{% endfor %}
{% endfor %}
{%- endif %}
{% endmacro %}

Expand Down
6 changes: 3 additions & 3 deletions tests/test_build_js/test_build_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_autofunction_example(self):
"autofunction_example",
"exampleTag()\n\n"
" JSDoc example tag\n\n"
" **Examples:**\n\n"
" Example:\n\n"
" // This is the example.\n"
" exampleTag();\n",
)
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_autoclass_example(self):
"autoclass_example",
"class ExampleClass()\n\n"
" JSDoc example tag for class\n\n"
" **Examples:**\n\n"
" Example:\n\n"
" // This is the example.\n"
" new ExampleClass();\n",
)
Expand Down Expand Up @@ -306,7 +306,7 @@ def test_autoattribute_example(self):
"autoattribute_example",
"ExampleAttribute\n\n"
" JSDoc example tag for attribute\n\n"
" **Examples:**\n\n"
" Example:\n\n"
" // This is the example.\n"
" console.log(ExampleAttribute);\n",
)
Expand Down
44 changes: 39 additions & 5 deletions tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ def test_func_render_callouts(function_render):
)
assert function_render(examples=["ex1", "ex2"]) == DEFAULT_RESULT + setindent(
"""
**Examples:**
.. admonition:: Examples

.. code-block:: js
.. code-block:: js

ex1
ex1

.. code-block:: js
.. code-block:: js

ex2
ex2
""",
)
assert function_render(see_alsos=["see", "this too"]) == DEFAULT_RESULT + setindent(
Expand All @@ -300,3 +300,37 @@ def test_func_render_callouts(function_render):
- :any:`this too`
""",
)


def test_all(function_render):
assert function_render(
description="description",
params=[Param("a", "xx")],
deprecated=True,
exceptions=[Exc("TypeError", "")],
examples=["ex1"],
see_alsos=["see"],
) == dedent(
"""\
.. js:function:: blah(a)

.. note::

Deprecated.

description

:param a: xx
:throws TypeError:

.. admonition:: Example

.. code-block:: js

ex1

.. seealso::

- :any:`see`
"""
)
Loading