Пример #1
0
def formatProperties(namespace):
    formatter = Formatter(METHOD_INDENTATION)
    for property in namespace['properties']:
        formatter.add(generatePropertyJSDoc(property))
        formatter.addLine(convertKey(property['name']), ':null,')
        formatter.newLine()
    return formatter.getResult()
Пример #2
0
def formatMethods(namespace):
    formatter = Formatter(METHOD_INDENTATION)
    for method in namespace['methods']:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine('this.', convertIds(method['name']), ' = function(', formatParams(method['parameters']), ") {")
        formatter.addLine('};')
        formatter.newLine()
    return formatter.getResult()
Пример #3
0
def extendGlobal(name, namespace):
    formatter = Formatter(METHOD_INDENTATION)

    for method in namespace['methods']:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine(name, '.prototype.', convertKey(method['name']), ' = function(', formatParams(method['parameters']), ") {")
        formatter.addLine('};')
        formatter.newLine()
    return formatter.getResult()
Пример #4
0
def formatGlobal(namespace):
    formatter = Formatter(METHOD_INDENTATION)

    for method in namespace['methods']:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine('function ', convertKey(method['name']), '(', formatParams(method['parameters']), ") {")
        formatter.addLine('}')
        formatter.newLine()
    return formatter.getResult()
Пример #5
0
def formatMethods(namespace):
    formatter = Formatter(METHOD_INDENTATION)
    key = 'methods' if 'methods' in namespace else 'method'
    for method in namespace[key]:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine(convertKey(method['name']), ':function(', formatParams(method['parameters']), ") {")
        formatter.addLine('},')
        formatter.newLine()
    return formatter.getResult()
Пример #6
0
def extendGlobal(name, namespace):
    formatter = Formatter(METHOD_INDENTATION)

    for method in namespace['methods']:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine(name, '.prototype.',
                          convertKey(method['name']), ' = function(',
                          formatParams(method['parameters']), ") {")
        formatter.addLine('};')
        formatter.newLine()
    return formatter.getResult()
Пример #7
0
def formatNamespace(namespace):
    namespaceName = convertIds(namespace[0])
    namespaceContent = namespace[1]

    formatter = Formatter()
    formatter.add(generateNamespaceJSDoc(namespaceContent))
    formatter.addLine(namespaceName, ' = (function() {').newLine()
    formatter.addLine(formatProperties(namespaceContent))
    formatter.addLine(formatMethods(namespaceContent))
    formatter.addLine('}());').newLine()
    return formatter.getResult()
Пример #8
0
def formatMethods(namespace):
    formatter = Formatter(METHOD_INDENTATION)

    key = 'functions' if 'functions' in namespace else 'function'

    for method in namespace[key]:
        formatter.add(generateMethodJSDoc(method))
        formatter.addLine(convertKey(method['name']), ':function(',
                          formatParams(method['parameters']), ") {")
        formatter.addLine('},')
        formatter.newLine()
    return formatter.getResult()
Пример #9
0
def formatNamespace(namespace):
    namespaceName = convertIds(namespace[0])
    namespaceContent = namespace[1]

    formatter = Formatter()
    formatter.add(generateNamespaceJSDoc(namespaceContent))

    if namespaceName.find('.') < 0:
        if namespaceName == 'Global': # ie. Global.alert -> alert()
            formatter.add(formatGlobal(namespaceContent))
            return formatter.getResult();
            
        formatter.add('var ')
        if namespaceName == 'Titanium':
            namespaceName = 'Ti'

    elif namespaceName.startswith('Global.'): # ie. Global.String prototype extension
        formatter.add(extendGlobal(namespaceName[7:], namespaceContent))
        return formatter.getResult();

    if 'subtype' in namespaceContent and namespaceContent['subtype'] == 'proxy':
        formatter.addLine(namespaceName, ' = function() {').addLine('};')
        formatter.addLine(namespaceName, '.prototype = {').newLine()
    else:
        formatter.addLine(namespaceName, ' = {').newLine()
    formatter.addLine(formatProperties(namespaceContent))
    formatter.addLine(formatMethods(namespaceContent))
    formatter.addLine('};').newLine()

    return formatter.getResult()
Пример #10
0
def formatNamespace(namespace):
    namespaceName = convertIds(namespace[0])
    namespaceContent = namespace[1]

    formatter = Formatter()
    formatter.add(generateNamespaceJSDoc(namespaceContent))

    if namespaceName.find('.') < 0:
        if namespaceName == 'Global':  # ie. Global.alert -> alert()
            formatter.add(formatGlobal(namespaceContent))
            return formatter.getResult()

        formatter.add('var ')
        if namespaceName == 'Titanium':
            namespaceName = 'Ti'

    elif namespaceName.startswith(
            'Global.'):  # ie. Global.String prototype extension
        formatter.add(extendGlobal(namespaceName[7:], namespaceContent))
        return formatter.getResult()

    if 'subtype' in namespaceContent and namespaceContent['subtype'] == 'proxy':
        formatter.addLine(namespaceName, ' = function() {').addLine('};')
        formatter.addLine(namespaceName, '.prototype = {').newLine()
    else:
        formatter.addLine(namespaceName, ' = {').newLine()
    formatter.addLine(formatProperties(namespaceContent))
    formatter.addLine(formatMethods(namespaceContent))
    formatter.addLine('};').newLine()

    return formatter.getResult()