コード例 #1
0
ファイル: JavaScript.py プロジェクト: Val9/jasy
def storeLoader(classes, fileName, bootCode="", urlPrefix=""):
    """
    Generates a source loader which is basically a file which loads the original JavaScript files.
    This is super useful during development of a project as it supports pretty fast workflows
    where most often a simple reload in the browser is enough to get the newest sources.
    
    - classes: List of sorted classes to compress
    - fileName: Filename to write result to
    - bootCode: Code to execute once all classes have been loaded
    - urlPrefix: Prepends the given URL prefix to all class URLs to load
    """
    
    info("Generating loader for %s classes...", len(classes))
    indent()
    
    main = session.getMain()
    files = []
    for classObj in classes:
        path = classObj.getPath()

        # Support for multi path classes 
        # (typically in projects with custom layout/structure e.g. 3rd party)
        if type(path) is list:
            for singleFileName in path:
                files.append(main.toRelativeUrl(singleFileName, urlPrefix))
        
        else:
            files.append(main.toRelativeUrl(path, urlPrefix))
    
    loader = '"%s"' % '","'.join(files)
    result = []
    outdent()
    
    assetData = assetManager.export(classes)
    if assetData:
        assetCode = 'core.io.Asset.addData(%s);' % assetData
        result.append(packCode(assetCode))

    wrappedBootCode = "function(){%s}" % bootCode if bootCode else "null"
    loaderCode = 'core.io.Queue.load([%s], %s, null, true);' % (loader, wrappedBootCode)
    result.append(packCode(loaderCode))

    writeFile(fileName, "".join(result))
コード例 #2
0
ファイル: JavaScript.py プロジェクト: Val9/jasy
def storeCompressed(classes, fileName, bootCode=""):
    """
    Combines the compressed result of the stored class list
    
    - classes: List of sorted classes to compress
    - fileName: Filename to write result to
    - bootCode: Code to execute once all the classes are loaded
    """
    
    info("Merging compressed output of %s classes...", len(classes))
    indent()
    result = []
    
    try:
        # FIXME
        translation = None 
        
        for classObj in classes:
            #debug("Adding class %s", classObj.id)
            #indent()
            result.append(classObj.getCompressed(getPermutation(), translation, jsOptimization, jsFormatting))
            #outdent()
            
    except ClassError as error:
        raise JasyError("Error during class compression! %s" % error)

    outdent()

    assetData = assetManager.export(classes)
    if assetData:
        assetCode = 'core.io.Asset.addData(%s);' % assetData
        result.append(packCode(assetCode))

    if bootCode:
        wrappedBootCode = "(function(){%s})();" % bootCode
        result.append(packCode(wrappedBootCode))

    writeFile(fileName, "".join(result))