Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

Commit

Permalink
Merge fed8c65 into 07c0b07
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Jul 27, 2017
2 parents 07c0b07 + fed8c65 commit 353d338
Show file tree
Hide file tree
Showing 30 changed files with 1,994 additions and 238 deletions.
7 changes: 5 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext examples

help:
@echo "Please use \`make <target>' where <target> is one of"
Expand Down Expand Up @@ -49,7 +49,10 @@ help:
clean:
rm -rf $(BUILDDIR)/*

html:
examples:
python gen_examples.py

html: examples
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
Expand Down
67 changes: 67 additions & 0 deletions docs/examples.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Examples
========

{% for e in examples %}
{{ e.example.documentation.title }}
{{ "-" * e.example.documentation.title|length }}

{{ e.example.documentation.summary }}

Original data
_____________

.. code::

{{ e.mocked|indent }}

{{ e.example.documentation.data|default("") }}

Parser rule
___________

.. code-block:: yaml

{{ e.example.rule|to_yaml|indent }}

{{ e.example.documentation.rule|default("") }}

Result
______

{{ e.example.documentation.result|default("") }}

{% for case in e.example.data %}

Example {{loop.index}}
^^^^^^^^^^

.. code-block:: yaml

{{ case|to_yaml|indent }}

.. raw:: html

<div><table border="1" class="docutils">
<tr>
<th class="head">{{ e.example.processor.attribute }}_key</th>
<th class="head">block</th>
<th class="head">extra_vars</th>
</tr>
<tbody>
{% for r in e.example.expected[loop.index0] %}
<tr>
<td style="vertical-align: top;">{{ r.key }}</pre></td>
<td style="vertical-align: top;">
<div class="code highlight-default"><div class="highlight" style="background:inherit; border:0px;"><pre>
{{ r.block|to_yaml|indent }}</pre></div></div></td>
<td style="vertical-align: top;">
<div class="code highlight-default"><div class="highlight" style="background:inherit; border:0px;"><pre>
{{ r.extra_vars|to_yaml|indent }}</pre></div></div></td>
</td>
</tr>
{% endfor %}
</tbody>
</table></div>

{% endfor %}
{% endfor %}
54 changes: 54 additions & 0 deletions docs/gen_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os

from glob import glob

import yaml

from jinja2 import Environment, FileSystemLoader, StrictUndefined


BASE_PATH = os.path.dirname(__file__) or "."
EXAMPLES_PATH = "{}/../test/unit/test_parser/".format(BASE_PATH)
EXAMPLES = sorted([x for x in glob('{}/*'.format(EXAMPLES_PATH))])


def get_examples():
examples = []
for e in EXAMPLES:
with open("{}/mocked.txt".format(e), "r") as f:
mocked = f.read()

with open("{}/example.yaml".format(e), "r") as f:
example = yaml.load(f.read())

examples.append({"mocked": mocked, "example": example})
return examples


def indent_text(text, indent=4):
return "\n".join(["{}{}".format(" " * indent, l) for l in text.splitlines()])


def render_examples(examples):
env = Environment(loader=FileSystemLoader(BASE_PATH),
trim_blocks=True,
undefined=StrictUndefined)
jinja_filters = {
"to_yaml": lambda obj: yaml.dump(obj, default_flow_style=False),
"indent": indent_text,
}
env.filters.update(jinja_filters)

template = env.get_template('examples.j2')
return template.render(examples=examples)


def save_text(text):
with open("{}/yang/parsers/examples.rst".format(BASE_PATH), "w+") as f:
f.write(text)


if __name__ == "__main__":
examples = get_examples()
text = render_examples(examples)
save_text(text)
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Documentation
yang/basics
yang/writing_profiles
yang/parsers
yang/parsers/examples
yang/parsers/XMLParser
yang/parsers/TextParser
yang/translators
Expand Down
3 changes: 0 additions & 3 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
sphinx
sphinx-rtd-theme
sphinxcontrib-napoleon
invoke
napalm
napalm_yang
Loading

0 comments on commit 353d338

Please sign in to comment.