diff --git a/docs/index.rst b/docs/index.rst index a8a9174..7908f62 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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. @@ -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! diff --git a/docs/usage.rst b/docs/usage.rst index 19a77db..624579c 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -10,7 +10,7 @@ render data. Directives ========== -.. rst:directive:: .. define:: name +.. rst:directive:: .. data.define:: name Define data and render it inplace. @@ -18,7 +18,7 @@ Directives :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 @@ -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 @@ -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:: +.. rst:directive:: .. data.schema:: 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: 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: `` @@ -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. diff --git a/src/sphinxnotes/data/__init__.py b/src/sphinxnotes/data/__init__.py index 7179d5c..3296d8f 100644 --- a/src/sphinxnotes/data/__init__.py +++ b/src/sphinxnotes/data/__init__.py @@ -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) diff --git a/tests/roots/test-smoke/index.rst b/tests/roots/test-smoke/index.rst index 777566a..be9c21b 100644 --- a/tests/roots/test-smoke/index.rst +++ b/tests/roots/test-smoke/index.rst @@ -1,7 +1,7 @@ Smoke Test ========== -.. template:: +.. data.template:: Rendered{{ name }} @@ -11,7 +11,7 @@ Smoke Test Rendered{{ content }} -.. define:: Name +.. data.define:: Name :Attr1: Value1 :Attr2: Value2 diff --git a/tests/test_smoke.py b/tests/test_smoke.py index 658f3e6..3735498 100644 --- a/tests/test_smoke.py +++ b/tests/test_smoke.py @@ -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)