Skip to content

Commit 800769a

Browse files
ReST template (PickNikRobotics#119)
1 parent f70408c commit 800769a

File tree

6 files changed

+58
-8
lines changed

6 files changed

+58
-8
lines changed

generate_parameter_library_py/generate_parameter_library_py/generate_markdown.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ def __str__(self):
159159
return code
160160

161161

162-
def run(yaml_file, output_file):
162+
def run(yaml_file, output_file, language):
163163
# cpp is used here because it the desired style of the markdown, e.g. false for C++ instead of False for Python
164-
gen_param_struct = GenerateCode("cpp")
164+
gen_param_struct = GenerateCode(language)
165165
output_dir = os.path.dirname(output_file)
166166
if output_dir and not os.path.isdir(output_dir):
167167
os.makedirs(output_dir)
@@ -180,8 +180,9 @@ def main():
180180
parser = argparse.ArgumentParser()
181181
parser.add_argument("--output_markdown_file")
182182
parser.add_argument("--input_yaml_file")
183+
parser.add_argument("--language", default="markdown")
183184
args = parser.parse_args()
184-
run(args.input_yaml_file, args.output_markdown_file)
185+
run(args.input_yaml_file, args.output_markdown_file, args.language)
185186
print(args)
186187

187188

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. code::
2+
{%- filter indent(width=2) %}
3+
4+
{{namespace}}:
5+
ros__parameters:
6+
{%- filter indent(width=4) %}
7+
{{default_param_values}}
8+
{% endfilter -%}
9+
{% endfilter -%}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{{title}} Parameters
2+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3+
4+
{{default_config}}
5+
6+
{{parameter_details}}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{name}} ({{type}}){% if description|length %}
2+
{{description}}
3+
{% endif %}
4+
{%- if default_value|length %}
5+
Default: {{default_value}}
6+
{% endif %}
7+
{%- if constraints|length %}
8+
9+
Constraints:
10+
11+
{%- filter indent(width=2) %}
12+
13+
{{constraints}}
14+
{% endfilter -%}
15+
16+
{% endif %}

generate_parameter_library_py/generate_parameter_library_py/parse_yaml.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ def __init__(
151151
):
152152
if language == "cpp":
153153
self.conversation = CPPConverstions()
154+
elif language == "rst" or language == "markdown":
155+
# cpp is used here because it the desired style of the markdown,
156+
# e.g. "false" for C++ instead of "False" for Python
157+
self.conversation = CPPConverstions()
154158
elif language == "python":
155159
self.conversation = PythonConvertions()
156160
else:
@@ -603,10 +607,19 @@ def get_all_templates(language: str):
603607
template_lang_path = os.path.join(
604608
os.path.dirname(__file__), "jinja_templates", language
605609
)
606-
template_markdown_path = os.path.join(
607-
os.path.dirname(__file__), "jinja_templates", "markdown"
608-
)
609-
template_paths = [template_lang_path, template_markdown_path]
610+
if language == "markdown":
611+
template_markdown_path = os.path.join(
612+
os.path.dirname(__file__), "jinja_templates", "markdown"
613+
)
614+
template_paths = [template_lang_path, template_markdown_path]
615+
elif language == "rst":
616+
template_rst_path = os.path.join(
617+
os.path.dirname(__file__), "jinja_templates", "rst"
618+
)
619+
template_paths = [template_lang_path, template_rst_path]
620+
else:
621+
template_paths = [template_lang_path]
622+
610623
template_map = {}
611624
for template_path in template_paths:
612625
for file_name in [
@@ -691,7 +704,9 @@ def __init__(self, language: str):
691704
self.set_stack_params = []
692705
if language == "cpp":
693706
self.comments = "// auto-generated DO NOT EDIT"
694-
elif language == "python":
707+
elif language == "rst":
708+
self.comments = ".. auto-generated DO NOT EDIT"
709+
elif language == "python" or language == "markdown":
695710
self.comments = "# auto-generated DO NOT EDIT"
696711
else:
697712
raise compile_error(

generate_parameter_library_py/setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
"jinja_templates/markdown/default_config",
5555
"jinja_templates/markdown/documentation",
5656
"jinja_templates/markdown/parameter_detail",
57+
"jinja_templates/rst/default_config",
58+
"jinja_templates/rst/documentation",
59+
"jinja_templates/rst/parameter_detail",
5760
"jinja_templates/python/declare_parameter",
5861
"jinja_templates/python/declare_runtime_parameter",
5962
"jinja_templates/python/declare_struct",

0 commit comments

Comments
 (0)