Various tweaking to get the module formatter to work for 'make docs' in the docs project. Likely the templates for other module formatting types will have to change

by the time I'm done.
This commit is contained in:
Michael DeHaan 2012-09-27 21:06:31 -04:00
parent 9a7a2a4d60
commit 83f277cfe6
6 changed files with 140 additions and 127 deletions

View file

@ -53,7 +53,7 @@ options:
with B(bold), etc. work too. with B(bold), etc. work too.
- remove: - remove:
required: false required: false
choices: [ yes, no, maybe, perhaps ] choices: [ yes, no ]
default: "maybe" default: "maybe"
aliases: [ kill, killme, delete ] aliases: [ kill, killme, delete ]
description: description:
@ -90,7 +90,6 @@ def html_ify(text):
t = _MODULE.sub("<span class='module'>" + r"\1" + "</span>", t) t = _MODULE.sub("<span class='module'>" + r"\1" + "</span>", t)
t = _URL.sub("<a href='" + r"\1" + "'>" + r"\1" + "</a>", t) t = _URL.sub("<a href='" + r"\1" + "'>" + r"\1" + "</a>", t)
t = _CONST.sub("<code>" + r"\1" + "</code>", t) t = _CONST.sub("<code>" + r"\1" + "</code>", t)
return t return t
def man_ify(text): def man_ify(text):
@ -121,7 +120,8 @@ def rst_xline(width, char="="):
return char * width return char * width
env = Environment(loader=FileSystemLoader('templates'), # FIXME: path should be configurable
env = Environment(loader=FileSystemLoader('../ansible/hacking/templates/'),
variable_start_string="@{", variable_start_string="@{",
variable_end_string="}@", variable_end_string="}@",
) )
@ -207,6 +207,8 @@ def main():
print "Need module_dir" print "Need module_dir"
sys.exit(1) sys.exit(1)
# TODO: make template dir configurable
if args.type == 'latex': if args.type == 'latex':
env.filters['jpfunc'] = latex_ify env.filters['jpfunc'] = latex_ify
template = env.get_template('latex.j2') template = env.get_template('latex.j2')
@ -221,6 +223,7 @@ def main():
outputname = "ansible.%s.man" outputname = "ansible.%s.man"
if args.type == 'rst': if args.type == 'rst':
env.filters['jpfunc'] = rst_ify env.filters['jpfunc'] = rst_ify
env.filters['html_ify'] = html_ify
env.filters['fmt'] = rst_fmt env.filters['fmt'] = rst_fmt
env.filters['xline'] = rst_xline env.filters['xline'] = rst_xline
template = env.get_template('rst.j2') template = env.get_template('rst.j2')

View file

@ -19,15 +19,26 @@
{% endfor %} {% endfor %}
{% if options is defined -%} {% if options is defined -%}
@{ xline(10, "=") }@ @{xline(10)}@ @{xline(10)}@ @{xline(60)}@ .. raw:: html
@{ "parameter" | fmt('%-10s')}@ @{ "required" | fmt('%-10s')}@ @{ "default" | fmt('%-10s')}@ @{ "comments" | fmt('%-60s')}@
@{ xline(10, "=") }@ @{xline(10)}@ @{xline(10)}@ @{xline(60)}@ {% for o in options -%} <table>
{% for opt, v in o.iteritems() %} <tr>
{% if v['required'] %}{% set required = 'yes' %}{% else %}{% set required = ' ' %}{% endif -%} <td>parameter</td>
@{opt |fmt("%-10s") }@ @{ required|fmt('%-10s') }@ @{ v['default']|fmt('%-10s') }@ {% for desc in v.description -%}@{ desc | jpfunc }@{% endfor -%} <td>required</td>
{% endfor -%} <td>default</td>
<td>choices</td>
<td>comments</td>
</tr>
{% for (k,v) in options.iteritems() %}
<tr>
<td>@{ k }@</td>
<td>@{ v.get('required',False) }@</td>
<td>@{ v['default'] }@</td>
<td><ul>{% for choice in v.get('choices',[]) -%}<li>@{ choice }@</li>{% endfor -%}</ul></td>
<td>{% for desc in v.description -%}@{ desc | html_ify }@{% endfor -%}</td>
</tr>
{% endfor %} {% endfor %}
@{ xline(10, "=") }@ @{xline(10)}@ @{xline(10)}@ @{xline(60)}@ </table>
{% endif %} {% endif %}
FIXME: examples! FIXME: include the examples here!

View file

