Skip to content

Commit 08eb94c

Browse files
authored
Merge pull request #7 from sphinx-notes/autodocs-improvement
Detailed API docs
2 parents d8822f7 + fc99b7b commit 08eb94c

File tree

23 files changed

+415
-232
lines changed

23 files changed

+415
-232
lines changed

.cruft.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "https://github.com/sphinx-notes/cookiecutter",
3-
"commit": "62cd96195962da3392cdc34125c95e9144a5f5ca",
3+
"commit": "4c6b17aec1a4b8ddca95c4882c6bed2bc230d595",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {
@@ -20,7 +20,7 @@
2020
"sphinx_version": "7.0",
2121
"development_status": "3 - Alpha",
2222
"_template": "https://github.com/sphinx-notes/cookiecutter",
23-
"_commit": "62cd96195962da3392cdc34125c95e9144a5f5ca"
23+
"_commit": "4c6b17aec1a4b8ddca95c4882c6bed2bc230d595"
2424
}
2525
},
2626
"directory": null

docs/api.rst

Lines changed: 116 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,151 @@
1-
=============
2-
API Reference
3-
=============
1+
==============
2+
API References
3+
==============
44

5-
Data Types
6-
==========
5+
The Render Pipeline
6+
===================
77

8-
.. autotype:: sphinxnotes.render.PlainValue
9-
.. autotype:: sphinxnotes.render.Value
8+
The pipeline defines how nodes carrying data are generated and when they are
9+
rendered as part of the document.
1010

11-
.. autoclass:: sphinxnotes.render.RawData
12-
.. autoclass:: sphinxnotes.render.ParsedData
11+
1. Generation: :py:class:`~sphinxnotes.render.BaseContextRole`,
12+
:py:class:`~sphinxnotes.render.BaseContextDirective` and their subclasses
13+
create :py:class:`~sphinxnotes.render.pending_node` on document parsing,
14+
and the node will be inserted to the document tree. The node contains:
1315

14-
.. autoclass:: sphinxnotes.render.Field
15-
.. autoclass:: sphinxnotes.render.Schema
16+
- :ref:`context`, the dynamic content of a Jinja template
1617

17-
.. autoclass:: sphinxnotes.render.data.Registry
18+
- :py:class:`~sphinxnotes.render.Template`,
19+
the Jinja template for rendering context to markup text
20+
(reStructuredText or Markdown)
1821

19-
.. automethod:: add_type
20-
.. automethod:: add_form
21-
.. automethod:: add_flag
22-
.. automethod:: add_by_option
22+
2. Render: the ``pending_node`` node will be rendered at the appropriate
23+
:py:class:`~sphinxnotes.render.Phase`, depending on
24+
:py:attr:`~sphinxnotes.render.pending_node.template.phase`.
2325

24-
.. autotype:: sphinxnotes.render.data.ByOptionStore
26+
Node
27+
-----
2528

26-
The Render Pipeline
27-
===================
29+
.. autoclass:: sphinxnotes.render.pending_node
30+
31+
.. _context:
2832

2933
Context
3034
-------
3135

32-
.. autoclass:: sphinxnotes.render.PendingContext
36+
Context refers to the dynamic content of a Jinja template. It can be:
37+
38+
:py:class:`~sphinxnotes.render.ResolvedContext`:
39+
Our dedicated data type (:py:class:`sphinxnotes.render.ParsedData`), or any
40+
Python ``dict``.
41+
42+
:py:class:`~sphinxnotes.render.PendingContext`:
43+
Context that is not yet available. For example, it may contain
44+
:py:class:`unparsed data <sphinxnotes.render.RawData>`,
45+
remote data, and more.
46+
47+
:py:class:`PendingContext` can be resolved to
48+
:py:class:`~sphinxnotes.render.ResolvedContext` by calling
49+
:py:meth:`~sphinxnotes.render.PendingContext.resolve`.
50+
3351
.. autotype:: sphinxnotes.render.ResolvedContext
34-
.. autoclass:: sphinxnotes.render.UnparsedData
3552

36-
.. autoclass:: sphinxnotes.render.pending_node
53+
.. autoclass:: sphinxnotes.render.PendingContext
54+
:members: resolve
3755

38-
Extra Context
39-
-------------
56+
``PendingContext`` Implementations
57+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4058

41-
.. autoclass:: sphinxnotes.render.ExtraContextGenerator
42-
.. autoclass:: sphinxnotes.render.ExtraContextRegistry
59+
.. autoclass:: sphinxnotes.render.UnparsedData
60+
:show-inheritance:
61+
62+
.. _extractx:
4363

4464
Template
4565
--------
4666

4767
.. autoclass:: sphinxnotes.render.Template
68+
:members:
69+
4870
.. autoclass:: sphinxnotes.render.Phase
71+
:members:
4972

50-
Pipeline
51-
--------
73+
Extra Context
74+
-------------
75+
76+
.. autoclass:: sphinxnotes.render.GlobalExtraContxt
77+
78+
.. autoclass:: sphinxnotes.render.ParsePhaseExtraContext
79+
80+
.. autoclass:: sphinxnotes.render.ResolvePhaseExtraContext
81+
82+
.. autoclass:: sphinxnotes.render.ExtraContextRegistry
83+
:members:
84+
85+
86+
Base Roles and Directives
87+
-------------------------
88+
89+
Base Role Classes
90+
~~~~~~~~~~~~~~~~~
5291

5392
.. autoclass:: sphinxnotes.render.BaseContextRole
54-
.. autoclass:: sphinxnotes.render.BaseContextDirective
93+
:show-inheritance:
94+
:members: process_pending_node, queue_pending_node, queue_context, current_context, current_template
95+
5596
.. autoclass:: sphinxnotes.render.BaseDataDefineRole
97+
:show-inheritance:
98+
:members: process_pending_node, queue_pending_node, queue_context, current_schema, current_template
99+
100+
Base Directive Classes
101+
~~~~~~~~~~~~~~~~~~~~~~
102+
103+
.. autoclass:: sphinxnotes.render.BaseContextDirective
104+
:show-inheritance:
105+
:members: process_pending_node, queue_pending_node, queue_context, current_context, current_template
106+
56107
.. autoclass:: sphinxnotes.render.BaseDataDefineDirective
108+
:show-inheritance:
109+
:members: process_pending_node, queue_pending_node, queue_context, current_schema, current_template
110+
57111
.. autoclass:: sphinxnotes.render.StrictDataDefineDirective
112+
:show-inheritance:
113+
:members: derive
114+
115+
Data, Field and Schema
116+
======================
117+
118+
.. autotype:: sphinxnotes.render.PlainValue
119+
120+
.. autotype:: sphinxnotes.render.Value
121+
122+
.. autoclass:: sphinxnotes.render.RawData
123+
:members: name, attrs, content
124+
:undoc-members:
125+
126+
.. autoclass:: sphinxnotes.render.ParsedData
127+
:members: name, attrs, content
128+
:undoc-members:
129+
130+
.. autoclass:: sphinxnotes.render.Field
131+
:members: parse
132+
133+
.. autoclass:: sphinxnotes.render.Schema
134+
:members: name, attrs, content
135+
:undoc-members:
136+
137+
.. autoclass:: sphinxnotes.render.data.Registry
138+
:members:
139+
140+
.. autotype:: sphinxnotes.render.data.ByOptionStore
58141

59142
Registry
60143
========
61144

145+
Developers can extend this extension (for example, to support more data types
146+
or add new extra context) by adding new items to
147+
:py:class:`sphinxnotes.render.REGISTRY`.
148+
62149
.. autodata:: sphinxnotes.render.REGISTRY
63150

64151
.. autoclass:: sphinxnotes.render.Registry

