|
17 | 17 | EXCLUDE = { |
18 | 18 | } |
19 | 19 |
|
20 | | -# For each class to document, it is possible to: |
21 | | -# 1) Document only the class: [classA, classB, ...] |
22 | | -# 2) Document all its methods: [classA, (classB, "*")] |
23 | | -# 3) Choose which methods to document (methods listed as strings): |
24 | | -# [classA, (classB, ["method1", "method2", ...]), ...] |
25 | | -# 4) Choose which methods to document (methods listed as qualified names): |
26 | | -# [classA, (classB, [module.classB.method1, module.classB.method2, ...]), ...] |
| 20 | + |
27 | 21 | PAGES = [ |
28 | 22 | { |
29 | | - 'page': 'fbotics.md', |
| 23 | + 'page': '_templates/generic_template/generic_template.md', |
| 24 | + 'classes': [ |
| 25 | + fbotics.models.payloads.generic_template.GenericTemplatePayload, |
| 26 | + fbotics.models.payloads.generic_template.GenericElement, |
| 27 | + fbotics.models.payloads.generic_template.GenericDefaultAction, |
| 28 | + ], |
| 29 | + }, |
| 30 | + { |
| 31 | + 'page': '_templates/button_template/button_template.md', |
| 32 | + 'classes': [ |
| 33 | + fbotics.models.payloads.button_template.ButtonTemplatePayload, |
| 34 | + ], |
| 35 | + }, |
| 36 | + { |
| 37 | + 'page': 'send/client.md', |
30 | 38 | 'methods': [ |
31 | 39 | fbotics.Client.send_message, |
32 | 40 | fbotics.Client.retrieve_supported_tags, |
33 | 41 | ], |
34 | 42 | }, |
35 | 43 | { |
36 | | - 'page': 'buttons.md', |
| 44 | + 'page': 'quick_replies/quick_replies.md', |
| 45 | + 'classes': [ |
| 46 | + fbotics.models.quick_reply.QuickReply, |
| 47 | + ], |
| 48 | + }, |
| 49 | + { |
| 50 | + 'page': 'send/request.md', |
| 51 | + 'classes': [ |
| 52 | + fbotics.models.request.Request, |
| 53 | + ], |
| 54 | + }, |
| 55 | + { |
| 56 | + 'page': 'send/recipient.md', |
| 57 | + 'classes': [ |
| 58 | + fbotics.models.recipient.Recipient, |
| 59 | + ], |
| 60 | + }, |
| 61 | + { |
| 62 | + 'page': 'buttons/buttons.md', |
37 | 63 | 'classes': [ |
38 | 64 | fbotics.models.buttons.WebUrlButton, |
39 | 65 | fbotics.models.buttons.CallButton, |
40 | 66 | fbotics.models.buttons.PostbackButton |
41 | 67 | ], |
42 | 68 | }, |
43 | 69 | { |
44 | | - 'page': 'message.md', |
| 70 | + 'page': 'send/message.md', |
45 | 71 | 'classes': [ |
46 | 72 | fbotics.models.message.Message, |
47 | 73 | ], |
48 | 74 | }, |
49 | 75 | { |
50 | | - 'page': 'templates.md', |
| 76 | + 'page': 'send/attachment.md', |
51 | 77 | 'classes': [ |
52 | | - fbotics.models.payloads.button_template.ButtonTemplatePayload, |
53 | | - fbotics.models.payloads.generic_template.GenericTemplatePayload, |
54 | | - fbotics.models.payloads.generic_template.GenericElement, |
55 | | - fbotics.models.payloads.generic_template.GenericDefaultAction, |
56 | | - fbotics.models.payloads.rich_media.RichMediaPayload |
| 78 | + fbotics.models.attachment.Attachment, |
57 | 79 | ], |
58 | | - } |
| 80 | + }, |
59 | 81 | ] |
60 | 82 |
|
61 | 83 | ROOT = 'http://fbotics.io/' |
62 | 84 |
|
| 85 | +def get_class_attr(Cls) -> []: |
| 86 | + import re |
| 87 | + return [a for a, v in Cls.__dict__.items() |
| 88 | + if not re.match('<function.*?>', str(v)) |
| 89 | + and not (a.startswith('__') and a.endswith('__'))] |
| 90 | + |
| 91 | +def get_class_attr_val(cls): |
| 92 | + attr = get_class_attr(type(cls)) |
| 93 | + attr_dict = {} |
| 94 | + for a in attr: |
| 95 | + attr_dict[a] = getattr(cls, a) |
| 96 | + return attr_dict |
| 97 | + |
63 | 98 |
|
64 | 99 | def get_function_signature(function, method=True): |
65 | 100 | wrapped = getattr(function, '_original_function', None) |
| 101 | + |
66 | 102 | if wrapped is None: |
67 | 103 | signature = inspect.getargspec(function) |
68 | 104 | else: |
@@ -93,17 +129,23 @@ def get_function_signature(function, method=True): |
93 | 129 |
|
94 | 130 |
|
95 | 131 | def get_class_signature(cls): |
96 | | - try: |
97 | | - class_signature = get_function_signature(cls.__init__) |
98 | | - class_signature = class_signature.replace('__init__', cls.__name__) |
99 | | - except (TypeError, AttributeError): |
100 | | - # in case the class inherits from object and does not |
101 | | - # define __init__ |
102 | | - class_signature = "{clean_module_name}.{cls_name}()".format( |
103 | | - clean_module_name=clean_module_name(cls.__module__), |
104 | | - cls_name=cls.__name__ |
105 | | - ) |
106 | | - return post_process_signature(class_signature) |
| 132 | + signature = '%s.%s(' % (cls.__module__, cls.__name__) |
| 133 | + class_attr_value_dict = get_class_attr_val(cls()) |
| 134 | + class_attr_value_dict.pop("_schema") |
| 135 | + for k, v in class_attr_value_dict.items(): |
| 136 | + signature += str(k) + "=" + str(v) + ', ' |
| 137 | + signature = signature[:-2] + ')' |
| 138 | + #try: |
| 139 | + # class_signature = get_function_signature(cls.__init__) |
| 140 | + # class_signature = class_signature.replace('__init__', cls.__name__) |
| 141 | + #except (TypeError, AttributeError): |
| 142 | + # # in case the class inherits from object and does not |
| 143 | + # # define __init__ |
| 144 | + # class_signature = "{clean_module_name}.{cls_name}()".format( |
| 145 | + # clean_module_name=clean_module_name(cls.__module__), |
| 146 | + # cls_name=cls.__name__ |
| 147 | + # ) |
| 148 | + return post_process_signature(signature) |
107 | 149 |
|
108 | 150 |
|
109 | 151 | def post_process_signature(signature): |
|
0 commit comments