コード例 #1
0
ファイル: jsca2js.py プロジェクト: jvandijk/jsca2js
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()
コード例 #2
0
ファイル: jsca2js.py プロジェクト: Tsuguya/jsca2js
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()
コード例 #3
0
ファイル: jsca2js.py プロジェクト: jvandijk/jsca2js
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()
コード例 #4
0
ファイル: jsca2js.py プロジェクト: Tsuguya/jsca2js
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()
コード例 #5
0
ファイル: jsca2js.py プロジェクト: Tsuguya/jsca2js
def generateMethodJSDoc(method):
    formatter = Formatter(METHOD_INDENTATION)
    formatter.addLine('/**')

    prefix = ' * '

    if KEYS['value'] in method:
        formatter.addLine(prefix, method[KEYS['value']])

    if 'platforms' in method and 'since' in method:
        formatter.addLine(prefix, 'platforms: ', ', '.join(getPlatforms(method['platforms'])))

    for param in method['parameters']:
        formatter.addLine(prefix, '@param {', formatType(param['type']), '} ',
            convertIds(param['name']), ' ', (param[KEYS['description']] if KEYS['description'] in param else param['description'] ) or '')

    if 'returntype' in method and method['returntype'] == 'void':
        formatter.addLine(prefix, '@returns ', method['returntype'])
    elif 'returns' in method:
        returns = method['returns']
        if type(returns) is list:
            for ret in returns:
                if ret['type'] != 'void':
                    formatter.addLine(prefix, '@returns ', formatReturn(ret))
        elif returns['type'] != 'void':
            formatter.addLine(prefix, '@returns ', formatReturn(returns))

    sinceVer = formatSince(method)
    if sinceVer:
        formatter.addLine(prefix, '@since ', sinceVer)

    formatter.addLine(' */')

    return convertLinks(formatter.getResult())
コード例 #6
0
ファイル: jsca2js.py プロジェクト: pchlupacek/jsca2js
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()
コード例 #7
0
ファイル: jsca2js.py プロジェクト: Tsuguya/jsca2js
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()
コード例 #8
0
ファイル: jsca2js.py プロジェクト: Tsuguya/jsca2js
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()
コード例 #9
0
ファイル: jsca2js.py プロジェクト: Tsuguya/jsca2js
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()
コード例 #10
0
ファイル: jsca2js.py プロジェクト: jvandijk/jsca2js
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()
コード例 #11
0
ファイル: jsca2js.py プロジェクト: jvandijk/jsca2js
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()
コード例 #12
0
ファイル: jsca2js.py プロジェクト: pchlupacek/jsca2js
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()
コード例 #13
0
ファイル: jsca2js.py プロジェクト: jvandijk/jsca2js
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()
コード例 #14
0
ファイル: jsca2js.py プロジェクト: pchlupacek/jsca2js
def generatePropertyJSDoc(property):
    formatter = Formatter(METHOD_INDENTATION)
    formatter.addLine('/**')

    prefix = ' * '

    formatter.addLine(prefix, property['value'])
    formatter.addLine(prefix, 'platforms:', ', '.join(property['platforms']))

    formatter.addLine(prefix, '@type ', property['type'])
    formatter.addLine(prefix, '@since ', property['since'])
    formatter.addLine(' */')

    return convertLinks(formatter.getResult())
コード例 #15
0
ファイル: jsca2js.py プロジェクト: Tsuguya/jsca2js
def generatePropertyJSDoc(property):
    formatter = Formatter(METHOD_INDENTATION)
    formatter.addLine('/**')

    prefix = ' * '

    if KEYS['value'] in property:
        formatter.addLine(prefix, property[KEYS['value']])
    if 'since' in property:
        formatter.addLine(prefix, 'platforms: ', ', '.join(getPlatforms(property['platforms'])))
    formatter.addLine(prefix, '@type ', formatType(property['type']))

    sinceVer = formatSince(property)
    if sinceVer:
        formatter.addLine(prefix, '@since ', sinceVer)

    formatter.addLine(' */')

    return convertLinks(formatter.getResult())
コード例 #16
0
ファイル: jsca2js.py プロジェクト: pchlupacek/jsca2js
def generateMethodJSDoc(method):
    formatter = Formatter(METHOD_INDENTATION)
    formatter.addLine('/**')

    prefix = ' * '

    formatter.addLine(prefix, method['value'])
    formatter.addLine(prefix, 'platforms:', ', '.join(method['platforms']))

    for param in method['parameters']:
        formatter.addLine(prefix, '@param {', param['type'], '} ', convertIds(param['name']), ' ', param['description'])

    if method['returntype'] != 'void':
        formatter.addLine(prefix, '@returns {', method['returntype'] + '}')

    formatter.addLine(' * ', '@since ', method['since'])
    formatter.addLine(' */')

    return convertLinks(formatter.getResult())
コード例 #17
0
ファイル: jsca2js.py プロジェクト: pchlupacek/jsca2js
def generateNamespaceJSDoc(namespace):
    formatter = Formatter()
    formatter.addLine('/**')

    prefix = ' * '
    if namespace['notes']:
        formatter.addLine(prefix, 'Notes: ', namespace['notes'])

    formatter.addLine(prefix, 'platforms:', ', '.join(namespace['platforms']))
    formatter.addLine(prefix, '@namespace ', namespace['description'])
    formatter.addLine(prefix, '@since ', namespace['since'])

    for example in namespace['examples']:
        formatter.addLine(prefix)
        formatter.addLine(prefix, '@example ', example['description'])
        formatter.addLine(prefix, example['code'])

    formatter.addLine(' */')
    return convertLinks(formatter.getResult())
コード例 #18
0
ファイル: jsca2js.py プロジェクト: jvandijk/jsca2js
def generatePropertyJSDoc(property):
    formatter = Formatter(METHOD_INDENTATION)
    formatter.addLine('/**')

    prefix = ' * '

    if KEYS['value'] in property:
        formatter.addLine(prefix, property[KEYS['value']])
    if 'since' in property:
        formatter.addLine(prefix, 'platforms: ',
                          ', '.join(getPlatforms(property['platforms'])))
    formatter.addLine(prefix, '@type ', formatType(property['type']))

    sinceVer = formatSince(property)
    if sinceVer:
        formatter.addLine(prefix, '@since ', sinceVer)

    formatter.addLine(' */')

    return convertLinks(formatter.getResult())
コード例 #19
0
ファイル: jsca2js.py プロジェクト: farwayer/jsca2js
def generateMethodJSDoc(method):
    formatter = Formatter(METHOD_INDENTATION)
    formatter.addLine('/**')

    prefix = ' * '

    if KEYS['value'] in method:
        formatter.addLine(prefix, method[KEYS['value']])

    if 'platforms' in method and 'since' in method:
        formatter.addLine(prefix, 'platforms: ',
                          ', '.join(getPlatforms(method['platforms'])))

    for param in method['parameters']:
        name = convertIds(param['name'])
        if 'optional' in param and param['optional']:
            name = "[" + name + "]"
        formatter.addLine(prefix, '@param {', formatType(param['type']), '} ',
                          name, ' ',
                          (param[KEYS['description']] if KEYS['description']
                           in param else param['description']) or '')

    if 'returntype' in method and method['returntype'] == 'void':
        formatter.addLine(prefix, '@returns ', method['returntype'])
    elif 'returns' in method:
        returns = method['returns']
        if type(returns) is list:
            for ret in returns:
                if ret['type'] != 'void':
                    formatter.addLine(prefix, '@returns ', formatReturn(ret))
        elif returns['type'] != 'void':
            formatter.addLine(prefix, '@returns ', formatReturn(returns))

    sinceVer = formatSince(method)
    if sinceVer:
        formatter.addLine(prefix, '@since ', sinceVer)

    formatter.addLine(' */')

    return convertLinks(formatter.getResult())
コード例 #20
0
ファイル: jsca2js.py プロジェクト: jvandijk/jsca2js
def generateNamespaceJSDoc(namespace):
    formatter = Formatter()
    formatter.addLine('/**')

    prefix = ' * '
    if 'notes' in namespace and namespace['notes']:
        formatter.addLine(prefix, 'Notes: ', namespace['notes'])

    if 'platforms' in namespace:
        formatter.addLine(prefix, 'platforms: ',
                          ', '.join(getPlatforms(namespace['platforms'])))
    if namespace['description']:
        formatter.addLine(prefix, '@namespace ', namespace['description'])
    if 'since' in namespace:
        formatter.addLine(prefix, '@since ', namespace['since'])

    if 'examples' in namespace:
        for example in namespace['examples']:
            formatter.addLine(prefix)
            formatter.addLine(prefix, '@example ', example['description'])
            formatter.addLine(prefix, example['code'])

    formatter.addLine(' */')
    return convertLinks(formatter.getResult())