Skip to content
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 docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ Then, add the extension name to ``extensions`` configuration item in your
.. ADDITIONAL CONTENT START

Before defining any data, we need to create template using the
:rst:dir:`template` directive, to tell extension how to render the data:
:rst:dir:`data.template` directive, to tell extension how to render the data:

.. code:: rst

.. template::
.. data.template::

Hi human! I am a cat named {{ name }}, I have {{ color }} fur.

{{ content }}.

.. template::
.. data.template::

Hi human! I am a cat named {{ name }}, I have {{ color }} fur.

Expand All @@ -88,12 +88,12 @@ Before defining any data, we need to create template using the
The above template will not change the document and will just create a temporary
template for later use.

We can define data now, using a :rst:dir:`data` directive:
We can define data now, using a :rst:dir:`data.define` directive:

.. example::
:style: grid

.. data:: mimi
.. data.define:: mimi
:color: black and brown

I like fish!
Expand Down
38 changes: 18 additions & 20 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ render data.
Directives
==========

.. rst:directive:: .. define:: name
.. rst:directive:: .. data.define:: name

Define data and render it inplace.

.. rst:directive:option:: *
:type: depends on the schema

This directive uses the "freestyle" option spec, if no any
:rst:dir:`schema` applied, it allows arbitrary options to be specified.
:rst:dir:`data.schema` applied, it allows arbitrary options to be specified.
Otherwise, the option name and value is depends on the schema.

The directive generates a dict-like data structure, we call it
Expand All @@ -27,21 +27,21 @@ Directives
.. example::
:style: grid

.. define:: mimi
.. data.define:: mimi
:color: black and brown

I like fish!

The fields of data context can be restricted and customized, see
:rst:dir:`schema` for details.
:rst:dir:`data.schema` for details.

The data will be rendered by template defined by the previous
:rst:dir:`template` directive.
:rst:dir:`data.template` directive.

.. rst:directive:: template
.. rst:directive:: data.template

Define a template for rendering data. The template will be applied to
the subsequent :rst:dir:`define` directives.
the subsequent :rst:dir:`data.define` directives.

.. rst:directive:option:: on
:type: choice
Expand All @@ -65,29 +65,29 @@ Directives
.. example::
:style: grid

.. template::
.. data.template::

Hi human! I am a cat named {{ name }}, I have {{ color }} fur.

{{ content }}.

.. define:: mimi
.. data.define:: mimi
:color: black and brown

I like fish!


.. rst:directive:: .. schema:: <DSL>
.. rst:directive:: .. data.schema:: <DSL>

Define a schema for restricting data. The schema will be applid to the
subsequent :rst:dir:`define` directives.
subsequent :rst:dir:`data.define` directives.

.. rst:directive:option:: *
:type: <DSL>

This directive uses the "freestyle" option spec, which allows arbitrary
options to be specified. Each option corrsponding to an option of
:rst:dir:`define` directive.
:rst:dir:`data.define` directive.

``content: <DSL>``

Expand All @@ -97,26 +97,24 @@ Directives
.. example::
:style: grid

.. schema:: int
.. data.schema:: int

.. template::
.. data.template::

``{{ name }} + 1 = {{ name + 1 }}``

.. define:: wow
.. data.define:: 1

.. define:: 1

.. rst:directive:: render
.. rst:directive:: data.render

Render a template immediately without defining data.
This is useful when you want to render some fixed content or predefined data.

The options of this directive are same to :rst:dir`template`.
The options of this directive are same to :rst:dir`data.template`.

.. example::
:style: grid

.. render::
.. data.render::

Sphinx has **{{ _sphinx.extensions | length }}** extensions loaded.
8 changes: 4 additions & 4 deletions src/sphinxnotes/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def setup(app: Sphinx):

app.setup_extension('sphinxnotes.render')

app.add_directive('define', FreeDataDefineDirective)
app.add_directive('template', TemplateDefineDirective)
app.add_directive('schema', SchemaDefineDirective)
app.add_directive('render', DataRenderDirective)
app.add_directive('data.define', FreeDataDefineDirective)
app.add_directive('data.template', TemplateDefineDirective)
app.add_directive('data.schema', SchemaDefineDirective)
app.add_directive('data.render', DataRenderDirective)

app.connect('source-read', FreeDataDefineRoleDispatcher().install)

Expand Down
4 changes: 2 additions & 2 deletions tests/roots/test-smoke/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Smoke Test
==========

.. template::
.. data.template::

Rendered{{ name }}

Expand All @@ -11,7 +11,7 @@ Smoke Test

Rendered{{ content }}

.. define:: Name
.. data.define:: Name
:Attr1: Value1
:Attr2: Value2

Expand Down
2 changes: 1 addition & 1 deletion tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@pytest.mark.sphinx('html', testroot='smoke')
@pytest.mark.parametrize('phase', PHASES)
def test_data_template_and_define(app, status, warning, phase):
"""Test that data:template and data:define directives work correctly."""
"""Test that data.template and data.define directives work correctly."""
index_path = app.srcdir / 'index.rst'
content = index_path.read_text(encoding='utf-8')
modified_content = content.replace(':on: {phase}', f':on: {phase}', 1)
Expand Down
Loading