232 self.__formatDescription(self.module.description), |
232 self.__formatDescription(self.module.description), |
233 'GlobalsList' : globalsList, |
233 'GlobalsList' : globalsList, |
234 'ClassList' : classList, |
234 'ClassList' : classList, |
235 'FunctionList' : functionList, |
235 'FunctionList' : functionList, |
236 } |
236 } |
237 except TagError, e: |
237 except TagError as e: |
238 sys.stderr.write("Error in tags of description of module %s.\n" % \ |
238 sys.stderr.write("Error in tags of description of module %s.\n" % \ |
239 self.module.name) |
239 self.module.name) |
240 sys.stderr.write("%s\n" % e) |
240 sys.stderr.write("%s\n" % e) |
241 return "" |
241 return "" |
242 |
242 |
374 'ClassDescription' : self.__formatDescription(_class.description), |
370 'ClassDescription' : self.__formatDescription(_class.description), |
375 'GlobalsList' : globalsList, |
371 'GlobalsList' : globalsList, |
376 'MethodList' : methList, |
372 'MethodList' : methList, |
377 'MethodDetails' : methBodies, |
373 'MethodDetails' : methBodies, |
378 } |
374 } |
379 except TagError, e: |
375 except TagError as e: |
380 sys.stderr.write("Error in tags of description of class %s.\n" % \ |
376 sys.stderr.write("Error in tags of description of class %s.\n" % \ |
381 className) |
377 className) |
382 sys.stderr.write("%s\n" % e) |
378 sys.stderr.write("%s\n" % e) |
383 clsBody = "" |
379 clsBody = "" |
384 |
380 |
430 @param className Name of the class containing the method. (string) |
426 @param className Name of the class containing the method. (string) |
431 @return The method list and method details section. (tuple of two string) |
427 @return The method list and method details section. (tuple of two string) |
432 """ |
428 """ |
433 methList = [] |
429 methList = [] |
434 methBodies = [] |
430 methBodies = [] |
435 methods = obj.methods.keys() |
431 methods = sorted(list(obj.methods.keys())) |
436 methods.sort() |
|
437 |
|
438 # first do the constructor |
|
439 if '__init__' in methods: |
432 if '__init__' in methods: |
440 methods.remove('__init__') |
433 methods.remove('__init__') |
441 try: |
434 try: |
442 methBody = self.constructorTemplate % { \ |
435 methBody = self.constructorTemplate % { \ |
443 'Anchor' : className, |
436 'Anchor' : className, |
445 'Method' : '__init__', |
438 'Method' : '__init__', |
446 'MethodDescription' : \ |
439 'MethodDescription' : \ |
447 self.__formatDescription(obj.methods['__init__'].description), |
440 self.__formatDescription(obj.methods['__init__'].description), |
448 'Params' : ', '.join(obj.methods['__init__'].parameters[1:]), |
441 'Params' : ', '.join(obj.methods['__init__'].parameters[1:]), |
449 } |
442 } |
450 except TagError, e: |
443 except TagError as e: |
451 sys.stderr.write("Error in tags of description of method %s.%s.\n" % \ |
444 sys.stderr.write("Error in tags of description of method %s.%s.\n" % \ |
452 (className, '__init__')) |
445 (className, '__init__')) |
453 sys.stderr.write("%s\n" % e) |
446 sys.stderr.write("%s\n" % e) |
454 methBody = "" |
447 methBody = "" |
455 methBodies.append(methBody) |
448 methBodies.append(methBody) |
462 'Method' : obj.methods[method].name, |
455 'Method' : obj.methods[method].name, |
463 'MethodDescription' : \ |
456 'MethodDescription' : \ |
464 self.__formatDescription(obj.methods[method].description), |
457 self.__formatDescription(obj.methods[method].description), |
465 'Params' : ', '.join(obj.methods[method].parameters[1:]), |
458 'Params' : ', '.join(obj.methods[method].parameters[1:]), |
466 } |
459 } |
467 except TagError, e: |
460 except TagError as e: |
468 sys.stderr.write("Error in tags of description of method %s.%s.\n" % \ |
461 sys.stderr.write("Error in tags of description of method %s.%s.\n" % \ |
469 (className, method)) |
462 (className, method)) |
470 sys.stderr.write("%s\n" % e) |
463 sys.stderr.write("%s\n" % e) |
471 methBody = "" |
464 methBody = "" |
472 methBodies.append(methBody) |
465 methBodies.append(methBody) |
483 """ |
476 """ |
484 Private method to generate the document section with details about Ruby modules. |
477 Private method to generate the document section with details about Ruby modules. |
485 |
478 |
486 @return The Ruby modules details section. (string) |
479 @return The Ruby modules details section. (string) |
487 """ |
480 """ |
488 rbModulesNames = self.module.modules.keys() |
481 rbModulesNames = sorted(list(self.module.modules.keys())) |
489 rbModulesNames.sort() |
|
490 rbModules = [] |
482 rbModules = [] |
491 for rbModuleName in rbModulesNames: |
483 for rbModuleName in rbModulesNames: |
492 rbModule = self.module.modules[rbModuleName] |
484 rbModule = self.module.modules[rbModuleName] |
493 globalsList = self.__genGlobalsListSection(rbModule) |
485 globalsList = self.__genGlobalsListSection(rbModule) |
494 methList, methBodies = self.__genMethodSection(rbModule, rbModuleName) |
486 methList, methBodies = self.__genMethodSection(rbModule, rbModuleName) |
504 'ClassesList' : classList, |
496 'ClassesList' : classList, |
505 'ClassesDetails' : classBodies, |
497 'ClassesDetails' : classBodies, |
506 'FunctionsList' : methList, |
498 'FunctionsList' : methList, |
507 'FunctionsDetails' : methBodies, |
499 'FunctionsDetails' : methBodies, |
508 } |
500 } |
509 except TagError, e: |
501 except TagError as e: |
510 sys.stderr.write("Error in tags of description of Ruby module %s.\n" % \ |
502 sys.stderr.write("Error in tags of description of Ruby module %s.\n" % \ |
511 rbModuleName) |
503 rbModuleName) |
512 sys.stderr.write("%s\n" % e) |
504 sys.stderr.write("%s\n" % e) |
513 rbmBody = "" |
505 rbmBody = "" |
514 |
506 |
522 |
514 |
523 @param obj Reference to the object being formatted. |
515 @param obj Reference to the object being formatted. |
524 @param modName Name of the Ruby module containing the classes. (string) |
516 @param modName Name of the Ruby module containing the classes. (string) |
525 @return The classes list and classes details section. (tuple of two string) |
517 @return The classes list and classes details section. (tuple of two string) |
526 """ |
518 """ |
527 classNames = obj.classes.keys() |
519 classNames = sorted(list(obj.classes.keys())) |
528 classNames.sort() |
|
529 classes = [] |
520 classes = [] |
530 for className in classNames: |
521 for className in classNames: |
531 _class = obj.classes[className] |
522 _class = obj.classes[className] |
532 supers = _class.super |
523 supers = _class.super |
533 if len(supers) > 0: |
524 if len(supers) > 0: |
545 'ClassSuper' : supers, |
536 'ClassSuper' : supers, |
546 'ClassDescription' : self.__formatDescription(_class.description), |
537 'ClassDescription' : self.__formatDescription(_class.description), |
547 'MethodList' : methList, |
538 'MethodList' : methList, |
548 'MethodDetails' : methBodies, |
539 'MethodDetails' : methBodies, |
549 } |
540 } |
550 except TagError, e: |
541 except TagError as e: |
551 sys.stderr.write("Error in tags of description of class %s.\n" % \ |
542 sys.stderr.write("Error in tags of description of class %s.\n" % \ |
552 className) |
543 className) |
553 sys.stderr.write("%s\n" % e) |
544 sys.stderr.write("%s\n" % e) |
554 clsBody = "" |
545 clsBody = "" |
555 |
546 |
592 Private method to generate the document section with details about functions. |
583 Private method to generate the document section with details about functions. |
593 |
584 |
594 @return The functions details section. (string) |
585 @return The functions details section. (string) |
595 """ |
586 """ |
596 funcBodies = [] |
587 funcBodies = [] |
597 funcNames = self.module.functions.keys() |
588 funcNames = sorted(list(self.module.functions.keys())) |
598 funcNames.sort() |
|
599 for funcName in funcNames: |
589 for funcName in funcNames: |
600 try: |
590 try: |
601 funcBody = self.functionTemplate % { \ |
591 funcBody = self.functionTemplate % { \ |
602 'Anchor' : funcName, |
592 'Anchor' : funcName, |
603 'Function' : self.module.functions[funcName].name, |
593 'Function' : self.module.functions[funcName].name, |
604 'FunctionDescription' : self.__formatDescription(\ |
594 'FunctionDescription' : self.__formatDescription(\ |
605 self.module.functions[funcName].description), |
595 self.module.functions[funcName].description), |
606 'Params' : ', '.join(self.module.functions[funcName].parameters), |
596 'Params' : ', '.join(self.module.functions[funcName].parameters), |
607 } |
597 } |
608 except TagError, e: |
598 except TagError as e: |
609 sys.stderr.write("Error in tags of description of function %s.\n" % \ |
599 sys.stderr.write("Error in tags of description of function %s.\n" % \ |
610 funcName) |
600 funcName) |
611 sys.stderr.write("%s\n" % e) |
601 sys.stderr.write("%s\n" % e) |
612 funcBody = "" |
602 funcBody = "" |
613 |
603 |
793 """ |
782 """ |
794 start = desc.find('{@') |
783 start = desc.find('{@') |
795 while start != -1: |
784 while start != -1: |
796 stop = desc.find('}', start + 2) |
785 stop = desc.find('}', start + 2) |
797 if stop == -1: |
786 if stop == -1: |
798 raise TagError, "Unterminated inline tag.\n%s" % desc |
787 raise TagError("Unterminated inline tag.\n%s" % desc) |
799 |
788 |
800 tagText = desc[start + 1:stop] |
789 tagText = desc[start + 1:stop] |
801 if tagText.startswith('@link'): |
790 if tagText.startswith('@link'): |
802 parts = tagText.split(None, 1) |
791 parts = tagText.split(None, 1) |
803 if len(parts) < 2: |
792 if len(parts) < 2: |
804 raise TagError, "Wrong format in inline tag %s.\n%s" % \ |
793 raise TagError("Wrong format in inline tag %s.\n%s" % \ |
805 (parts[0], desc) |
794 (parts[0], desc)) |
806 |
795 |
807 formattedTag = self.__formatCrossReferenceEntry(parts[1]) |
796 formattedTag = self.__formatCrossReferenceEntry(parts[1]) |
808 desc = desc.replace("{%s}" % tagText, formattedTag) |
797 desc = desc.replace("{%s}" % tagText, formattedTag) |
809 else: |
798 else: |
810 tag = tagText.split(None, 1)[0] |
799 tag = tagText.split(None, 1)[0] |
811 raise TagError, "Unknown inline tag encountered, %s.\n%s" % \ |
800 raise TagError("Unknown inline tag encountered, %s.\n%s" % \ |
812 (tag, desc) |
801 (tag, desc)) |
813 |
802 |
814 start = desc.find('{@') |
803 start = desc.find('{@') |
815 |
804 |
816 return desc |
805 return desc |
817 |
806 |
862 lastItem = paramList[-1][1] |
851 lastItem = paramList[-1][1] |
863 elif desc.startswith("@return"): |
852 elif desc.startswith("@return"): |
864 inTagSection = True |
853 inTagSection = True |
865 parts = desc.split(None, 1) |
854 parts = desc.split(None, 1) |
866 if len(parts) < 2: |
855 if len(parts) < 2: |
867 raise TagError, "Wrong format in %s line.\n" % parts[0] |
856 raise TagError("Wrong format in %s line.\n" % parts[0]) |
868 returns = [parts[1]] |
857 returns = [parts[1]] |
869 lastItem = returns |
858 lastItem = returns |
870 elif desc.startswith("@exception") or \ |
859 elif desc.startswith("@exception") or \ |
871 desc.startswith("@throws") or \ |
860 desc.startswith("@throws") or \ |
872 desc.startswith("@raise"): |
861 desc.startswith("@raise"): |
873 inTagSection = True |
862 inTagSection = True |
874 parts = desc.split(None, 2) |
863 parts = desc.split(None, 2) |
875 if len(parts) < 2: |
864 if len(parts) < 2: |
876 raise TagError, "Wrong format in %s line.\n" % parts[0] |
865 raise TagError("Wrong format in %s line.\n" % parts[0]) |
877 excName = parts[1] |
866 excName = parts[1] |
878 try: |
867 try: |
879 exceptionDict[excName] = [parts[2]] |
868 exceptionDict[excName] = [parts[2]] |
880 except IndexError: |
869 except IndexError: |
881 exceptionDict[excName] = [] |
870 exceptionDict[excName] = [] |
882 lastItem = exceptionDict[excName] |
871 lastItem = exceptionDict[excName] |
883 elif desc.startswith("@signal"): |
872 elif desc.startswith("@signal"): |
884 inTagSection = True |
873 inTagSection = True |
885 m = _signal(desc,0) |
874 m = _signal(desc,0) |
886 if m is None: |
875 if m is None: |
887 raise TagError, "Wrong format in %s line.\n" % parts[0] |
876 raise TagError("Wrong format in %s line.\n" % parts[0]) |
888 signalName = 1 and m.group("SignalName1") \ |
877 signalName = 1 and m.group("SignalName1") \ |
889 or m.group("SignalName2") |
878 or m.group("SignalName2") |
890 signalDesc = 1 and m.group("SignalDescription1") \ |
879 signalDesc = 1 and m.group("SignalDescription1") \ |
891 or m.group("SignalDescription2") |
880 or m.group("SignalDescription2") |
892 signalDict[signalName] = [] |
881 signalDict[signalName] = [] |
895 lastItem = signalDict[signalName] |
884 lastItem = signalDict[signalName] |
896 elif desc.startswith("@event"): |
885 elif desc.startswith("@event"): |
897 inTagSection = True |
886 inTagSection = True |
898 m = _event(desc,0) |
887 m = _event(desc,0) |
899 if m is None: |
888 if m is None: |
900 raise TagError, "Wrong format in %s line.\n" % parts[0] |
889 raise TagError("Wrong format in %s line.\n" % parts[0]) |
901 eventName = 1 and m.group("EventName1") \ |
890 eventName = 1 and m.group("EventName1") \ |
902 or m.group("EventName2") |
891 or m.group("EventName2") |
903 eventDesc = 1 and m.group("EventDescription1") \ |
892 eventDesc = 1 and m.group("EventDescription1") \ |
904 or m.group("EventDescription2") |
893 or m.group("EventDescription2") |
905 eventDict[eventName] = [] |
894 eventDict[eventName] = [] |
908 lastItem = eventDict[eventName] |
897 lastItem = eventDict[eventName] |
909 elif desc.startswith("@deprecated"): |
898 elif desc.startswith("@deprecated"): |
910 inTagSection = True |
899 inTagSection = True |
911 parts = desc.split(None, 1) |
900 parts = desc.split(None, 1) |
912 if len(parts) < 2: |
901 if len(parts) < 2: |
913 raise TagError, "Wrong format in %s line.\n" % parts[0] |
902 raise TagError("Wrong format in %s line.\n" % parts[0]) |
914 deprecated = [parts[1]] |
903 deprecated = [parts[1]] |
915 lastItem = deprecated |
904 lastItem = deprecated |
916 elif desc.startswith("@author"): |
905 elif desc.startswith("@author"): |
917 inTagSection = True |
906 inTagSection = True |
918 parts = desc.split(None, 1) |
907 parts = desc.split(None, 1) |
919 if len(parts) < 2: |
908 if len(parts) < 2: |
920 raise TagError, "Wrong format in %s line.\n" % parts[0] |
909 raise TagError("Wrong format in %s line.\n" % parts[0]) |
921 authorInfo = [parts[1]] |
910 authorInfo = [parts[1]] |
922 lastItem = authorInfo |
911 lastItem = authorInfo |
923 elif desc.startswith("@since"): |
912 elif desc.startswith("@since"): |
924 inTagSection = True |
913 inTagSection = True |
925 parts = desc.split(None, 1) |
914 parts = desc.split(None, 1) |
926 if len(parts) < 2: |
915 if len(parts) < 2: |
927 raise TagError, "Wrong format in %s line.\n" % parts[0] |
916 raise TagError("Wrong format in %s line.\n" % parts[0]) |
928 sinceInfo = [parts[1]] |
917 sinceInfo = [parts[1]] |
929 lastItem = sinceInfo |
918 lastItem = sinceInfo |
930 elif desc.startswith("@see"): |
919 elif desc.startswith("@see"): |
931 inTagSection = True |
920 inTagSection = True |
932 parts = desc.split(None, 1) |
921 parts = desc.split(None, 1) |
933 if len(parts) < 2: |
922 if len(parts) < 2: |
934 raise TagError, "Wrong format in %s line.\n" % parts[0] |
923 raise TagError("Wrong format in %s line.\n" % parts[0]) |
935 seeList.append([parts[1]]) |
924 seeList.append([parts[1]]) |
936 lastItem = seeList[-1] |
925 lastItem = seeList[-1] |
937 elif desc.startswith("@@"): |
926 elif desc.startswith("@@"): |
938 lastItem.append(desc[1:]) |
927 lastItem.append(desc[1:]) |
939 elif desc.startswith("@"): |
928 elif desc.startswith("@"): |
940 tag = desc.split(None, 1)[0] |
929 tag = desc.split(None, 1)[0] |
941 raise TagError, "Unknown tag encountered, %s.\n" % tag |
930 raise TagError("Unknown tag encountered, %s.\n" % tag) |
942 else: |
931 else: |
943 lastItem.append(ditem) |
932 lastItem.append(ditem) |
944 elif not inTagSection: |
933 elif not inTagSection: |
945 lastItem.append(ditem) |
934 lastItem.append(ditem) |
946 |
935 |