Skip to content

Commit

Permalink
Added json format option to scripts documentation output
Browse files Browse the repository at this point in the history
  • Loading branch information
pineapplemachine committed May 27, 2017
1 parent 7668576 commit cd02e05
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions pydwarf/uristdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __main__():
template.format['txt'] = txttemplate()
template.format['md'] = mdtemplate()
template.format['html'] = htmltemplate()
template.format['json'] = jsontemplate()



Expand Down Expand Up @@ -188,5 +189,28 @@ def metadata(self, metadata):
return '<h3>Metadata</h3>\n<ul>%s</ul>' % '\n'.join(('<li><strong>%s:</strong> %s</li>' % (key, self.norm(value)) for key, value in metadata.iteritems()))


class jsontemplate(template):
def __init__(self):
pass

def preprocesstext(self, text):
# Doesn't handle control characters, but why the fuck would you
# put control characters in the text
# TODO: Maybe at least check for and remove control characters
return text.replace('"', '\"')

def concat(self, items):
return '[%s]' % ','.join(items)

def full(self, delimiter=None, allmeta=None, **kwargs):
import json
jmeta = dict(allmeta)
if 'description' in jmeta:
jmeta['description'] = self.norm(jmeta['description'])
if 'arguments' in jmeta:
for key in jmeta['arguments']:
jmeta['arguments'][key] = self.norm(jmeta['arguments'][key])
return json.dumps(jmeta)


__main__()
3 changes: 2 additions & 1 deletion pydwarf/uristscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def doc(self, format=None):
description = self.meta('description'),
compatibility = self.meta('compatibility'),
arguments = self.meta('arguments'),
metadata = {key: value for key, value in self.metadata.iteritems() if key not in handled_metadata_keys}
metadata = {key: value for key, value in self.metadata.iteritems() if key not in handled_metadata_keys},
allmeta = self.metadata,
)


Expand Down

0 comments on commit cd02e05

Please sign in to comment.