Skip to content

Commit

Permalink
Rename xref_formatter to type_xref_formatter (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane authored Sep 28, 2023
1 parent 8859bd1 commit 6f75c4b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sphinx_js/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def setup(app: Sphinx) -> None:
"js_source_path", default=["../"], rebuild="env", types=[str, list]
)
app.add_config_value("jsdoc_config_path", default=None, rebuild="env")
app.add_config_value("ts_xref_formatter", None, "env")
app.add_config_value("ts_type_xref_formatter", None, "env")
app.add_config_value("ts_should_destructure_arg", None, "env")
app.add_config_value("ts_post_convert", None, "env")

Expand Down
14 changes: 7 additions & 7 deletions sphinx_js/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class JsRenderer:

_renderer_type: Literal["function", "class", "attribute"]
_template: str
_xref_formatter: Callable[[TypeXRef], str]
_type_xref_formatter: Callable[[TypeXRef], str]
_partial_path: list[str]
_explicit_formal_params: str
_content: list[str]
Expand All @@ -64,17 +64,17 @@ class JsRenderer:
def _template_vars(self, name: str, obj: TopLevel) -> dict[str, Any]:
raise NotImplementedError

def _set_xref_formatter(
def _set_type_xref_formatter(
self, formatter: Callable[[Config, TypeXRef], str] | None
) -> None:
if formatter:
self._xref_formatter = partial(formatter, self._app.config)
self._type_xref_formatter = partial(formatter, self._app.config)
return

def default_xref_formatter(xref: TypeXRef) -> str:
def default_type_xref_formatter(xref: TypeXRef) -> str:
return xref.name

self._xref_formatter = default_xref_formatter
self._type_xref_formatter = default_type_xref_formatter

def __init__(
self,
Expand All @@ -90,7 +90,7 @@ def __init__(

self._directive = directive
self._app = app
self._set_xref_formatter(app.config.ts_xref_formatter)
self._set_type_xref_formatter(app.config.ts_type_xref_formatter)

# content, arguments, options, app: all need to be accessible to
# template_vars, so we bring them in on construction and stow them away
Expand Down Expand Up @@ -313,7 +313,7 @@ def strs() -> Iterator[str]:
return r"\ ".join(res)

def render_xref(self, s: TypeXRef, escape: bool = False) -> str:
result = self._xref_formatter(s)
result = self._type_xref_formatter(s)
if escape:
result = rst.escape(result)
return result
Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_ts/source/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sphinx_js.ir import TypeXRefInternal


def ts_xref_formatter(config, xref):
def ts_type_xref_formatter(config, xref):
if isinstance(xref, TypeXRefInternal):
name = rst.escape(xref.name)
return f":js:class:`{name}`"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class _app:
renderer._app = _app
renderer._explicit_formal_params = None
renderer._content = []
renderer._set_xref_formatter(ts_xref_formatter)
renderer._set_type_xref_formatter(ts_xref_formatter)
return renderer


Expand Down Expand Up @@ -246,7 +246,7 @@ def xref_render(config, val):
res.append([config, val])
return val.package + "::" + val.name

function_renderer._set_xref_formatter(xref_render)
function_renderer._set_type_xref_formatter(xref_render)
assert function_renderer.render_type([xref_external]) == "blah::A"
assert res[0][0] == function_renderer._app.config
assert res[0][1] == xref_external
Expand Down

0 comments on commit 6f75c4b

Please sign in to comment.