@ -38,19 +38,19 @@ description:
the file module - including M(copy), M(template), and M(assmeble). the file module - including M(copy), M(template), and M(assmeble).
version_added: "0.1" version_added: "0.1"
options: options:
- dest: dest:
description: description:
- defines the file being managed, unless when used with I(state=link), and then sets the destination to create a symbolic link to using I(src) - defines the file being managed, unless when used with I(state=link), and then sets the destination to create a symbolic link to using I(src)
required: true required: true
default: [] default: []
aliases: [] aliases: []
- state: state:
description: description:
- If directory, all immediate subdirectories will be created if they do not exist. If I(file), the file will NOT be created if it does not exist, see the M(copy) or M(template) module if you want that behavior. If I(link), the symbolic link will be created or changed. If absent, directories will be recursively deleted, and files or symlinks will be unlinked. - If directory, all immediate subdirectories will be created if they do not exist. If I(file), the file will NOT be created if it does not exist, see the M(copy) or M(template) module if you want that behavior. If I(link), the symbolic link will be created or changed. If absent, directories will be recursively deleted, and files or symlinks will be unlinked.
required: false required: false
default: file default: file
choices: [ file, link, directory, absent ] choices: [ file, link, directory, absent ]
- mode: mode:
description: description:
- mode the file or directory should be, such as 0644 as would be fed to I(chmod). English modes like B(g+x) are not yet supported - mode the file or directory should be, such as 0644 as would be fed to I(chmod). English modes like B(g+x) are not yet supported
examples: examples:

View file

@ -33,19 +33,19 @@ description:
server must have direct access to the remote resource. server must have direct access to the remote resource.
version_added: "0.6" version_added: "0.6"
options: options:
- url: url:
description: description:
- HTTP, HTTPS, or FTP URL - HTTP, HTTPS, or FTP URL
required: true required: true
default: null default: null
aliases: [] aliases: []
- dest: dest:
description: description:
- absolute path of where to download the file to. - absolute path of where to download the file to.
- If I(dest) is a directory, the basename of the file on the remote server will be used. If a directory, I(thirsty=yes) must also be set. - If I(dest) is a directory, the basename of the file on the remote server will be used. If a directory, I(thirsty=yes) must also be set.
required: true required: true
default: null default: null
- thirsty: thirsty:
description: description:
- if C(yes), will download the file every time and replace the - if C(yes), will download the file every time and replace the
file if the contents change. if C(no), the file will only be downloaded if file if the contents change. if C(no), the file will only be downloaded if
@ -55,7 +55,7 @@ options:
required: false required: false
choices: [ "yes", "no" ] choices: [ "yes", "no" ]
default: "no" default: "no"
- others: others:
description: description:
- all arguments accepted by the M(file) module also work here - all arguments accepted by the M(file) module also work here
required: false required: false

View file

@ -29,38 +29,37 @@ description:
sections if they don't exist. sections if they don't exist.
version_added: "0.9" version_added: "0.9"
options: options:
- dest: dest:
description: description:
- Path to the INI-style file; this file is created if required - Path to the INI-style file; this file is created if required
required: true required: true
default: null default: null
aliases: [] aliases: []
- section: section:
description: description:
- Section name in INI file. This is added if C(state=present) automatically when - Section name in INI file. This is added if C(state=present) automatically when
a single value is being set. a single value is being set.
required: true required: true
default: null default: null
- option: option:
description: description:
- if set (required for changing a I(value)), this is the name of the option. - if set (required for changing a I(value)), this is the name of the option.
- May be omitted if adding/removing a whole I(section). - May be omitted if adding/removing a whole I(section).
required: false required: false
default: [] default: []
- value: value:
description: description:
- the string value to be associated with an I(option). May be omitted when - the string value to be associated with an I(option). May be omitted when removing an I(option).
removing an I(option).
required: false required: false
default: [] default: []
- backup: backup:
description: description:
- Create a backup file including the timestamp information so you can get - Create a backup file including the timestamp information so you can get
the original file back if you somehow clobbered it incorrectly. the original file back if you somehow clobbered it incorrectly.
required: false required: false
default: no default: no
choices: [ "yes", "no" ] choices: [ "yes", "no" ]
- others: others:
description: description:
- all arguments accepted by the M(file) module also work here - all arguments accepted by the M(file) module also work here
required: false required: false

View file

@ -31,29 +31,29 @@ description:
file only. For other cases, see the M(copy) or M(template) modules. file only. For other cases, see the M(copy) or M(template) modules.
version_added: "0.7" version_added: "0.7"
options: options:
- name: name:
required: true required: true
description: description:
- The file to modify - The file to modify
- regexp: regexp:
required: true required: true
description: description:
- The regular expression to look for in the file. For I(state=present), - The regular expression to look for in the file. For I(state=present),
the pattern to replace. For I(state=absent), the pattern of the line the pattern to replace. For I(state=absent), the pattern of the line
to remove. to remove.
- state: state:
required: false required: false
choices: [ present, absent ] choices: [ present, absent ]
default: "present" default: "present"
aliases: [] aliases: []
description: description:
- Whether the line should be there or not. - Whether the line should be there or not.
- line: line:
required: false required: false
description: description:
- Required for I(state=present). The line to insert/replace into the - Required for I(state=present). The line to insert/replace into the
file. Must match the value given to C(regexp). file. Must match the value given to C(regexp).
- insertafter: insertafter:
required: false required: false
default: EOF default: EOF
description: description:
@ -63,7 +63,7 @@ options:
file, and C(EOF) for inserting the line at the end of the file. file, and C(EOF) for inserting the line at the end of the file.
choices: [ BOF, EOF ] choices: [ BOF, EOF ]
default: EOF default: EOF
- backup: backup:
required: false required: false
default: no default: no
description: description: