Document a single collection in an API. Args: resource: Collection or service being documented. path: string, Dot separated name of the resource. root_discovery: Deserialized discovery document. discovery: Deserialized discovery document, but just the portion that
(resource, path, root_discovery, discovery, css=CSS)
| 297 | |
| 298 | |
| 299 | def document_collection(resource, path, root_discovery, discovery, css=CSS): |
| 300 | """Document a single collection in an API. |
| 301 | |
| 302 | Args: |
| 303 | resource: Collection or service being documented. |
| 304 | path: string, Dot separated name of the resource. |
| 305 | root_discovery: Deserialized discovery document. |
| 306 | discovery: Deserialized discovery document, but just the portion that |
| 307 | describes the resource. |
| 308 | css: string, The CSS to include in the generated file. |
| 309 | """ |
| 310 | collections = [] |
| 311 | methods = [] |
| 312 | resource_name = path.split(".")[-2] |
| 313 | html = [ |
| 314 | "<html><body>", |
| 315 | css, |
| 316 | "<h1>%s</h1>" % breadcrumbs(path[:-1], root_discovery), |
| 317 | "<h2>Instance Methods</h2>", |
| 318 | ] |
| 319 | |
| 320 | # Which methods are for collections. |
| 321 | for name in dir(resource): |
| 322 | if not name.startswith("_") and callable(getattr(resource, name)): |
| 323 | if hasattr(getattr(resource, name), "__is_resource__"): |
| 324 | collections.append(name) |
| 325 | else: |
| 326 | methods.append(name) |
| 327 | |
| 328 | # TOC |
| 329 | if collections: |
| 330 | for name in collections: |
| 331 | if not name.startswith("_") and callable(getattr(resource, name)): |
| 332 | href = path + name + ".html" |
| 333 | html.append( |
| 334 | string.Template(COLLECTION_LINK).substitute(href=href, name=name) |
| 335 | ) |
| 336 | |
| 337 | if methods: |
| 338 | for name in methods: |
| 339 | if not name.startswith("_") and callable(getattr(resource, name)): |
| 340 | doc = getattr(resource, name).__doc__ |
| 341 | params = method_params(doc) |
| 342 | firstline = doc.splitlines()[0] |
| 343 | html.append( |
| 344 | string.Template(METHOD_LINK).substitute( |
| 345 | name=name, params=params, firstline=firstline |
| 346 | ) |
| 347 | ) |
| 348 | |
| 349 | if methods: |
| 350 | html.append("<h3>Method Details</h3>") |
| 351 | for name in methods: |
| 352 | dname = name.rsplit("_")[0] |
| 353 | html.append(method(name, getattr(resource, name).__doc__)) |
| 354 | |
| 355 | html.append("</body></html>") |
| 356 |
no test coverage detected
searching dependent graphs…