MkConfigSetting

github Show source on GitHub

Node for describing a config setting.

Example: YAML format

Jinja

{{ "path" | MkConfigSetting(mode="yaml",
                            setting={"plugins": {"mknodes": {"path": "path.to.module"}}},
                            description="Some **markdown** to describe the setting",
                            default="path.to.module")}}

Python

MkConfigSetting(
    "path",
    "Some **markdown** to describe the setting",
    setting={"plugins": {"mknodes": {"path": "path.to.module"}}},
    default="path.to.module",
)

**path**

Default: 'path.to.module'

Some markdown to describe the setting

plugins:
  mknodes:
    path: path.to.module
`**path**`
:   Default: `'path.to.module'`

    Some **markdown** to describe the setting

    ````yaml
    plugins:
      mknodes:
        path: path.to.module

    ````
<dl>
<dt><code>**path**</code></dt>
<dd>
<p>Default: <code>'path.to.module'</code></p>
<p>Some <strong>markdown</strong> to describe the setting</p>
<pre><code class="language-yaml">plugins:
  mknodes:
    path: path.to.module

</code></pre>
</dd>
</dl>
MkConfigSetting
╰── MkCode(None, language='yaml')
    ╰── MkText('plugins:\n  mknodes:\n    path: path.to.module\n')

Example: JSON format

Jinja

{{ "path" | MkConfigSetting(mode="json",
                            setting={"plugins": {"mknodes": {"path": "path.to.module"}}},
                            description="Some **markdown** to describe the setting",
                            default="path.to.module")}}

Python

MkConfigSetting(
    "path",
    "Some **markdown** to describe the setting",
    setting={"plugins": {"mknodes": {"path": "path.to.module"}}},
    default="path.to.module",
    mode="json",
)

**path**

Default: 'path.to.module'

Some markdown to describe the setting

{
  "plugins": {
    "mknodes": {
      "path": "path.to.module"
    }
  }
}
`**path**`
:   Default: `'path.to.module'`

    Some **markdown** to describe the setting

    ````json
    {
      "plugins": {
        "mknodes": {
          "path": "path.to.module"
        }
      }
    }
    ````
<dl>
<dt><code>**path**</code></dt>
<dd>
<p>Default: <code>'path.to.module'</code></p>
<p>Some <strong>markdown</strong> to describe the setting</p>
<pre><code class="language-json">{
  &quot;plugins&quot;: {
    &quot;mknodes&quot;: {
      &quot;path&quot;: &quot;path.to.module&quot;
    }
  }
}
</code></pre>
</dd>
</dl>
MkConfigSetting
╰── MkCode(None, language='json')
    ╰── MkText('{\n  "plugins": {\n    "mknodes": {\n      "path": "path.to.module"\n    }\n  }\n}')

Example: TOML format

Jinja

{{ "path" | MkConfigSetting(mode="toml",
                            setting={"plugins": {"mknodes": {"path": "path.to.module"}}},
                            description="Some **markdown** to describe the setting",
                            default="path.to.module")}}

Python

MkConfigSetting(
    "path",
    "Some **markdown** to describe the setting",
    setting={"plugins": {"mknodes": {"path": "path.to.module"}}},
    default="path.to.module",
    mode="toml",
)

**path**

Default: 'path.to.module'

Some markdown to describe the setting

[plugins.mknodes]
path = "path.to.module"
`**path**`
:   Default: `'path.to.module'`

    Some **markdown** to describe the setting

    ````toml
    [plugins.mknodes]
    path = "path.to.module"

    ````
<dl>
<dt><code>**path**</code></dt>
<dd>
<p>Default: <code>'path.to.module'</code></p>
<p>Some <strong>markdown</strong> to describe the setting</p>
<pre><code class="language-toml">[plugins.mknodes]
path = &quot;path.to.module&quot;

</code></pre>
</dd>
</dl>
MkConfigSetting
╰── MkCode(None, language='toml')
    ╰── MkText('[plugins.mknodes]\npath = "path.to.module"\n')

class MkConfigSetting(mktemplate.MkTemplate)
graph TD
  1561279813["mkconfigsetting.MkConfigSetting"]
  1289759389["mktemplate.MkTemplate"]
  3160803176["rendercache.TemplateRenderMixin"]
  2751680898["builtins.object"]
  835538629["mkcontainer.MkContainer"]
  1956333208["mkcontainer.MkContainerBase"]
  1359323199["mknode.MkNode"]
  1289759389 --> 1561279813
  3160803176 --> 1289759389
  2751680898 --> 3160803176
  835538629 --> 1289759389
  1956333208 --> 835538629
  1359323199 --> 1956333208
  2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/templatenodes/mkconfigsetting/metadata.toml
