Skip to content

Commit

Permalink
Doc generation understands mapSubject/mapPredicate -> map<>
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Amstutz committed Jul 7, 2016
1 parent 93ed1fb commit 2abc7f4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions schema_salad/makedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,27 @@ def __init__(self, toc, j, renderlist, redirects):
("docAfter" not in f))):
self.render_type(f, 1)

def typefmt(self, tp, redirects, nbsp=False):
def typefmt(self, tp, redirects, nbsp=False, jsonldPredicate=None):
# type: (Any, Dict[str, str], bool) -> Union[str, unicode]
global primitiveType
if isinstance(tp, list):
if nbsp and len(tp) <= 3:
return "&nbsp;|&nbsp;".join([self.typefmt(n, redirects) for n in tp])
return "&nbsp;|&nbsp;".join([self.typefmt(n, redirects, jsonldPredicate=jsonldPredicate) for n in tp])
else:
return " | ".join([self.typefmt(n, redirects) for n in tp])
if isinstance(tp, dict):
if tp["type"] == "https://w3id.org/cwl/salad#array":
return "array&lt;%s&gt;" % (self.typefmt(tp["items"], redirects, nbsp=True))
ar = "array&lt;%s&gt;" % (self.typefmt(tp["items"], redirects, nbsp=True))
if jsonldPredicate and "mapSubject" in jsonldPredicate:
if "mapPredicate" in jsonldPredicate:
ar += " | map&lt;%s.%s,&nbsp;%s.%s&gt" % (self.typefmt(tp["items"], redirects),
jsonldPredicate["mapSubject"],
self.typefmt(tp["items"], redirects),
jsonldPredicate["mapPredicate"])
ar += " | map&lt;%s.%s,&nbsp;%s&gt" % (self.typefmt(tp["items"], redirects),
jsonldPredicate["mapSubject"],
self.typefmt(tp["items"], redirects))
return ar
if tp["type"] in ("https://w3id.org/cwl/salad#record", "https://w3id.org/cwl/salad#enum"):
frg = schema.avro_name(tp["name"])
if tp["name"] in redirects:
Expand Down Expand Up @@ -345,7 +355,8 @@ def extendsfrom(item, ex):
rfrg = schema.avro_name(i["name"])
tr = "<td><code>%s</code></td><td>%s</td><td>%s</td>"\
"<td>%s</td>" % (
rfrg, self.typefmt(tp, self.redirects),
rfrg, self.typefmt(tp, self.redirects,
jsonldPredicate=i.get("jsonldPredicate")),
"Optional" if opt else "Required",
mistune.markdown(desc))
if opt:
Expand Down

0 comments on commit 2abc7f4

Please sign in to comment.