Skip to content

Commit 061ce10

Browse files
committed
Beta release 0.5.1
1 parent 7a23377 commit 061ce10

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1544
-775
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ lib/
1818
lib64/
1919
parts/
2020
sdist/
21+
out/
2122
var/
2223
wheels/
2324
share/python-wheels/

README.md

+105-34
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# ansible-autodoc
2-
Generate documentation from annotated playbooks and roles using templates
2+
Generate documentation from annotated playbooks and roles using templates.
33

4-
Please note this is still a work in progress, while the code might work in it's current state
5-
I don't recommend yet to use it, as I will probably change things.
4+
Note: this project is currently in Beta, issues, ideas and pull requests are welcome.
65

76
# Features
87
* allow to document playbook projects and roles
@@ -13,25 +12,49 @@ I don't recommend yet to use it, as I will probably change things.
1312
# Installation
1413
## Manual
1514
1. download / git clone this project
16-
2. run `install.py` Note sudo is required
15+
2. run `install.py` Note sudo is required ( I use this locally while developing)
1716

1817
## Pip
19-
using pip (not yet)
18+
using pip
2019
```
2120
pip install ansible-autodoc
2221
```
2322

24-
# Use
23+
## Use
24+
```$xslt
25+
ansible-autodoc -h # print help
26+
ansible-autodoc -p all path/to/role # print in cli all the recolected data
27+
ansible-autodoc [path/to/project] # will generate README file based on annotations
28+
```
29+
### more flexibility
30+
you can create a configuration file "autodoc.config.yaml" in the root of your project in order to modify
31+
several behaviours, see the sample config file for more details:
32+
33+
```$xslt
34+
# role or project with playbooks
35+
$ cd <project>
36+
37+
# create sample configuration (optional)
38+
# you can pass the options as parameters too
39+
$ ansible-autodoc --sample-doc > autodoc.config.yaml
40+
```
2541

26-
## Annotations
42+
# Annotations
2743

2844
Use the following annotations in your playbooks and roles
2945

30-
* author: `# @author: Author Name` to annotate the author of playbook or role
31-
* description: `# @description: Project description goes here` to annotate the project description
46+
* meta: `# @meta author: Author Name` to annotate the metadata of playbook or role, like author,
47+
check below list of useful metadata
48+
* author: (self explanatory)
49+
* description: playbook / role description
50+
* name: to define a different role/project name instead of the folder name
51+
* license: (self explanatory)
52+
* email: (self explanatory)
3253
* todo: `# @todo: section #Taskt that need to be done` to annotate a todo
33-
* tags: `# @tag: tagname # description` to annotate tags
34-
* variables: `# @var: varname: ["some_defaut","other"] # Description of the variables` to annotate a variables
54+
* action: `# @action section # description of the action` to annotate a actions performed by the playbook/role
55+
* tag: `# @tag tagname # description` to annotate tags, this is a special annotation as this will not only search
56+
for annotations, but also for used tags in the project and add that to the generated output.
57+
* variables: `# @var varname: ["some_defaut","other"] # Description of the variables` to annotate a variables
3558
* example: the idea is that after every annotation, we can define an example block, linked to the annotation.
3659
```$xslt
3760
# @example: title # Some description
@@ -40,37 +63,87 @@ Use the following annotations in your playbooks and roles
4063
# @end
4164
```
4265

43-
### Not implemented:
66+
## Not implemented:
4467
this is still not implemented, just ideas
4568

4669
`Nothing here`
4770

48-
## Generate Documentation
49-
50-
```$xslt
51-
# role or project with playbooks
52-
$ cd <project>
53-
54-
# create sample configuration (optional)
55-
# you can pass the options as parameters too
56-
$ ansible-autodoc --sample-doc > autodoc.config.yaml
57-
58-
# crate documentation
59-
$ ansible-autodoc
60-
61-
# more options
62-
$ ansible-autodoc -h
63-
```
64-
6571
# Templates
6672
the template engine uses jinja2 for document parsing, the directory structure of the template
6773
will be recreated on the output, already existent files will be overwritten.
6874

6975
you can specify your own template, for extending templates create a new template directory and
7076
specify the location of the same in the configuration file.
7177

