Skip to content

Commit

Permalink
Init object we think
Browse files Browse the repository at this point in the history
See #6
  • Loading branch information
xander.harris committed Feb 23, 2023
1 parent a5d65e5 commit 619b7b4
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 30 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ verify_ssl = true
name = "pypi"

[packages]
faker = "*"
myst_parser = "*"
pyyaml = "*"
sphinx = "*"
Expand Down
26 changes: 25 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 40 additions & 26 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,32 @@ Each example is preceded by it's ReStructuredText source.
## JSON object directive

```{code-block} rst
.. json:object:: Github Issue
:showexample:
.. json:object:: Github Issue
:showexample:
Information about a Github issue.
:property id: Github assigned issue ID
:proptype id: integer
:options id: nullable, default=''
:property url url: direct link to this issue
:property url repository_url: direct link to the repository that
this issue lives in
:property url labels_url: retrieve and manipulate the labels
associated with this issue
:property url comments_url: retrieve and manipulate the comments
associated with this issue
:property url events_url: retrieve and manipulate the events associated
with this issue
:property html_url: HTML formatted information about this issue
:proptype html_url: url
:property integer number: raw issue number
:property string state: current state of the issue
:property string title: issue title
:property string body: issue body
:property user: embedded information about the user that created
the issue
:proptype user: :json:object:`Github User`
Information about a Github issue.
:property id: Github assigned issue ID
:proptype id: integer
:options id: nullable, default=''
:property url url: direct link to this issue
:property url repository_url: direct link to the repository that
this issue lives in
:property url labels_url: retrieve and manipulate the labels
associated with this issue
:property url comments_url: retrieve and manipulate the comments
associated with this issue
:property url events_url: retrieve and manipulate the events associated
with this issue
:property html_url: HTML formatted information about this issue
:proptype html_url: url
:property integer number: raw issue number
:property string state: current state of the issue
:property string title: issue title
:property string body: issue body
:property user: embedded information about the user that created
the issue
:proptype user: :json:object:`Github User`
```

```{eval-rst}
Expand Down Expand Up @@ -88,6 +87,21 @@ Each example is preceded by it's ReStructuredText source.
The semantics of this data type is described in :rfc:`7807`.
```

```{eval-rst}
.. json:object:: Error
:showexample: yaml
What a normal JSON error body looks like.
:property string type:
:property string title:
:property integer status:
:property string detail:
:property uri instance:
The semantics of this data type is described in :rfc:`7807`.
```

## GitHub API JSON objects

```{code-block} rst
Expand Down
20 changes: 17 additions & 3 deletions sphinx_jsondomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from docutils import nodes
from docutils.parsers.rst import directives as rst_directives
from docutils.statemachine import StateWS
from docutils.statemachine import StateMachineWS
from sphinx import addnodes
from sphinx import directives
from sphinx import domains
Expand Down Expand Up @@ -74,13 +76,25 @@ class JSONObject(directives.ObjectDescription):
#
# NB self.domain is required to be the name of the sphinx domain
# inside of DocFieldTransformer
def __init__(self):
def __init__(
self, name='', arguments='', options='',
content='', lineno='', content_offset='', block_text='',
state=StateWS(StateMachineWS([StateWS], 'StateWS')),
state_machine=StateMachineWS([StateWS], 'StateWS')):
"""Initialize the class."""
self.names = []
self.name = name
self.domain_obj = ''
self.state = state
self.options = options
self.arguments = arguments
self.content = content
self.content_offset = content_offset
super().__init__(
name='', arguments='', options='', content='', lineno='',
content_offset='', block_text='', state='', state_machine='')
name=self.name, arguments=self.arguments, options=self.options,
content=self.content, lineno='',
content_offset=self.content_offset, block_text='',
state=self.state, state_machine=state_machine)

def run(self):
"""
Expand Down
8 changes: 8 additions & 0 deletions tmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from loguru import logger
from sphinx.application import Sphinx
import sphinx_jsondomain

s = Sphinx('.', '.', 'build/docs', 'build/docs/.doctrees', 'html')
jo = sphinx_jsondomain.JSONObject()

logger.debug(jo)

0 comments on commit 619b7b4

Please sign in to comment.