[metadata]
name = "MkConfigSetting"
icon = "mdi:library"
virtual_children = true

[requirements.extension.def_list]

[examples.yaml]
title = "YAML format"
jinja = """
{{ "path" | MkConfigSetting(mode="yaml",
                            setting={"plugins": {"mknodes": {"path": "path.to.module"}}},
                            description="Some **markdown** to describe the setting",
                            default="path.to.module")}}
"""

[examples.json]
title = "JSON format"
jinja = """
{{ "path" | MkConfigSetting(mode="json",
                            setting={"plugins": {"mknodes": {"path": "path.to.module"}}},
                            description="Some **markdown** to describe the setting",
                            default="path.to.module")}}
"""

[examples.toml]
title = "TOML format"
jinja = """
{{ "path" | MkConfigSetting(mode="toml",
                            setting={"plugins": {"mknodes": {"path": "path.to.module"}}},
                            description="Some **markdown** to describe the setting",
                            default="path.to.module")}}
"""

[output.markdown]
template = """
{{ node.title | md_style(bold=True, code=True) }}
:   {% filter indent %}Default: `{{ node.default | repr }}`

{% if node.version_added %}
Version added: `{{ node.version_added }}`

{% endif %}
{% if node.optional is not none %}
Required: `{{ "yes" if node.required else "no" }}`

{% endif %}
{{ node.description }}


{% if node.setting is instance(dict) %}
{{ node.setting | serialize(node.mode) | MkCode(language=node.mode) }}
{% else %}
{{ node.setting | MkCode(language=node.mode) }}
{% endif %}
{% endfilter %}
"""
mknodes.templatenodes.mkconfigsetting.MkConfigSetting
 9class MkConfigSetting(mktemplate.MkTemplate):
10    """Node for describing a config setting."""
11
12    ICON = "material/library"
13
14    def __init__(
15        self,
16        title: str,
17        description: str,
18        *,
19        setting: dict[str, Any] | str | None = None,
20        default: str | int | None = None,
21        version_added: str | None = None,
22        optional: bool | None = None,
23        mode: superdict.MarkupTypeStr = "yaml",
24        **kwargs: Any,
25    ) -> None:
26        """Constructor.
27
28        Args:
29            title: Setting title
30            description: Setting description
31            setting: (Nested) json-like object representing the setting
32            default: Default setting value
33            version_added: Version added
34            optional: Whether setting is optional. (None hides the label)
35            mode: Markup language of settings file
36            kwargs: Keyword arguments passed to parent
37        """
38        super().__init__("output/markdown/template", **kwargs)
39        self.title = title
40        self.setting = setting
41        self.default = default
42        self.version_added = version_added
43        self.description = description
44        self.optional = optional
45        self.mode = mode
Page info
Code for this page
mknodes.manual.nodes_section.create_section_for_nodes
 93def create_section_for_nodes(
 94    nav: mk.MkNav,
 95    klasses: Sequence[type[mk.MkNode]],
 96) -> mk.MkTable:
 97    table = mk.MkTable(columns=["Node", "Docstrings", "Markdown extensions"])
 98    for kls in klasses:
 99        tpl = "classpage_custom.jinja"
100        page = mk.MkClassPage(kls, icon=kls.ICON, template_path=tpl, parent=nav, hide="toc")
101        nav += page
102        if kls.STATUS:
103            page.metadata.status = kls.STATUS
104        elif kls.JS_FILES:
105            page.metadata.status = "js"
106        elif kls.CSS:
107            page.metadata.status = "css"
108        page.created_by = create_section_for_nodes
109        link = mk.MkLink(page, kls.__name__, icon=kls.ICON)
110        extensions = ", ".join(f"`{i}`" for i in kls.REQUIRED_EXTENSIONS)
111        table.add_row((link, kls.__doc__, extensions))
112    return table
Resources
Resources(css=[],
          markdown_extensions={'admonition': {},
                               'pymdownx.details': {},
                               'pymdownx.highlight': {'anchor_linenums': True,
                                                      'line_spans': '__span',
                                                      'pygments_lang_class': True},
                               'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
                                                                           'format': <function fence_code_format at 0x7ff77e88b060>,
                                                                           'name': 'mermaid'}]},
                               'pymdownx.tabbed': {},
                               'tables': {}},
          plugins=[Plugin('mkdocstrings')],
          js=[],
          assets=[],
          packages=[])
Metadata
created:
  source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/nodes_section.py
  source_function: create_section_for_nodes
  source_line_no: 93
hide:
- toc
icon: material/library
status: new
title: MkConfigSetting