def combine_platforms_and_since(annotated_obj): parent = annotated_obj.parent obj = annotated_obj.api_obj result = [] platforms = None since = DEFAULT_SINCE if dict_has_non_empty_member(obj, "platforms"): platforms = obj["platforms"] # Method/property/event can't have more platforms than the types they belong to. if (platforms is None or isinstance(annotated_obj, AnnotatedMethod) or isinstance(annotated_obj, AnnotatedProperty) or isinstance(annotated_obj, AnnotatedEvent)): if parent is not None: if dict_has_non_empty_member(parent.api_obj, "platforms"): if platforms is None or len(parent.api_obj["platforms"]) < len(platforms): platforms = parent.api_obj["platforms"] # Last resort is the default list of platforms if platforms is None: platforms = DEFAULT_PLATFORMS if "since" in obj and len(obj["since"]) > 0: since = obj["since"] else: # If a method/event/property we can check type's "since" if (isinstance(annotated_obj, AnnotatedMethod) or isinstance(annotated_obj, AnnotatedProperty) or isinstance(annotated_obj, AnnotatedEvent)): if (parent is not None and dict_has_non_empty_member(parent.api_obj, "since")): since = parent.api_obj["since"] since_is_dict = isinstance(since, dict) for name in platforms: one_platform = {"name": name, "pretty_name": pretty_platform_name(name)} if not since_is_dict: one_platform["since"] = since if one_platform["name"] == "mobileweb": if len(since) >= 3: if float(since[0:3]) < float(DEFAULT_MOBILEWEB_SINCE[0:3]): one_platform["since"] = DEFAULT_MOBILEWEB_SINCE else: if name in since: one_platform["since"] = since[name] else: if one_platform["name"] == "mobileweb": one_platform["since"] = DEFAULT_MOBILEWEB_SINCE else: one_platform["since"] = DEFAULT_SINCE result.append(one_platform) # Be sure no "since" is _before_ a parent object since. if parent and parent.platforms: for entry in result: platform_name = entry["name"] version_parts = entry["since"].split(".") for parent_entry in parent.platforms: if parent_entry["name"] == platform_name: parent_version_parts = parent_entry["since"].split(".") if parent_version_parts > version_parts: entry["since"] = parent_entry["since"] break return result
def to_jsca_function(method): log.trace("%s.%s" % (method.parent.name, method.name)) creatable = False; if dict_has_non_empty_member(method.parent.api_obj, "extends"): ancestor = method.parent.api_obj["extends"] if (ancestor == "Titanium.Proxy" or ancestor == "Titanium.UI.View"): creatable = True; if ("createable" in method.parent.api_obj): creatable = method.parent.api_obj["createable"] result = { "name": method.name, "deprecated": method.deprecated is not None and len(method.deprecated) > 0, "description": "" if "summary" not in method.api_obj else to_jsca_description(method.api_obj["summary"], method) } if dict_has_non_empty_member(method.api_obj, "returns") and method.api_obj["returns"] != "void": result["returnTypes"] = to_jsca_return_types(method.api_obj["returns"]) if method.parameters is not None and len(method.parameters) > 0: result["parameters"] = [to_jsca_method_parameter(p) for p in method.parameters] result["since"] = to_jsca_since(method.platforms) result['userAgents'] = to_jsca_userAgents(method.platforms) result['isInstanceProperty'] = True if creatable else False result['isClassProperty'] = False if creatable else True result['isInternal'] = False # we don't make this distinction (yet anyway) result['examples'] = to_jsca_examples(method) result['references'] = [] # we don't use the notion of 'references' (yet anyway) result['exceptions'] = [] # we don't specify exceptions (yet anyway) result['isConstructor'] = False # we don't expose native class constructors result['isMethod'] = True # all of our functions are class instance functions, ergo methods return to_ordered_dict(result, ('name',))
def append_setters_getters(self, methods): def since_for_yaml(since): if isinstance(since, basestring): new_since = '"%s"' % since elif isinstance(since, dict): new_since = {} for k in since.keys(): new_since[k] = '"%s"' % since[k] return new_since existing_method_names = [m.name for m in methods] for p in self.properties: if p.name.upper() == p.name: continue # no constants getter_ok = True setter_ok = True if p.permission == "read-only" or p.availability == "creation": setter_ok = False if p.permission == "write-only": getter_ok = False if "accessors" in p.api_obj and not p.api_obj["accessors"]: getter_ok = setter_ok = False if getter_ok: if dict_has_non_empty_member(p.api_obj, "type"): data_type = p.api_obj["type"] returns_array = [] if isinstance(data_type, list): for t in data_type: returns_array.append({"type": t}) else: returns_array.append({"type": data_type}) p.api_obj["returns_for_getter_template"] = returns_array if dict_has_non_empty_member(p.api_obj, "since"): p.api_obj["since_for_getter_template"] = since_for_yaml( p.api_obj["since"]) generated_method = yaml.load( AnnotatedProxy.render_getter_method(p)) annotated_method = AnnotatedMethod(generated_method, self) annotated_method.getter_for = p annotated_method.inherited_from = p.inherited_from if annotated_method.name not in existing_method_names: methods.append(annotated_method) if setter_ok: if dict_has_non_empty_member(p.api_obj, "since"): if getter_ok and dict_has_non_empty_member( p.api_obj, "since_for_getter_template"): p.api_obj["since_for_setter_template"] = p.api_obj[ "since_for_getter_template"] else: p.api_obj[ "since_for_setter_template"] = since_for_yaml( p.api_obj["since"]) generated_method = yaml.load( AnnotatedProxy.render_setter_method(p)) annotated_method = AnnotatedMethod(generated_method, self) annotated_method.setter_for = p annotated_method.inherited_from = p.inherited_from if annotated_method.name not in existing_method_names: methods.append(annotated_method)
def __init__(self, api_obj, annotated_parent): AnnotatedApi.__init__(self, api_obj) self.typestr = "event" self.parent = annotated_parent self.yaml_source_folder = self.parent.yaml_source_folder if dict_has_non_empty_member(api_obj, "exclude-platforms") and not dict_has_non_empty_member(api_obj, "platforms"): platforms = exclude_platforms(api_obj, annotated_parent); if platforms: api_obj["platforms"] = platforms
def append_inherited_attributes(self, att_list, att_list_name): if not "extends" in self.api_obj: return super_type_name = self.api_obj["extends"] class_type = { "properties": AnnotatedProperty, "methods": AnnotatedMethod, "events": AnnotatedEvent }[att_list_name] existing_names = [item.name for item in att_list] excluded_names = [] if "excludes" in self.api_obj and att_list_name in self.api_obj[ "excludes"]: excluded_names = self.api_obj["excludes"][att_list_name] class_platforms = [] if dict_has_non_empty_member(self.api_obj, "platforms"): class_platforms = self.api_obj["platforms"] while (super_type_name is not None and len(super_type_name) > 0 and super_type_name in apis): super_type = apis[super_type_name] if dict_has_non_empty_member(super_type, att_list_name): for new_item in super_type[att_list_name]: if new_item["name"] in existing_names or new_item[ "name"] in excluded_names: continue # TIDOC-920. Crosscheck class with attributes to see if the platforms match # If not, add them to the excludes list if class_platforms and dict_has_non_empty_member( new_item, "platforms"): attr_platforms = new_item["platforms"] platform_match = False for attr_platform_name in attr_platforms: if attr_platform_name in class_platforms: platform_match = True break if not platform_match: excluded_names.append(new_item["name"]) continue new_instance = class_type(new_item, self) new_instance.inherited_from = super_type_name att_list.append(new_instance) existing_names.append(new_item["name"]) # Keep going up supertypes if "extends" in super_type: super_type_name = super_type["extends"] else: super_type_name = None if excluded_names: if "excludes" not in self.api_obj: self.api_obj["excludes"] = {} self.api_obj["excludes"][att_list_name] = excluded_names
def combine_platforms_and_since(annotated_obj): obj = annotated_obj.api_obj result = [] platforms = None since = DEFAULT_SINCE if dict_has_non_empty_member(obj, "platforms"): platforms = obj["platforms"] # Method/property/event can't have more platforms than the types they belong to. if (platforms is None or isinstance(annotated_obj, AnnotatedMethod) or isinstance(annotated_obj, AnnotatedProperty) or isinstance(annotated_obj, AnnotatedEvent)): if annotated_obj.parent is not None: if dict_has_non_empty_member(annotated_obj.parent.api_obj, "platforms"): if platforms is None or len( annotated_obj.parent.api_obj["platforms"]) < len( platforms): platforms = annotated_obj.parent.api_obj["platforms"] # Last resort is the default list of platforms if platforms is None: platforms = DEFAULT_PLATFORMS if "since" in obj and len(obj["since"]) > 0: since = obj["since"] else: # If a method/event/property we can check type's "since" if (isinstance(annotated_obj, AnnotatedMethod) or isinstance(annotated_obj, AnnotatedProperty) or isinstance(annotated_obj, AnnotatedEvent)): if (annotated_obj.parent is not None and dict_has_non_empty_member( annotated_obj.parent.api_obj, "since")): since = annotated_obj.parent.api_obj["since"] since_is_dict = isinstance(since, dict) for name in platforms: one_platform = { "name": name, "pretty_name": pretty_platform_name(name) } if not since_is_dict: one_platform["since"] = since if one_platform["name"] == "mobileweb": if len(since) >= 3: if float(since[0:3]) < float(DEFAULT_MOBILEWEB_SINCE[0:3]): one_platform["since"] = DEFAULT_MOBILEWEB_SINCE else: if name in since: one_platform["since"] = since[name] else: if one_platform["name"] == "mobileweb": one_platform["since"] = DEFAULT_MOBILEWEB_SINCE else: one_platform["since"] = DEFAULT_SINCE result.append(one_platform) return result
def __init__(self, api_obj, annotated_parent): AnnotatedApi.__init__(self, api_obj) self.typestr = "event" self.parent = annotated_parent self.yaml_source_folder = self.parent.yaml_source_folder if dict_has_non_empty_member( api_obj, "exclude-platforms") and not dict_has_non_empty_member( api_obj, "platforms"): platforms = exclude_platforms(api_obj, annotated_parent) if platforms: api_obj["platforms"] = platforms
def append_setters_getters(self, methods): def since_for_yaml(since): if isinstance(since, basestring): new_since = '"%s"' % since elif isinstance(since, dict): new_since = {} for k in since.keys(): new_since[k] = '"%s"' % since[k] return new_since existing_method_names = [m.name for m in methods] for p in self.properties: if p.name.upper() == p.name: continue # no constants getter_ok = True setter_ok = True if p.permission == "read-only" or p.availability == "creation": setter_ok = False if p.permission == "write-only": getter_ok = False if "accessors" in p.api_obj and not p.api_obj["accessors"]: getter_ok = setter_ok = False if getter_ok: if dict_has_non_empty_member(p.api_obj, "type"): data_type = p.api_obj["type"] returns_array = [] if isinstance(data_type, list): for t in data_type: returns_array.append({"type": t}) else: returns_array.append({"type": data_type}) p.api_obj["returns_for_getter_template"] = returns_array if dict_has_non_empty_member(p.api_obj, "since"): p.api_obj["since_for_getter_template"] = since_for_yaml(p.api_obj["since"]) generated_method = yaml.load(AnnotatedProxy.render_getter_method(p)) annotated_method = AnnotatedMethod(generated_method, self) annotated_method.getter_for = p annotated_method.inherited_from = p.inherited_from if annotated_method.name not in existing_method_names: methods.append(annotated_method) if setter_ok: if dict_has_non_empty_member(p.api_obj, "since"): if getter_ok and dict_has_non_empty_member(p.api_obj, "since_for_getter_template"): p.api_obj["since_for_setter_template"] = p.api_obj["since_for_getter_template"] else: p.api_obj["since_for_setter_template"] = since_for_yaml(p.api_obj["since"]) generated_method = yaml.load(AnnotatedProxy.render_setter_method(p)) annotated_method = AnnotatedMethod(generated_method, self) annotated_method.setter_for = p annotated_method.inherited_from = p.inherited_from if annotated_method.name not in existing_method_names: methods.append(annotated_method)
def append_inherited_attributes(self, att_list, att_list_name): if not "extends" in self.api_obj: return super_type_name = self.api_obj["extends"] class_type = {"properties": AnnotatedProperty, "methods": AnnotatedMethod, "events": AnnotatedEvent}[att_list_name] existing_names = [item.name for item in att_list] excluded_names = [] if "excludes" in self.api_obj and att_list_name in self.api_obj["excludes"]: excluded_names = self.api_obj["excludes"][att_list_name] class_platforms = [] if dict_has_non_empty_member(self.api_obj, "platforms"): class_platforms = self.api_obj["platforms"] while (super_type_name is not None and len(super_type_name) > 0 and super_type_name in apis): super_type = apis[super_type_name] if dict_has_non_empty_member(super_type, att_list_name): for new_item in super_type[att_list_name]: if new_item["name"] in existing_names or new_item["name"] in excluded_names: continue # TIDOC-920. Crosscheck class with attributes to see if the platforms match # If not, add them to the excludes list if class_platforms and dict_has_non_empty_member(new_item, "platforms"): attr_platforms = new_item["platforms"] platform_match = False; for attr_platform_name in attr_platforms: if attr_platform_name in class_platforms: platform_match = True; break if not platform_match: excluded_names.append(new_item["name"]) continue new_instance = class_type(new_item, self) new_instance.inherited_from = super_type_name att_list.append(new_instance) existing_names.append(new_item["name"]) # Keep going up supertypes if "extends" in super_type: super_type_name = super_type["extends"] else: super_type_name = None if excluded_names: if "excludes" not in self.api_obj: self.api_obj["excludes"] = {}; self.api_obj["excludes"][att_list_name] = excluded_names
def properties(self): properties = [] if dict_has_non_empty_member(self.api_obj, "properties"): properties = [AnnotatedProperty(p, self) for p in self.api_obj["properties"]] # Append properties from Titanium.Event.yml existing_names = [p.name for p in properties] event_super_type = apis.get("Titanium.Event") if event_super_type is not None and dict_has_non_empty_member(event_super_type, "properties"): for prop in event_super_type["properties"]: if prop["name"] in existing_names: continue new_prop = AnnotatedProperty(prop, self) new_prop.inherited_from = "Titanium.Event" properties.append(new_prop) return sorted(properties, key=lambda item: item.name)
def to_jsca_function(method): log.trace("%s.%s" % (method.parent.name, method.name)) result = { "name": method.name, "deprecated": method.deprecated is not None and len(method.deprecated) > 0, "description": "" if "summary" not in method.api_obj else to_jsca_description( method.api_obj["summary"], method) } if dict_has_non_empty_member( method.api_obj, "returns") and method.api_obj["returns"] != "void": result["returnTypes"] = to_jsca_return_types(method.api_obj["returns"]) if method.parameters is not None and len(method.parameters) > 0: result["parameters"] = [ to_jsca_method_parameter(p) for p in method.parameters ] result["since"] = to_jsca_since(method.platforms) result['userAgents'] = to_jsca_userAgents(method.platforms) result['isInstanceProperty'] = True # we don't have class static methods result['isClassProperty'] = False # we don't have class static methods result['isInternal'] = False # we don't make this distinction (yet anyway) result['examples'] = to_jsca_examples(method) result['references'] = [ ] # we don't use the notion of 'references' (yet anyway) result['exceptions'] = [] # we don't specify exceptions (yet anyway) result[ 'isConstructor'] = False # we don't expose native class constructors result[ 'isMethod'] = True # all of our functions are class instance functions, ergo methods return to_ordered_dict(result, ('name', ))
def to_jsca_examples(api): if dict_has_non_empty_member(api.api_obj, "examples"): return [ to_jsca_example(example) for example in api.api_obj["examples"] ] else: return []
def append_inherited_attributes(self, att_list, att_list_name): if not "extends" in self.api_obj: return super_type_name = self.api_obj["extends"] class_type = {"properties": AnnotatedProperty, "methods": AnnotatedMethod, "events": AnnotatedEvent}[ att_list_name ] existing_names = [item.name for item in att_list] excluded_names = [] if "excludes" in self.api_obj and att_list_name in self.api_obj["excludes"]: excluded_names = self.api_obj["excludes"][att_list_name] while super_type_name is not None and len(super_type_name) > 0 and super_type_name in apis: super_type = apis[super_type_name] if dict_has_non_empty_member(super_type, att_list_name): for new_item in super_type[att_list_name]: if new_item["name"] in existing_names or new_item["name"] in excluded_names: continue new_instance = class_type(new_item, self) new_instance.inherited_from = super_type_name att_list.append(new_instance) existing_names.append(new_item["name"]) # Keep going up supertypes if "extends" in super_type: super_type_name = super_type["extends"] else: super_type_name = None
def build_method_list(self): methods = [] if dict_has_non_empty_member(self.api_obj, "methods"): methods = [AnnotatedMethod(m, self) for m in self.api_obj["methods"]] self.append_setters_getters(methods) self.append_inherited_methods(methods) return sorted(methods, key=lambda item: item.name)
def to_jsca_property(prop, for_event=False): result = { "name": prop.name, "description": "" if "summary" not in prop.api_obj else to_jsca_description(prop.api_obj["summary"], prop), "deprecated": prop.deprecated is not None and len(prop.deprecated) > 0, "type": "" if "type" not in prop.api_obj else to_jsca_type_name(prop.api_obj["type"]) } if not for_event: creatable = False; if dict_has_non_empty_member(prop.parent.api_obj, "extends"): ancestor = prop.parent.api_obj["extends"] if (ancestor == "Titanium.Proxy" or ancestor == "Titanium.UI.View"): creatable = True if ("createable" in prop.parent.api_obj): creatable = prop.parent.api_obj["createable"] result["isClassProperty"] = False if (creatable and prop.name != prop.name.upper()) else True result["isInstanceProperty"] = True if (creatable and prop.name != prop.name.upper()) else False result["since"] = to_jsca_since(prop.platforms) result["userAgents"] = to_jsca_userAgents(prop.platforms) result["isInternal"] = False result["examples"] = to_jsca_examples(prop) result["availability"] = to_jsca_availability(prop) result["permission"] = to_jsca_permission(prop) if "constants" in prop.api_obj: result["constants"] = to_jsca_constants(prop.api_obj["constants"]) return to_ordered_dict(result, ("name",))
def to_solr_property(prop, for_event=False): if dict_has_non_empty_member(prop.api_obj, "type"): content = to_solr_type_name(prop.api_obj["type"]) else: content = "" if for_event is True: return { "content": prop.name + " " + content + " " + to_solr_description(prop.api_obj["summary"]), "name": prop.name } else: return { "id": prop.parent.name + "-property-" + prop.name + "-" + solr_category, "url": prop.parent.name + "-property-" + prop.name, "name": prop.parent.name + "." + prop.name, "type": solr_category, "content": prop.parent.name + " " + prop.name + " " + content + " " + to_solr_description(prop.api_obj["summary"], prop) + " " + to_solr_remarks(prop) + " " + to_solr_examples(prop) }
def append_inherited_attributes(self, att_list, att_list_name): if not "extends" in self.api_obj: return super_type_name = self.api_obj["extends"] class_type = { "properties": AnnotatedProperty, "methods": AnnotatedMethod, "events": AnnotatedEvent }[att_list_name] existing_names = [item.name for item in att_list] excluded_names = [] if "excludes" in self.api_obj and att_list_name in self.api_obj[ "excludes"]: excluded_names = self.api_obj["excludes"][att_list_name] while (super_type_name is not None and len(super_type_name) > 0 and super_type_name in apis): super_type = apis[super_type_name] if dict_has_non_empty_member(super_type, att_list_name): for new_item in super_type[att_list_name]: if new_item["name"] in existing_names or new_item[ "name"] in excluded_names: continue new_instance = class_type(new_item, self) new_instance.inherited_from = super_type_name att_list.append(new_instance) existing_names.append(new_item["name"]) # Keep going up supertypes if "extends" in super_type: super_type_name = super_type["extends"] else: super_type_name = None
def parameters(self): parameters = [] if dict_has_non_empty_member(self.api_obj, "parameters"): parameters = [ AnnotatedMethodParameter(p, self) for p in self.api_obj["parameters"] ] return parameters
def properties(self): properties = [] if dict_has_non_empty_member(self.api_obj, "properties"): properties = [ AnnotatedProperty(p, self) for p in self.api_obj["properties"] ] self.append_inherited_properties(properties) return sorted(properties, key=lambda item: item.name)
def build_method_list(self): methods = [] if dict_has_non_empty_member(self.api_obj, "methods"): methods = [AnnotatedMethod(m, self) for m in self.api_obj["methods"]] # Not for "pseudo-types" if is_titanium_proxy(self.api_obj): self.append_setters_getters(methods) self.append_inherited_methods(methods) return sorted(methods, key=lambda item: item.name)
def build_method_list(self): methods = [] if dict_has_non_empty_member(self.api_obj, "methods"): methods = [ AnnotatedMethod(m, self) for m in self.api_obj["methods"] ] self.append_setters_getters(methods) self.append_inherited_methods(methods) return sorted(methods, key=lambda item: item.name)
def annotate(annotated_obj): annotated_obj.summary_html = "" annotated_obj.description_html = "" annotated_obj.examples_html = [] annotated_obj.inherited_from_obj = None if dict_has_non_empty_member(annotated_obj.api_obj, "summary"): summary = annotated_obj.api_obj["summary"] annotated_obj.summary_html = markdown_to_html(summary, obj=annotated_obj) if dict_has_non_empty_member(annotated_obj.api_obj, "description"): annotated_obj.description_html = markdown_to_html(annotated_obj.api_obj["description"], obj=annotated_obj) if dict_has_non_empty_member(annotated_obj.api_obj, "examples"): for example in annotated_obj.api_obj["examples"]: one_example = {"title": "", "example": ""} if dict_has_non_empty_member(example, "title"): one_example["title"] = example["title"] if dict_has_non_empty_member(example, "example"): html_example = markdown_to_html(example["example"], obj=annotated_obj) # Suspicious if the example has content (beyond the <p></p>) but not <code>. # This can happen if in the .yml the example starts off immediately with code, # because the yaml parser interprets the leading four spaces (which the programmer # put in there to tip off markdown that it's a code block) as indentation. if len(html_example) > len("<p></p>") and "<code>" not in html_example: html_example = "<pre><code>%s</code></pre>" % html_example one_example["example"] = html_example annotated_obj.examples_html.append(one_example) if annotated_obj.typestr in ("parameter", "property"): annotated_obj.type_html = "" if dict_has_non_empty_member(annotated_obj.api_obj, "type"): annotated_obj.type_html = data_type_to_html(annotated_obj.api_obj["type"]) if annotated_obj.typestr == "method": annotated_obj.return_type_html = "" if dict_has_non_empty_member(annotated_obj.api_obj, "returns"): annotated_obj.return_type_html = data_type_to_html(annotated_obj.api_obj["returns"]) annotated_obj.template_html = "method" annotated_obj.filename_html = clean_for_filename("%s.%s-%s" % (annotated_obj.parent.name, annotated_obj.name, "method")) if annotated_obj.typestr in ("proxy", "module"): annotated_obj.template_html = "proxy" if annotated_obj.typestr == "module": annotated_obj.filename_html = clean_for_filename("%s-module" % annotated_obj.name) if annotated_obj.typestr == "proxy": annotated_obj.filename_html = clean_for_filename("%s-object" % annotated_obj.name) if annotated_obj.typestr == "property": annotated_obj.filename_html = clean_for_filename("%s.%s-%s" % (annotated_obj.parent.name, annotated_obj.name, "property")) annotated_obj.template_html = "property" # Override for "property" that is an event callback property if annotated_obj.typestr == "property" and annotated_obj.parent.typestr == "event": annotated_obj.filename_html = clean_for_filename("%s.%s.%s-%s" % (annotated_obj.parent.parent.name, annotated_obj.parent.name, annotated_obj.name, "callback-property")) annotated_obj.template_html = "property" if annotated_obj.typestr == "parameter": annotated_obj.filename_html = clean_for_filename("%s.%s-param" % (annotated_obj.parent.filename_html, annotated_obj.name)) annotated_obj.template_html = "property" if annotated_obj.typestr == "event": annotated_obj.filename_html = clean_for_filename("%s.%s-%s" % (annotated_obj.parent.name, annotated_obj.name, "event")) annotated_obj.template_html = "event" if hasattr(annotated_obj, "inherited_from") and len(annotated_obj.inherited_from) > 0: if annotated_obj.inherited_from in all_annotated_apis: annotated_obj.inherited_from_obj = all_annotated_apis[annotated_obj.inherited_from] for list_type in ("methods", "properties", "events", "parameters"): annotate_member_list(annotated_obj, list_type)
def build_method_list(self): methods = [] if dict_has_non_empty_member(self.api_obj, "methods"): methods = [ AnnotatedMethod(m, self) for m in self.api_obj["methods"] ] # Not for "pseudo-types" if is_titanium_proxy(self.api_obj): self.append_setters_getters(methods) self.append_inherited_methods(methods) return sorted(methods, key=lambda item: item.name)
def combine_platforms_and_since(annotated_obj): obj = annotated_obj.api_obj result = [] platforms = None since = DEFAULT_SINCE if dict_has_non_empty_member(obj, "platforms"): platforms = obj["platforms"] # Method/property/event can't have more platforms than the types they belong to. if (platforms is None or isinstance(annotated_obj, AnnotatedMethod) or isinstance(annotated_obj, AnnotatedProperty) or isinstance(annotated_obj, AnnotatedEvent)): if annotated_obj.parent is not None: if dict_has_non_empty_member(annotated_obj.parent.api_obj, "platforms"): if platforms is None or len(annotated_obj.parent.api_obj["platforms"]) < len(platforms): platforms = annotated_obj.parent.api_obj["platforms"] # Last resort is the default list of platforms if platforms is None: platforms = DEFAULT_PLATFORMS if "since" in obj and len(obj["since"]) > 0: since = obj["since"] else: # If a method/event/property we can check type's "since" if (isinstance(annotated_obj, AnnotatedMethod) or isinstance(annotated_obj, AnnotatedProperty) or isinstance(annotated_obj, AnnotatedEvent)): if (annotated_obj.parent is not None and dict_has_non_empty_member(annotated_obj.parent.api_obj, "since")): since = annotated_obj.parent.api_obj["since"] since_is_dict = isinstance(since, dict) for name in platforms: one_platform = {"name": name, "pretty_name": pretty_platform_name(name)} if not since_is_dict: one_platform["since"] = since else: if name in since: one_platform["since"] = since[name] else: one_platform["since"] = DEFAULT_SINCE result.append(one_platform) return result
def exclude_platforms(obj, parent): platforms = None if parent is not None: all_platforms = None if dict_has_non_empty_member(parent.api_obj, "platforms"): all_platforms = parent.api_obj["platforms"] else: all_platforms = DEFAULT_PLATFORMS if all_platforms is not None: platforms = [x for x in all_platforms if x not in obj["exclude-platforms"]] if not platforms: log.warn("No platforms for %s" % (obj["name"])) return platforms
def to_solr_return_types(return_types): if return_types is None or len(return_types) == 0: return "" orig_types = return_types if not isinstance(orig_types, list): orig_types = [orig_types] return_types = "" for t in orig_types: if dict_has_non_empty_member(t, "summary"): return_types += " " + to_solr_type_name(t["type"]) + " " + to_solr_description(t["summary"]) else: return_types += " " + to_solr_type_name(t["type"]) return return_types
def to_jsca_userAgents(api): rv = [{"platform": platform["name"]} for platform in api.platforms] if dict_has_non_empty_member(api.api_obj, "osver"): osversions = api.api_obj["osver"] for key in osversions.keys(): for platform in rv: platform_name = platform["platform"] if re.match("ios", key, re.IGNORECASE) and (platform_name == "ipad" or platform_name == "iphone"): platform["os"] = "ios" platform["osversion"] = osversions[key] if re.match("android", key, re.IGNORECASE) and platform_name == "android": platform["os"] = "android" platform["osversion"] = osversions[key] return rv
def exclude_platforms(obj, parent): platforms = None if parent is not None: all_platforms = None if dict_has_non_empty_member(parent.api_obj, "platforms"): all_platforms = parent.api_obj["platforms"] else: all_platforms = DEFAULT_PLATFORMS if all_platforms is not None: platforms = [ x for x in all_platforms if x not in obj["exclude-platforms"] ] if not platforms: log.warn("No platforms for %s" % (obj["name"])) return platforms
def to_solr_function(method): log.trace("%s.%s" % (method.parent.name, method.name)) content = to_solr_description(method.api_obj["summary"], method) + " " + to_solr_remarks(method) if method.parameters is not None and len(method.parameters) > 0: for p in method.parameters: content += " " + to_solr_method_parameter(p) if dict_has_non_empty_member(method.api_obj, "returns") and method.api_obj["returns"] != "void": content += " " + to_solr_return_types(method.api_obj["returns"]) content += " " + to_solr_examples(method) result = { "id": method.parent.name + "-method-" + method.name + "-" + solr_category, "url": method.parent.name + "-method-" + method.name, "name": method.parent.name + "." + method.name, "type": solr_category, "content": method.parent.name + " " + method.name + " " + content } return result
def to_jsca_function(method): log.trace("%s.%s" % (method.parent.name, method.name)) result = { "name": method.name, "description": "" if "description" not in method.api_obj else to_jsca_description(method.api_obj["description"]) } if dict_has_non_empty_member(method.api_obj, "returns") and method.api_obj["returns"] != "void": result["returnTypes"] = to_jsca_return_types(method.api_obj["returns"]) if method.parameters is not None and len(method.parameters) > 0: result["parameters"] = [to_jsca_method_parameter(p) for p in method.parameters] result["since"] = to_jsca_since(method.platforms) result['userAgents'] = to_jsca_userAgents(method.platforms) result['isInstanceProperty'] = True # we don't have class static methods result['isClassProperty'] = False # we don't have class static methods result['isInternal'] = False # we don't make this distinction (yet anyway) result['examples'] = to_jsca_examples(method) result['references'] = [] # we don't use the notion of 'references' (yet anyway) result['exceptions'] = [] # we don't specify exceptions (yet anyway) result['isConstructor'] = False # we don't expose native class constructors result['isMethod'] = True # all of our functions are class instance functions, ergo methods return to_ordered_dict(result, ('name',))
def to_jsca_property(prop, for_event=False): result = { "name": prop.name, "description": "" if "summary" not in prop.api_obj else to_jsca_description( prop.api_obj["summary"], prop), "deprecated": prop.deprecated is not None and len(prop.deprecated) > 0, "type": "" if "type" not in prop.api_obj else to_jsca_type_name( prop.api_obj["type"]) } if not for_event: creatable = False if dict_has_non_empty_member(prop.parent.api_obj, "extends"): ancestor = prop.parent.api_obj["extends"] if (ancestor == "Titanium.Proxy" or ancestor == "Titanium.UI.View"): creatable = True if ("createable" in prop.parent.api_obj): creatable = prop.parent.api_obj["createable"] result["isClassProperty"] = False if ( creatable and prop.name != prop.name.upper()) else True result["isInstanceProperty"] = True if ( creatable and prop.name != prop.name.upper()) else False result["since"] = to_jsca_since(prop.platforms) result["userAgents"] = to_jsca_userAgents(prop.platforms) result["isInternal"] = False result["examples"] = to_jsca_examples(prop) result["availability"] = to_jsca_availability(prop) result["permission"] = to_jsca_permission(prop) if "constants" in prop.api_obj: result["constants"] = to_jsca_constants(prop.api_obj["constants"]) return to_ordered_dict(result, ("name", ))
def to_jsca_availability(prop): if dict_has_non_empty_member(prop.api_obj, "availability"): return prop.api_obj["availability"] else: return "always"
def to_solr_remarks(api): if dict_has_non_empty_member(api.api_obj, "description"): return api.api_obj["description"] else: return ""
def to_solr_examples(api): rv = "" if dict_has_non_empty_member(api.api_obj, "examples"): for example in api.api_obj["examples"]: rv += " " + example["title"] + " " + example["example"] return rv
def combine_platforms_and_since(annotated_obj): parent = annotated_obj.parent obj = annotated_obj.api_obj result = [] platforms = None since = DEFAULT_SINCE if dict_has_non_empty_member(obj, "platforms"): platforms = obj["platforms"] # Method/property/event can't have more platforms than the types they belong to. if (platforms is None or isinstance(annotated_obj, AnnotatedMethod) or isinstance(annotated_obj, AnnotatedProperty) or isinstance(annotated_obj, AnnotatedEvent)): if parent is not None: if dict_has_non_empty_member(parent.api_obj, "platforms"): if platforms is None or len( parent.api_obj["platforms"]) < len(platforms): platforms = parent.api_obj["platforms"] # Last resort is the default list of platforms if platforms is None: platforms = DEFAULT_PLATFORMS if "since" in obj and len(obj["since"]) > 0: since = obj["since"] else: # If a method/event/property we can check type's "since" if (isinstance(annotated_obj, AnnotatedMethod) or isinstance(annotated_obj, AnnotatedProperty) or isinstance(annotated_obj, AnnotatedEvent)): if (parent is not None and dict_has_non_empty_member(parent.api_obj, "since")): since = parent.api_obj["since"] since_is_dict = isinstance(since, dict) for name in platforms: one_platform = { "name": name, "pretty_name": pretty_platform_name(name) } min_since = first_version_for_platform(one_platform["name"]) if not since_is_dict: one_platform["since"] = since if min_since is not None: if StrictVersion(since) < StrictVersion(min_since): one_platform["since"] = min_since else: if name in since: one_platform["since"] = since[name] else: if min_since is not None: one_platform["since"] = min_since else: one_platform["since"] = DEFAULT_SINCE result.append(one_platform) # Be sure no "since" is _before_ a parent object since. if parent and parent.platforms: for entry in result: platform_name = entry["name"] version_parts = entry["since"].split(".") for parent_entry in parent.platforms: if parent_entry["name"] == platform_name: parent_version_parts = parent_entry["since"].split(".") if parent_version_parts > version_parts: entry["since"] = parent_entry["since"] break return result
def events(self): events = [] if dict_has_non_empty_member(self.api_obj, "events"): events = [AnnotatedEvent(e, self) for e in self.api_obj["events"]] self.append_inherited_events(events) return sorted(events, key=lambda item: item.name)
def to_jsca_examples(api): if dict_has_non_empty_member(api.api_obj, "examples"): return [to_jsca_example(example) for example in api.api_obj["examples"]] else: return []
def to_jsca_inherits(api): if dict_has_non_empty_member(api.api_obj, "extends"): return api.api_obj["extends"] else: return 'Object'
def properties(self): properties = [] if dict_has_non_empty_member(self.api_obj, "properties"): properties = [AnnotatedProperty(p, self) for p in self.api_obj["properties"]] self.append_inherited_properties(properties) return sorted(properties, key=lambda item: item.name)
def to_jsca_remarks(api): if dict_has_non_empty_member(api.api_obj, "notes"): return [markdown_to_html(api.api_obj["notes"])] else: return []
def to_jsca_permission(prop): if dict_has_non_empty_member(prop.api_obj, "permission"): return prop.api_obj["permission"] else: return "read-write"
def to_jsca_remarks(api): if dict_has_non_empty_member(api.api_obj, "description"): return [markdown_to_html(api.api_obj["description"])] else: return []
def parameters(self): parameters = [] if dict_has_non_empty_member(self.api_obj, "parameters"): parameters = [AnnotatedMethodParameter(p, self) for p in self.api_obj["parameters"]] return parameters
def annotate(annotated_obj): annotated_obj.summary_html = "" annotated_obj.description_html = "" annotated_obj.examples_html = [] annotated_obj.inherited_from_obj = None if hasattr(annotated_obj, "inherited_from") and len(annotated_obj.inherited_from) > 0: if annotated_obj.inherited_from in all_annotated_apis: annotated_obj.inherited_from_obj = all_annotated_apis[ annotated_obj.inherited_from] is_inherited = (annotated_obj.inherited_from_obj is not None) if annotated_obj.deprecated: if "notes" in annotated_obj.deprecated: annotated_obj.deprecated["notes_html"] = markdown_to_html( annotated_obj.deprecated["notes"], obj=annotated_obj, suppress_link_warnings=is_inherited, strip_outer_paragraph=True) if dict_has_non_empty_member(annotated_obj.api_obj, "summary"): summary = annotated_obj.api_obj["summary"] annotated_obj.summary_html = markdown_to_html( summary, obj=annotated_obj, suppress_link_warnings=is_inherited) if dict_has_non_empty_member(annotated_obj.api_obj, "description"): annotated_obj.description_html = markdown_to_html( annotated_obj.api_obj["description"], obj=annotated_obj, suppress_link_warnings=is_inherited) if dict_has_non_empty_member(annotated_obj.api_obj, "examples"): for example in annotated_obj.api_obj["examples"]: one_example = {"title": "", "example": ""} if dict_has_non_empty_member(example, "title"): one_example["title"] = example["title"] if dict_has_non_empty_member(example, "example"): html_example = markdown_to_html( example["example"], obj=annotated_obj, suppress_link_warnings=is_inherited) # Suspicious if the example has content (beyond the <p></p>) but not <code>. # This can happen if in the .yml the example starts off immediately with code, # because the yaml parser interprets the leading four spaces (which the programmer # put in there to tip off markdown that it's a code block) as indentation. if len(html_example) > len( "<p></p>") and "<code>" not in html_example: html_example = "<pre><code>%s</code></pre>" % html_example one_example["example"] = html_example annotated_obj.examples_html.append(one_example) if annotated_obj.typestr in ("parameter", "property"): annotated_obj.type_html = "" if dict_has_non_empty_member(annotated_obj.api_obj, "type"): annotated_obj.type_html = data_type_to_html( annotated_obj.api_obj["type"]) if annotated_obj.typestr == "method": annotated_obj.return_type_html = "" if dict_has_non_empty_member(annotated_obj.api_obj, "returns"): annotated_obj.return_type_html = data_type_to_html( annotated_obj.api_obj["returns"]) annotated_obj.template_html = "method" annotated_obj.filename_html = clean_for_filename( "%s.%s-%s" % (annotated_obj.parent.name, annotated_obj.name, "method")) if annotated_obj.typestr in ("proxy", "module"): annotated_obj.template_html = "proxy" if annotated_obj.typestr == "module": annotated_obj.filename_html = clean_for_filename("%s-module" % annotated_obj.name) if annotated_obj.typestr == "proxy": annotated_obj.filename_html = clean_for_filename("%s-object" % annotated_obj.name) if annotated_obj.typestr == "property": annotated_obj.filename_html = clean_for_filename( "%s.%s-%s" % (annotated_obj.parent.name, annotated_obj.name, "property")) annotated_obj.template_html = "property" if annotated_obj.default is not None: annotated_obj.default_html = markdown_to_html( str(annotated_obj.default), suppress_link_warnings=is_inherited) # Override for "property" that is an event callback property if annotated_obj.typestr == "property" and annotated_obj.parent.typestr == "event": annotated_obj.filename_html = clean_for_filename( "%s.%s.%s-%s" % (annotated_obj.parent.parent.name, annotated_obj.parent.name, annotated_obj.name, "callback-property")) annotated_obj.template_html = "property" if annotated_obj.typestr == "parameter": annotated_obj.filename_html = clean_for_filename( "%s.%s-param" % (annotated_obj.parent.filename_html, annotated_obj.name)) annotated_obj.template_html = "property" if annotated_obj.default is not None: annotated_obj.default_html = markdown_to_html( str(annotated_obj.default), suppress_link_warnings=is_inherited) if annotated_obj.typestr == "event": annotated_obj.filename_html = clean_for_filename( "%s.%s-%s" % (annotated_obj.parent.name, annotated_obj.name, "event")) annotated_obj.template_html = "event" for list_type in ("methods", "properties", "events", "parameters"): annotate_member_list(annotated_obj, list_type)