433
class DocGrokView(GAIAView):
434
"""A base DocGrok view.
436
This view is used for all things not covered by other, more
440
grok.context(DocGrok)
442
grok.require('grok.ManageApplications')
444
def getDoc(self, text=None, heading_only=False):
445
"""Get the doc string of the module STX formatted."""
448
if (hasattr(self.context, "apidoc") and
449
hasattr(self.context.apidoc, "getDocString")):
450
text = self.context.apidoc.getDocString()
453
lines = text.strip().split('\n')
454
if len(lines) and heading_only:
455
# Find first empty line to separate heading from trailing text.
458
if line.strip() == "":
460
headlines.append(line)
462
# Get rid of possible CVS id.
463
lines = [line for line in lines if not line.startswith('$Id')]
464
return renderText('\n'.join(lines), self.context.getPath())
466
def getDocHeading(self, text=None):
467
return self.getDoc(text, True)
469
def getPathParts(self, path=None):
470
"""Get parts of a dotted name as url and name parts.
473
path = self.context.path
476
return getDottedPathDict(path)
479
for part in path.split('.'):
486
'url':"/docgrok/%s" % (part_path,)
491
def getEntries(self, columns=True):
492
"""Return info objects for all modules and classes in the
493
associated apidoc container.
496
if (not hasattr(self.context, "apidoc") or
497
not hasattr(self.context.apidoc, "items")):
500
for name, obj in self.context.apidoc.items():
504
'path': getPythonPath(removeAllProxies(obj)),
509
'isinterface' : False,
511
'isfunction' : False,
512
'istextfile' : False,
513
'iszcmlfile' : False,
516
entry['url'] = "%s/%s" % (self.context.path.replace('.','/'), name)
517
if hasattr(obj,"getDocString"):
518
entry['doc'] = self.getDocHeading(obj.getDocString())
519
elif hasattr(obj, "getDoc") and isinstance(
520
removeAllProxies(obj), InterfaceClass):
521
entry['doc'] = self.getDocHeading(obj.getDoc())
522
if isinstance(obj, Class):
523
entry['isclass'] = True
524
elif isinstance(obj, TextFile):
525
entry['istextfile'] = True
526
elif isinstance(obj, ZCMLFile):
527
entry['iszcmlfile'] = True
528
elif isinstance(obj,Function):
529
entry['isfunction'] = True
530
if hasattr(obj, 'getSignature'):
531
entry['signature'] = obj.getSignature()
532
elif (isinstance(obj, Module) and
533
os.path.basename(obj.getFileName()) in
534
['__init.py__', '__init__.pyc', '__init__.pyo']):
535
entry['ispackage'] = True
536
elif isinstance(obj, Module):
537
entry['ismodule'] = True
538
elif isinstance(obj, InterfaceClass):
539
entry['isinterface'] = True
540
entries.append(entry)
542
entries.sort(lambda x, y: cmp(x['name'], y['name']))
546
self.docgrok_root = self.context._traversal_root
547
self.app_root = self.docgrok_root.__parent__
551
class DocGrokPackageView(DocGrokView):
552
"""A view for packages handled by DocGrok."""
554
grok.context(DocGrokPackage)
558
class DocGrokModuleView(DocGrokView):
559
"""A view for modules handled by DocGrok."""
561
grok.context(DocGrokModule)
565
class DocGrokClassView(DocGrokView):
566
"""A view for classes handled by DocGrok."""
568
grok.context(DocGrokClass)
572
return self._listClasses(self.context.apidoc.getBases())
574
def getInterfaces(self):
575
return self._listClasses(
576
[iface for iface in self.context.apidoc.getInterfaces()])
578
def getAttributes(self):
579
attrs = self.context.getAttributes()
581
a['interface'] = self._listClasses([a['interface']])
584
def getMethods(self):
585
methods = self.context.getMethods()
587
m['doc'] = renderText(m['attr'].__doc__ or '',
588
inspect.getmodule(m['attr']))
589
m['interface'] = self._listClasses([m['interface']])
592
def _listClasses(self, classes):
595
unwrapped_cls = removeAllProxies(cls)
596
fullpath = getPythonPath(unwrapped_cls)
599
path, name = fullpath.rsplit('.', 1)
601
'path': path or None,
602
'path_parts' : self.getPathParts(path) or None,
604
'url': fullpath and fullpath.replace('.','/') or None,
605
'doc': self.getDocHeading(cls.__doc__) or None
610
class DocGrokInterfaceView(DocGrokClassView):
612
grok.context(DocGrokInterface)
616
class DocGrokGrokApplicationView(DocGrokClassView):
618
grok.context(DocGrokGrokApplication)
622
class DocGrokTextFileView(DocGrokView):
624
grok.context(DocGrokTextFile)
627
def getContent(self):
628
lines = self.context.getContent()
629
if self.context.path.endswith('.stx'):
630
format = 'zope.source.stx'
632
format = 'zope.source.rest'
633
return renderText(lines, format=format)
635
def getPackagePathParts(self):
636
return self.getPathParts(
637
self.context.getPackagePath())