def typefmt(tp, redirects, nbsp=False): if isinstance(tp, list): if nbsp and len(tp) <= 3: return " | ".join([typefmt(n, redirects) for n in tp]) else: return " | ".join([typefmt(n, redirects) for n in tp]) if isinstance(tp, dict): if tp["type"] == "https://w3id.org/cwl/salad#array": return "array<%s>" % (typefmt( tp["items"], redirects, nbsp=True)) 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: return """<a href="%s">%s</a>""" % (redirects[tp["name"]], frg) else: return """<a href="#%s">%s</a>""" % (to_id(frg), frg) if isinstance(tp["type"], dict): return typefmt(tp["type"], redirects) else: if str(tp) in redirects: return """<a href="%s">%s</a>""" % (redirects[tp], redirects[tp]) elif str(tp) in basicTypes: return """<a href="#CWLType">%s</a>""" % schema.avro_name(str(tp)) else: _, frg = urlparse.urldefrag(tp) if frg: tp = frg return """<a href="#%s">%s</a>""" % (to_id(tp), tp)
def typefmt(self, tp, redirects, nbsp=False): global primitiveType if isinstance(tp, list): if nbsp and len(tp) <= 3: return " | ".join([self.typefmt(n, redirects) 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<%s>" % (self.typefmt(tp["items"], redirects, nbsp=True)) 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: return """<a href="%s">%s</a>""" % (redirects[tp["name"]], frg) elif tp["name"] in self.typemap: return """<a href="#%s">%s</a>""" % (to_id(frg), frg) else: return frg if isinstance(tp["type"], dict): return self.typefmt(tp["type"], redirects) else: if str(tp) in redirects: return """<a href="%s">%s</a>""" % (redirects[tp], redirects[tp]) elif str(tp) in basicTypes: return """<a href="%s">%s</a>""" % (primitiveType, schema.avro_name(str(tp))) else: _, frg = urlparse.urldefrag(tp) if frg: tp = frg return """<a href="#%s">%s</a>""" % (to_id(tp), tp)
def typefmt(tp, nbsp=False): if isinstance(tp, list): if nbsp and len(tp) <= 3: return " | ".join([typefmt(n) for n in tp]) else: return " | ".join([typefmt(n) for n in tp]) if isinstance(tp, dict): if tp["type"] == "https://w3id.org/cwl/salad#array": return "array<%s>" % (typefmt(tp["items"], True)) if tp["type"] in ("https://w3id.org/cwl/salad#record", "https://w3id.org/cwl/salad#enum"): frg = schema.avro_name(tp["name"]) return """<a href="#%s">%s</a>""" % (to_id(frg), frg) if isinstance(tp["type"], dict): return typefmt(tp["type"]) else: if str(tp) in ( "https://w3id.org/cwl/salad#null", "http://www.w3.org/2001/XMLSchema#boolean", "http://www.w3.org/2001/XMLSchema#int", "http://www.w3.org/2001/XMLSchema#long", "http://www.w3.org/2001/XMLSchema#float", "http://www.w3.org/2001/XMLSchema#double", "http://www.w3.org/2001/XMLSchema#string", "https://w3id.org/cwl/salad#record", "https://w3id.org/cwl/salad#enum", "https://w3id.org/cwl/salad#array", ): return """<a href="#CWLType">%s</a>""" % schema.avro_name(str(tp)) else: _, frg = urlparse.urldefrag(tp) if frg: tp = frg return """<a href="#%s">%s</a>""" % (to_id(tp), tp)
def render_type(self, f, depth): if f["name"] in self.rendered or f["name"] in self.redirects: return self.rendered.add(f["name"]) if "doc" not in f: f["doc"] = "" f["type"] = copy.deepcopy(f) f["doc"] = "" f = f["type"] if "doc" not in f: f["doc"] = "" def extendsfrom(item, ex): if "extends" in item: for e in aslist(item["extends"]): ex.insert(0, self.typemap[e]) extendsfrom(self.typemap[e], ex) ex = [f] extendsfrom(f, ex) enumDesc = {} if f["type"] == "enum" and isinstance(f["doc"], list): for e in ex: for i in e["doc"]: idx = i.find(":") if idx > -1: enumDesc[i[:idx]] = i[idx + 1:] e["doc"] = [ i for i in e["doc"] if i.find(":") == -1 or i.find(" ") < i.find(":") ] f["doc"] = fix_doc(f["doc"]) if f["type"] == "record": for field in f.get("fields", []): if "doc" not in field: field["doc"] = "" if f["type"] != "documentation": lines = [] for l in f["doc"].splitlines(): if len(l) > 0 and l[0] == "#": l = ("#" * depth) + l lines.append(l) f["doc"] = "\n".join(lines) _, frg = urlparse.urldefrag(f["name"]) num = self.toc.add_entry(depth, frg) doc = "## %s %s\n" % (num, frg) else: doc = "" if self.title is None: self.title = f["doc"][0:f["doc"].index("\n")][2:] if f["type"] == "documentation": f["doc"] = number_headings(self.toc, f["doc"]) #if "extends" in f: # doc += "\n\nExtends " # doc += ", ".join([" %s" % linkto(ex) for ex in aslist(f["extends"])]) #if f["name"] in self.subs: # doc += "\n\nExtended by" # doc += ", ".join([" %s" % linkto(s) for s in self.subs[f["name"]]]) #if f["name"] in self.uses: # doc += "\n\nReferenced by" # doc += ", ".join([" [%s.%s](#%s)" % (s[0], s[1], to_id(s[0])) for s in self.uses[f["name"]]]) doc = doc + "\n\n" + f["doc"] doc = mistune.markdown(doc, renderer=MyRenderer()) if f["type"] == "record": doc += "<h3>Fields</h3>" doc += """<table class="table table-striped">""" doc += "<tr><th>field</th><th>type</th><th>required</th><th>description</th></tr>" required = [] optional = [] for i in f.get("fields", []): tp = i["type"] if isinstance( tp, list) and tp[0] == "https://w3id.org/cwl/salad#null": opt = False tp = tp[1:] else: opt = True desc = i["doc"] #if "inherited_from" in i: # desc = "%s _Inherited from %s_" % (desc, linkto(i["inherited_from"])) frg = schema.avro_name(i["name"]) tr = "<td><code>%s</code></td><td>%s</td><td>%s</td><td>%s</td>" % ( frg, self.typefmt( tp, self.redirects), opt, mistune.markdown(desc)) if opt: required.append(tr) else: optional.append(tr) for i in required + optional: doc += "<tr>" + i + "</tr>" doc += """</table>""" elif f["type"] == "enum": doc += "<h3>Symbols</h3>" doc += """<table class="table table-striped">""" doc += "<tr><th>symbol</th><th>description</th></tr>" for e in ex: for i in e.get("symbols", []): doc += "<tr>" frg = schema.avro_name(i) doc += "<td><code>%s</code></td><td>%s</td>" % ( frg, enumDesc.get(frg, "")) doc += "</tr>" doc += """</table>""" f["doc"] = doc self.typedoc.write(f["doc"]) subs = self.docParent.get(f["name"], []) + self.record_refs.get( f["name"], []) if len(subs) == 1: self.render_type(self.typemap[subs[0]], depth) else: for s in subs: self.render_type(self.typemap[s], depth + 1) for s in self.docAfter.get(f["name"], []): self.render_type(self.typemap[s], depth)
def render_type(self, f, depth): if f["name"] in self.rendered or f["name"] in self.redirects: return self.rendered.add(f["name"]) if "doc" not in f: f["doc"] = "" f["type"] = copy.deepcopy(f) f["doc"] = "" f = f["type"] if "doc" not in f: f["doc"] = "" f["doc"] = fix_doc(f["doc"]) if f["type"] == "record": for field in f.get("fields", []): if "doc" not in field: field["doc"] = "" if f["type"] != "documentation": lines = [] for l in f["doc"].splitlines(): if len(l) > 0 and l[0] == "#": l = ("#" * depth) + l lines.append(l) f["doc"] = "\n".join(lines) _, frg = urlparse.urldefrag(f["name"]) num = self.toc.add_entry(depth, frg) doc = "## %s %s\n" % (num, frg) else: doc = "" if self.title is None: self.title = f["doc"][0:f["doc"].index("\n")][2:] if f["type"] == "documentation": f["doc"] = number_headings(self.toc, f["doc"]) #if "extends" in f: # doc += "\n\nExtends " # doc += ", ".join([" %s" % linkto(ex) for ex in aslist(f["extends"])]) #if f["name"] in self.subs: # doc += "\n\nExtended by" # doc += ", ".join([" %s" % linkto(s) for s in self.subs[f["name"]]]) #if f["name"] in self.uses: # doc += "\n\nReferenced by" # doc += ", ".join([" [%s.%s](#%s)" % (s[0], s[1], to_id(s[0])) for s in self.uses[f["name"]]]) doc = doc + "\n\n" + f["doc"] doc = mistune.markdown(doc, renderer=MyRenderer()) if f["type"] == "record": doc += "<h3>Fields</h3>" doc += """<table class="table table-striped">""" doc += "<tr><th>field</th><th>type</th><th>required</th><th>description</th></tr>" for i in f.get("fields", []): doc += "<tr>" tp = i["type"] if isinstance(tp, list) and tp[0] == "null": opt = False tp = tp[1:] else: opt = True desc = i["doc"] #if "inherited_from" in i: # desc = "%s _Inherited from %s_" % (desc, linkto(i["inherited_from"])) frg = schema.avro_name(i["name"]) doc += "<td><code>%s</code></td><td>%s</td><td>%s</td><td>%s</td>" % ( frg, typefmt(tp, self.redirects), opt, mistune.markdown(desc)) doc += "</tr>" doc += """</table>""" f["doc"] = doc self.typedoc.write(f["doc"]) subs = self.docParent.get(f["name"], []) + self.record_refs.get( f["name"], []) if len(subs) == 1: self.render_type(self.typemap[subs[0]], depth) else: for s in subs: self.render_type(self.typemap[s], depth + 1) for s in self.docAfter.get(f["name"], []): self.render_type(self.typemap[s], depth)
def render_type(self, f, depth): if f["name"] in self.rendered or f["name"] in self.redirects: return self.rendered.add(f["name"]) if "doc" not in f: f["doc"] = "" f["type"] = copy.deepcopy(f) f["doc"] = "" f = f["type"] if "doc" not in f: f["doc"] = "" def extendsfrom(item, ex): if "extends" in item: for e in aslist(item["extends"]): ex.insert(0, self.typemap[e]) extendsfrom(self.typemap[e], ex) ex = [f] extendsfrom(f, ex) enumDesc = {} if f["type"] == "enum" and isinstance(f["doc"], list): for e in ex: for i in e["doc"]: idx = i.find(":") if idx > -1: enumDesc[i[:idx]] = i[idx+1:] e["doc"] = [i for i in e["doc"] if i.find(":") == -1 or i.find(" ") < i.find(":")] f["doc"] = fix_doc(f["doc"]) if f["type"] == "record": for field in f.get("fields", []): if "doc" not in field: field["doc"] = "" if f["type"] != "documentation": lines = [] for l in f["doc"].splitlines(): if len(l) > 0 and l[0] == "#": l = ("#" * depth) + l lines.append(l) f["doc"] = "\n".join(lines) _, frg = urlparse.urldefrag(f["name"]) num = self.toc.add_entry(depth, frg) doc = "## %s %s\n" % (num, frg) else: doc = "" if self.title is None: self.title = f["doc"][0:f["doc"].index("\n")][2:] if f["type"] == "documentation": f["doc"] = number_headings(self.toc, f["doc"]) #if "extends" in f: # doc += "\n\nExtends " # doc += ", ".join([" %s" % linkto(ex) for ex in aslist(f["extends"])]) #if f["name"] in self.subs: # doc += "\n\nExtended by" # doc += ", ".join([" %s" % linkto(s) for s in self.subs[f["name"]]]) #if f["name"] in self.uses: # doc += "\n\nReferenced by" # doc += ", ".join([" [%s.%s](#%s)" % (s[0], s[1], to_id(s[0])) for s in self.uses[f["name"]]]) doc = doc + "\n\n" + f["doc"] doc = mistune.markdown(doc, renderer=MyRenderer()) if f["type"] == "record": doc += "<h3>Fields</h3>" doc += """<table class="table table-striped">""" doc += "<tr><th>field</th><th>type</th><th>required</th><th>description</th></tr>" required = [] optional = [] for i in f.get("fields", []): tp = i["type"] if isinstance(tp, list) and tp[0] == "https://w3id.org/cwl/salad#null": opt = False tp = tp[1:] else: opt = True desc = i["doc"] #if "inherited_from" in i: # desc = "%s _Inherited from %s_" % (desc, linkto(i["inherited_from"])) frg = schema.avro_name(i["name"]) tr = "<td><code>%s</code></td><td>%s</td><td>%s</td><td>%s</td>" % (frg, self.typefmt(tp, self.redirects), opt, mistune.markdown(desc)) if opt: required.append(tr) else: optional.append(tr) for i in required+optional: doc += "<tr>" + i + "</tr>" doc += """</table>""" elif f["type"] == "enum": doc += "<h3>Symbols</h3>" doc += """<table class="table table-striped">""" doc += "<tr><th>symbol</th><th>description</th></tr>" for e in ex: for i in e.get("symbols", []): doc += "<tr>" frg = schema.avro_name(i) doc += "<td><code>%s</code></td><td>%s</td>" % (frg, enumDesc.get(frg, "")) doc += "</tr>" doc += """</table>""" f["doc"] = doc self.typedoc.write(f["doc"]) subs = self.docParent.get(f["name"], []) + self.record_refs.get(f["name"], []) if len(subs) == 1: self.render_type(self.typemap[subs[0]], depth) else: for s in subs: self.render_type(self.typemap[s], depth+1) for s in self.docAfter.get(f["name"], []): self.render_type(self.typemap[s], depth)
def render_type(self, f, depth): if f["name"] in self.rendered or f["name"] in self.redirects: return self.rendered.add(f["name"]) if "doc" not in f: f["doc"] = "" f["type"] = copy.deepcopy(f) f["doc"] = "" f = f["type"] if "doc" not in f: f["doc"] = "" f["doc"] = fix_doc(f["doc"]) if f["type"] == "record": for field in f.get("fields", []): if "doc" not in field: field["doc"] = "" if f["type"] != "documentation": lines = [] for l in f["doc"].splitlines(): if len(l) > 0 and l[0] == "#": l = ("#" * depth) + l lines.append(l) f["doc"] = "\n".join(lines) _, frg = urlparse.urldefrag(f["name"]) num = self.toc.add_entry(depth, frg) doc = "## %s %s\n" % (num, frg) else: doc = "" if self.title is None: self.title = f["doc"][0:f["doc"].index("\n")][2:] if f["type"] == "documentation": f["doc"] = number_headings(self.toc, f["doc"]) #if "extends" in f: # doc += "\n\nExtends " # doc += ", ".join([" %s" % linkto(ex) for ex in aslist(f["extends"])]) #if f["name"] in self.subs: # doc += "\n\nExtended by" # doc += ", ".join([" %s" % linkto(s) for s in self.subs[f["name"]]]) #if f["name"] in self.uses: # doc += "\n\nReferenced by" # doc += ", ".join([" [%s.%s](#%s)" % (s[0], s[1], to_id(s[0])) for s in self.uses[f["name"]]]) doc = doc + "\n\n" + f["doc"] doc = mistune.markdown(doc, renderer=MyRenderer()) if f["type"] == "record": doc += "<h3>Fields</h3>" doc += """<table class="table table-striped">""" doc += "<tr><th>field</th><th>type</th><th>required</th><th>description</th></tr>" for i in f.get("fields", []): doc += "<tr>" tp = i["type"] if isinstance(tp, list) and tp[0] == "null": opt = False tp = tp[1:] else: opt = True desc = i["doc"] #if "inherited_from" in i: # desc = "%s _Inherited from %s_" % (desc, linkto(i["inherited_from"])) frg = schema.avro_name(i["name"]) doc += "<td><code>%s</code></td><td>%s</td><td>%s</td><td>%s</td>" % (frg, typefmt(tp, self.redirects), opt, mistune.markdown(desc)) doc += "</tr>" doc += """</table>""" f["doc"] = doc self.typedoc.write(f["doc"]) subs = self.docParent.get(f["name"], []) + self.record_refs.get(f["name"], []) if len(subs) == 1: self.render_type(self.typemap[subs[0]], depth) else: for s in subs: self.render_type(self.typemap[s], depth+1) for s in self.docAfter.get(f["name"], []): self.render_type(self.typemap[s], depth)