This repository has been archived by the owner on May 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,994 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
sphinx | ||
sphinx-rtd-theme | ||
sphinxcontrib-napoleon | ||
invoke | ||
napalm | ||
napalm_yang |
Oops, something went wrong.