docs/conf.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
extensions = [
2525
'sphinx.ext.githubpages',
2626
'sphinx.ext.doctest',
27+
'sphinx.ext.viewcode',
2728
'sphinx_design',
2829
'sphinx_copybutton',
2930
'sphinx_last_updated_by_git',
@@ -118,12 +119,17 @@
118119
# documentation root, use os.path.abspath to make it absolute, like shown here.
119120
import os
120121
import sys
121-
sys.path.insert(0, os.path.abspath('../src/sphinxnotes'))
122-
extensions.append('render')
122+
sys.path.insert(0, os.path.abspath('../src/'))
123+
extensions.append('sphinxnotes.render')
123124

124125
# CUSTOM CONFIGURATION
125126

126-
_ = extensions.pop() # no need to load extension
127-
primary_domain = 'py'
127+
autodoc_default_options = {
128+
'member-order': 'bysource',
129+
}
130+
131+
intersphinx_mapping['python'] = ('https://docs.python.org/3', None)
132+
intersphinx_mapping['sphinx'] = ('https://www.sphinx-doc.org/en/master', None)
128133

129-
extensions.append('sphinx.ext.doctest')
134+
def setup(app):
135+
app.add_object_type('event', 'event') # for intersphinx

docs/dsl.rst

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
1-
=====================
2-
Field Declaration DSL
3-
=====================
1+
==========================
2+
Field Description Language
3+
==========================
44

55
.. default-domain:: py
66
.. highlight:: python
77
.. role:: py(code)
88
:language: Python
99

1010

11-
The Field Declaration DSL is a Domain Specific Language (DSL) that used to
12-
define the type and structure of field values. A DSL declaration consists of
13-
one or more :term:`modifier`\ s separated by commas (``,``).
14-
15-
Python API
16-
==========
17-
18-
User can create a :class:`sphinxnotes.render.Field` from DSL and use it to parse
19-
string to :type:`sphinxnotes.render.Value`:
20-
21-
>>> from sphinxnotes.render import Field
22-
>>> Field.from_dsl('list of int').parse('1,2,3')
23-
[1, 2, 3]
11+
The Field Description Language is a Domain Specific Language (DSL) that is used to
12+
define the type and structure of field values. An FDL declaration consists of
13+
one or more :term:`modifier` entries separated by commas (``,``).
2414

2515
Syntax
2616
======
@@ -34,17 +24,28 @@ Syntax
3424
Modifier
3525
There are four categories of modifiers:
3626

37-
Type modifier
38-
Specifies the element type (scalar value)
27+
Type modifier
28+
Specifies the element type (scalar value)
29+
30+
Form modifier
31+
Specifies a container type with element type
3932

40-
Form modifier
41-
Specifies a container type with element type
33+
Flag
34+
A boolean flag (either on or off)
4235

43-
Flag
44-
A boolean flag (either on or off)
36+
By-Option
37+
A key-value option
38+
39+
Python API
40+
==========
41+
42+
Users can create a :class:`sphinxnotes.render.Field` from FDL and use it to parse
43+
strings into :type:`sphinxnotes.render.Value`:
44+
45+
>>> from sphinxnotes.render import Field
46+
>>> Field.from_dsl('list of int').parse('1,2,3')
47+
[1, 2, 3]
4548

46-
By-Option
47-
A key-value option
4849

4950
Type
5051
====
@@ -73,7 +74,7 @@ A type modifier specifies the data type of a single (scalar) value.
7374
* - ``str``
7475
- :py:class:`str`
7576
- ``string``
76-
- String. If looks like a Python literal (e.g., ``"hello"``), it's parsed accordingly.
77+
- String. If it looks like a Python literal (e.g., ``"hello"``), it is parsed accordingly.
7778

7879
Examples:
7980

@@ -129,8 +130,8 @@ Flag
129130

130131
A flag is a boolean modifier that can be either on or off.
131132

132-
Every flag is available as a attribute of the :class:`Field`.
133-
For example, we have a "required" flag registed, we can access ``Field.required``
133+
Every flag is available as an attribute of the :class:`Field`.
134+
For example, we have a "required" flag registered, and we can access ``Field.required``
134135
attribute.
135136

136137
.. list-table::
@@ -154,8 +155,8 @@ By-Option
154155

155156
A by-option is a key-value modifier with the syntax ``<name> by <value>``.
156157

157-
Every by-option is available as a attribute of the :class:`Field`.
158-
For example, we have a "sep" flag registed, we can get the value of separator
158+
Every by-option is available as an attribute of the :class:`Field`.
159+
For example, we have a "sep" by-option registered, and we can get the separator
159160
from ``Field.sep`` attribute.
160161

161162
Built-in by-options:
@@ -179,10 +180,10 @@ DSL Input Result
179180
``int, sep by ':'`` ``1:2:3`` :py:`[1, 2, 3]`
180181
=================== ========= ================
181182

182-
Extending the DSL
183+
Extending the FDL
183184
=================
184185

185-
You can extend the DSL by registering custom types, flags, and by-options
186+
You can extend the FDL by registering custom types, flags, and by-options
186187
through the :attr:`~sphinxnotes.render.Registry.data` attribute of
187188
:data:`sphinxnotes.render.REGISTRY`.
188189

@@ -212,7 +213,7 @@ Adding Custom Flags
212213
-------------------
213214

214215
Use :meth:`~sphinxnotes.render.data.Registry.add_flag` method of
215-
:data:`sphinxnotes.render.REGISTRY` to add a new type:
216+
:data:`sphinxnotes.render.REGISTRY` to add a new flag:
216217

217218
>>> from sphinxnotes.render import REGISTRY
218219
>>> REGISTRY.data.add_flag('unique', default=False)

docs/index.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,17 @@ Introduction
3030
3131
A framework to define, constrain, and render data in Sphinx documentation.
3232

33-
.. seealso:: `sphinxnotes-any`__ and `sphinxnotes-data`__
34-
35-
__ https://sphinx.silverrainz.me/any/
36-
__ https://sphinx.silverrainz.me/data/
37-
3833
.. INTRODUCTION END
3934
4035
Getting Started
4136
===============
4237

4338
.. ADDITIONAL CONTENT START
4439
45-
This extension is not intended to be used directly by Sphinx user.
46-
It is for Sphinx extension developer, please refer to :doc:`dsl` and :doc:`api`.
40+
.. note::
41+
42+
This extension is not intended to be used directly by Sphinx users.
43+
It is for Sphinx extension developers.
4744

4845
.. ADDITIONAL CONTENT END
4946
@@ -53,6 +50,7 @@ Contents
5350
.. toctree::
5451
:caption: Contents
5552

53+
usage
5654
dsl
5755
api
5856
changelog

0 commit comments

Comments
 (0)