Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module_formatter fixes #1119

Merged
merged 1 commit into from
Sep 28, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions hacking/module_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,6 @@ def rst_fmt(text, fmt):
def rst_xline(width, char="="):
return char * width


# FIXME: path should be configurable
env = Environment(loader=FileSystemLoader('../ansible/hacking/templates/'),
variable_start_string="@{",
variable_end_string="}@",
)

env.globals['xline'] = rst_xline

def load_examples_section(text):
return text.split('***BREAK***')

Expand Down Expand Up @@ -165,6 +156,11 @@ def main():
dest="module_dir",
default=MODULEDIR,
help="Ansible modules/ directory")
p.add_argument("-T", "--template-dir",
action="store",
dest="template_dir",
default="hacking/templates",
help="directory containing Jinja2 templates")
p.add_argument("-t", "--type",
action='store',
dest='type',
Expand Down Expand Up @@ -208,7 +204,16 @@ def main():
print "Need module_dir"
sys.exit(1)

# TODO: make template dir configurable
if not args.template_dir:
print "Need template_dir"
sys.exit(1)

env = Environment(loader=FileSystemLoader(args.template_dir),
variable_start_string="@{",
variable_end_string="}@",
)

env.globals['xline'] = rst_xline

if args.type == 'latex':
env.filters['jpfunc'] = latex_ify
Expand Down Expand Up @@ -241,7 +246,6 @@ def main():
if fname.endswith(".swp"):
continue

# FIXME: html/manpage/latex
print " processing module source ---> %s" % fname

doc = get_docstring(fname, verbose=args.verbose)
Expand Down
70 changes: 0 additions & 70 deletions hacking/templates/latex.j2

This file was deleted.

25 changes: 10 additions & 15 deletions hacking/templates/man.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,19 @@
."
{% if options is defined -%}
.SH OPTIONS
{% for o in options -%}{% for opt, v in o.iteritems() -%}
.IP @{opt}@
{% for desc in v.description -%}
@{ desc | jpfunc }@
{% endfor -%}
{% if v['required'] %}(required){% endif -%}
{% if v['choices'] -%}
." .SS Choices
{% for (k,v) in options.iteritems() %}
.IP @{ k }@
{% for desc in v.description -%}@{ desc | jpfunc }@{% endfor -%}
{% if v.get('choices') %}
.IR Choices :
{% for choice in v['choices'] -%}@{ choice }@{% if not loop.last %},{% else %}.{% endif -%}
{% endfor -%}
{% endif %}
{% for choice in v.get('choices',[]) -%}@{ choice }@{% if not loop.last %},{%else%}.{%endif-%}{% endfor -%}{% endif %}
{% if v.get('required') %}(required){% endif -%}
{% if v.get('default') %} (default: @{ v.get('default') }@){% endif -%}
{#---------------------------------------------- #}
{% if v['version_added'] is defined -%}
(Added in Ansible version @{ v['version_added'] }@.)
{% if v.get('version_added') -%}
(Added in Ansible version @{ v.get('version_added') }@.)
{% endif -%}
{% endfor -%}
{% endfor -%}
{% endfor %}
{% endif %}
."
."
Expand Down
12 changes: 6 additions & 6 deletions hacking/templates/rst.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _@{ module }@:

@{ module }@
````````
``````````````````````````````

{# ------------------------------------------
#
Expand All @@ -23,11 +23,11 @@

<table>
<tr>
<td>parameter</td>
<td>required</td>
<td>default</td>
<td>choices</td>
<td>comments</td>
<th class="head">parameter</th>
<th class="head">required</th>
<th class="head">default</th>
<th class="head">choices</th>
<th class="head">comments</th>
</tr>
{% for (k,v) in options.iteritems() %}
<tr>
Expand Down