78+
annotations are parsed as follows: "@annotation key:value # description"
79+
your annotation item would then contain these values and some automatically filled if available:
80+
```
81+
{
82+
"key": "key section",
83+
"value": "value section",
84+
"desc": "description",
85+
"file": "absolute path where the annotation was found",
86+
"line": "line number of the annotation",
87+
"role": "name of the role the annotation was found"
88+
}
89+
```
90+
91+
92+
## template API
93+
when templating autodoc projects you will have the methods from DocumentParser exposed in the templates:
94+
'r' is a reference to the parser in order to do things like:
95+
```
96+
{{ r.get_roles() | pprint }}
97+
```
98+
99+
* r.get_gata() : get the full data of autodoc in jason structure, this can be quite overwhelming when templating
100+
* r.get_annotations() : get a list of the scanned annotations as per configuration
101+
* r.get_roles(exclude_playbook) : return a list of scanned roles, if exclude_playbook is True the palybook
102+
role '_ansible_playbook_' is removed
103+
* r.is_role() : return True if the scanned project directory is identified as role, false if scanned as playbook
104+
* r.get_role_name() : If scanned project is a role, return role name (project folder name)
105+
* r.get_type(name,role="all"): return an array with the corresponding annotation "name", role is optional
106+
* if "all" or not specified, the mixed result for all roles will be returned
107+
* if "play" specified, the playbook results will be returned
108+
* r.get_multi_type(name,role="all"): return a dict of all the annotations with structure `section:[item1,item2]`
109+
you can use it like:
110+
```
111+
{% for key , values in r.get_multi_type("action","role_name") %}
112+
{{ key }}
113+
{% for item in values %}
114+
{{ item.desc }}
115+
{% endfor %}
116+
{% endfor %}
117+
```
118+
* r.get_keys(name,role="all"): return a list of annotation keys, same parameters as get_type.
119+
* r.get_item(name,key,role="all"): return a single annotation item, same parameters as get_type plus "key"
120+
* r.get_duplicates(name): return a dict of annotations that are duplicated, i.e useful for tags to identify
121+
if they have been annotated more than once or if there are tags used in more than one role.
122+
* r.allow_multiple(name): check if a annotation allows multiple values, like @todo or @action.
123+
* r.include(filename): include a tex file, path relative to the project root
124+
125+
* r.cli_left_space("string",spaces) : left justify with spaces a string, spaces is optional, see python ljust()
126+
* r.cli_print_section() : return the passed parameter when using cli print "-p", default is "all"
127+
128+
* r.capitalize(string) : wrapper for python capitalize
129+
* r.fprn(role_name,replace_value="Playbook"): "filter playbook role name" replace the internal playbook role name
130+
"_ansible_playbook_" with a different value.
72131

73132
# changelog
133+
134+
2019/02/17 - Version 0.5.1
135+
* add missing feature @example
136+
* improve default template "readme"
137+
138+
2019/02/17 - Version 0.5.0
139+
* added uint tests
140+
* refactored annotation discovery into Annotation object
141+
* changed annotation to allow multi line description
142+
* made annotation syntax more uniform
143+
* moved some essential logic from AutodocCli to Config
144+
* IMPROVEMENT: got rid of annotations author and description and use meta: author | description instead
145+
* Missing feature from 0.4: @example
146+
74147
2019/01/22 - Version 0.4.2
75148
* FIX: yaml load unicode files
76149
* FIX: document parsing when some annotations are not present
@@ -79,26 +152,24 @@ specify the location of the same in the configuration file.
79152
2019/01/21 - Version 0.4.2
80153
* Added example block annotation
81154

82-
83155
2019/01/21 - Version 0.4.1
84156
* Added print template to stdout, useful for project review and development
85157
* Added @var annotation
86158

87-
88159
2019/01/20 - Version 0.4.0
89160
* Basic functionality with tag annotations working
90161
* simple annotations: "author", "description" and "todo2 also working
91162

92163
# Todo
93164
* when a yaml file with a special char is templated, an UnicodeEncodeError will be thrown
94-
* add testing, coverage, travis
165+
* Improve test coverage
95166
* add template cli parameter
96167

97168
### improvements
98-
* instead of using different annotation for author, description etc, use one annotation @info: <section> # value
99169
* improve the default templates : ongoing task
100170
* improve the documentation : ongoing task
101-
* add @meta tag, for enabling and disabling parts of the template & document
171+
* add @autodoc tag, to use as flags for specific templates, i.e # @autodoc tags:hidden #
172+
to hide the render of tags section
102173
* add annotation personalization by extending annotation definition in configuration file
103174
* document annotation personalization
104175

0 commit comments

Comments
 (0)