Skip to content

Commit

Permalink
Merge pull request #26 from sphinx-contrib/domain
Browse files Browse the repository at this point in the history
Wrap directives in minimal domain
  • Loading branch information
dhellmann committed Jun 12, 2019
2 parents 4bde6ad + b7e21ed commit 3bd6258
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 15 deletions.
4 changes: 2 additions & 2 deletions doc/source/csv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Code

.. code-block:: rst
.. datatemplate-csv::
.. datatemplate:csv::
:source: sample.csv
:template: csv-sample.tmpl
:headers:
Expand All @@ -29,7 +29,7 @@ Code
Rendered Output
===============

.. datatemplate-csv::
.. datatemplate:csv::
:source: sample.csv
:template: csv-sample.tmpl
:headers:
Expand Down
1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ for Sphinx to render as part of its output.
yaml
csv
xml
legacy

Indices and tables
==================
Expand Down
2 changes: 1 addition & 1 deletion doc/source/json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ Template File
Rendered Output
===============

.. datatemplate-json::
.. datatemplate:json::
:source: sample.json
:template: sample.tmpl
25 changes: 25 additions & 0 deletions doc/source/legacy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
================
Legacy Samples
================

The ``datatemplate`` directive is should no longer be used. It is
deprecated, and will be removed in the next release.

Data File
=========

.. include:: sample.yaml
:literal:

Template File
=============

.. include:: _templates/sample.tmpl
:literal:

Rendered Output
===============

.. datatemplate::
:source: sample.yaml
:template: sample.tmpl
8 changes: 4 additions & 4 deletions doc/source/using.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
The ``datatemplate`` directive is the interface between the data
source and the rendering template. It requires two parameters.

.. rst:directive:: datatemplate-json
.. rst:directive:: datatemplate:json
Load ``source`` via :py:func:`json.load`

Expand All @@ -21,7 +21,7 @@ source and the rendering template. It requires two parameters.
The text encoding that will be used to read the source file. See :any:`standard-encodings`
.. rst:directive:: datatemplate-yaml
.. rst:directive:: datatemplate:yaml
Load ``source`` via PyYAML_ (``yaml.safe_load``)

Expand All @@ -39,7 +39,7 @@ source and the rendering template. It requires two parameters.
.. _PyYAML: https://pyyaml.org

.. rst:directive:: datatemplate-xml
.. rst:directive:: datatemplate:xml
Load ``source`` via :py:func:`xml.etree.ElementTree.parse` (actually using ``defusedxml``)

Expand All @@ -53,7 +53,7 @@ source and the rendering template. It requires two parameters.
.. rst:directive:: datatemplate-csv
.. rst:directive:: datatemplate:csv
Load ``source`` via :py:func:`csv.reader` or :py:class:`csv.DictReader` depending on ``header``

Expand Down
2 changes: 1 addition & 1 deletion doc/source/xml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ Template File
Rendered Output
===============

.. datatemplate-xml::
.. datatemplate:xml::
:source: sample.xml
:template: xml-sample.tmpl
2 changes: 1 addition & 1 deletion doc/source/yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ Template File
Rendered Output
===============

.. datatemplate-yaml::
.. datatemplate:yaml::
:source: sample.yaml
:template: sample.tmpl
12 changes: 7 additions & 5 deletions sphinxcontrib/datatemplates/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from sphinx.util import logging

from sphinxcontrib.datatemplates import directive
from . import directive, domain

LOG = logging.getLogger(__name__)


def setup(app):
LOG.info('initializing sphinxcontrib.datatemplates')
app.add_directive('datatemplate-json', directive.DataTemplateJSON)
app.add_directive('datatemplate-yaml', directive.DataTemplateYAML)
app.add_directive('datatemplate-csv', directive.DataTemplateCSV)
app.add_directive('datatemplate-xml', directive.DataTemplateXML)
app.add_directive('datatemplate', directive.DataTemplateLegacy)
app.add_domain(domain.DataTemplateDomain)

return {
'parallel_read_safe': True,
'parallel_write_safe': True,
}
21 changes: 21 additions & 0 deletions sphinxcontrib/datatemplates/domain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sphinx.domains import Domain
from . import directive


class DataTemplateDomain(Domain):

name = 'datatemplate'
label = 'DataTemplate Replacement'
directives = {
'json': directive.DataTemplateJSON,
'yaml': directive.DataTemplateYAML,
'csv': directive.DataTemplateCSV,
'xml': directive.DataTemplateXML,
}

def get_objects(self):
return []

def resolve_xref(self, env, fromdocname, builder, typ, target, node,
contnode):
return None
2 changes: 1 addition & 1 deletion tools/travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -e

case "$BUILD" in
docs)
sphinx-build -W -b html doc/source doc/build;;
sphinx-build -b html doc/source doc/build;;
linter)
flake8 sphinxcontrib setup.py;
python setup.py sdist;
Expand Down

0 comments on commit 3bd6258

Please sign in to comment.