-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mkdocs): cli postprocessing support
That way, a single huge markdown file containing documentation for commands and methods can be split up into multiple files for individual inclusion in mkdocs. It's done by a post-processor which is loaded by mako-render, providing access to the entire context. Said processor may also drop results altogether and thus prevent files to be written that have been split up by it.
- Loading branch information
Showing
7 changed files
with
81 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ gen/*-cli/ | |
*.go | ||
*.pyc | ||
**target/ | ||
**docs/ | ||
**build_html/ | ||
.*.deps | ||
**Cargo.lock | ||
|
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
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
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,5 +1,41 @@ | ||
import util | ||
|
||
import os | ||
import re | ||
|
||
SPLIT_START = '>>>>>>>' | ||
SPLIT_END = '<<<<<<<' | ||
|
||
re_splitters = re.compile(r"%s ([\w\-\.]+)\n(.*?)\n%s" % (SPLIT_START, SPLIT_END), re.MULTILINE|re.DOTALL) | ||
|
||
# transform name to be a suitable subcommand | ||
def mangle_subcommand(name): | ||
return util.camel_to_under(name).replace('_', '-').replace('.', '-') | ||
|
||
|
||
# transform the resource name into a suitable filename to contain the markdown documentation for it | ||
def subcommand_md_filename(resource): | ||
return mangle_subcommand(resource) + '.md' | ||
|
||
|
||
# split the result along split segments | ||
def process_template_result(r, output_file): | ||
found = False | ||
dir = None | ||
if output_file: | ||
dir = os.path.dirname(output_file) | ||
if not os.path.isdir(dir): | ||
os.makedirs(dir) | ||
# end handle output directory | ||
|
||
for m in re_splitters.finditer(r): | ||
found = True | ||
fh = open(os.path.join(dir, m.group(1)), 'wb') | ||
fh.write(m.group(2)) | ||
fh.close() | ||
# end for each match | ||
|
||
if found: | ||
r = None | ||
|
||
return r |