Changeset 12009

Show
Ignore:
Timestamp:
01/11/08 19:15:42 (6 months ago)
Author:
jburke
Message:

Refs #4573: putting in scope changes. Say hello to _scopeName for string IDs. \!strict

Location:
util/trunk/buildscripts
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • util/trunk/buildscripts/build.js

    r11907 r12009  
    131131                nlsIgnoreString += (nlsIgnoreString ? "|" : "") + buildUtil.regExpEscape(nameSegment); 
    132132                 
     133                 
     134                //Burn in scope names for dojo.js/xd.js if requested. 
     135                if(kwArgs.scopeMap && (layerName.match(/dojo\.xd\.js$/) || layerName.match(/dojo\.js$/))){ 
     136                        fileContents = buildUtil.setScopeNames(fileContents, kwArgs.scopeMap); 
     137                } 
     138 
    133139                //Burn in xd path for dojo if requested, and only do this in dojo.xd.js. 
    134140                if(layerName.match(/dojo\.xd\.js/) && kwArgs.xdDojoPath){ 
     
    143149                var uncompressedContents = layerLegalText + fileContents; 
    144150                if(layerName.match(/\.xd\.js$/) && !layerName.match(/dojo(\.xd)?\.js/)){ 
    145                         uncompressedContents = buildUtilXd.makeXdContents(uncompressedContents, prefixes); 
     151                        uncompressedContents = buildUtilXd.makeXdContents(uncompressedContents, prefixes, kwArgs); 
    146152                } 
    147153                fileUtil.saveUtf8File(uncompressedFileName, uncompressedContents); 
     
    246252 
    247253        if(kwArgs.loader == "xdomain"){ 
    248                 buildUtilXd.xdgen(prefixName, prefixPath, prefixes, layerIgnoreRegExp); 
     254                buildUtilXd.xdgen(prefixName, prefixPath, prefixes, layerIgnoreRegExp, kwArgs); 
    249255        } 
    250256 
  • util/trunk/buildscripts/jslib/buildUtil.js

    r11919 r12009  
    9292                        + "will be generated in each module prefix's release directory which maps the " 
    9393                        + "short symbol names to more descriptive names." 
    94         } 
     94        }, 
     95        "scopeMap": { 
     96                defaultValue: "", 
     97                helpText: "Change the default dojo, dijit and dojox scope names to soemthing else. Useful if you want to " 
     98                        + "use Dojo as part of a JS library, but want to make a self-contained library with no external dojo/dijit/dojox " 
     99                        + "references. Format is a string that contains no spaces, and is similar to the djConfig.scopeMap value (note that the " 
     100                        + "backslashes below are required to avoid shell escaping):\n" 
     101                        + "scopeMap: [[\\\"dojo\\\",\\\"mydojo\\\"],[\\\"dijit\\\",\\\"mydijit\\\"][\\\"dojox\\\",\\\"mydojox\\\"]]" 
     102        }, 
     103        "xdScopeArgs": { 
     104                defaultValue: "", 
     105                helpText: "If the loader=xdomain build option is used, then the value of this option " 
     106                        + "will be used as the arguments to the function that defines the modules in the .xd.js files. " 
     107                        + "This allows for more than one version of the same module to be in a page. See documentation on " 
     108                        + "djConfig.scopeMap for more information." 
     109        }, 
     110        "xdDojoScopeName": { 
     111                defaultValue: "dojo", 
     112                helpText: "If the loader=xdomain build option is used, then the value of this option " 
     113                        + "will be used instead of 'dojo' for the 'dojo._xdResourceLoaded()' calls that are done in the .xd.js files. " 
     114                        + "This allows for dojo to be under a different scope name but still allow xdomain loading with that scope name." 
     115        }     
    95116}; 
    96117 
     
    183204                dojo._loadedUrls.push(buildscriptsPath + "../../dojo/_base/_loader/hostenv_"+hostenvType+".js"); 
    184205        } 
    185  
    186         dojo._loadedUrls.push(buildscriptsPath + "jslib/dojoGuardEnd.jsfrag"); 
    187206} 
    188207 
     
    372391                        } 
    373392                 
    374                  
     393                         
     394                        //Add the loader files if this is a loader layer. 
    375395                        if(layerName == "dojo.js"){ 
    376396                                buildUtil.includeLoaderFiles("default", hostenvType, buildscriptsPath); 
     
    398418                        var depList = buildUtil.determineUriList(layer.dependencies, layerUris, dependencies["filters"]);  
    399419                         
     420                         
     421                        //Add the final closure guard to the list. 
     422                        if(layerName == "dojo.js" || layerName == "dojo.xd.js"){ 
     423                                depList.push(buildscriptsPath + "jslib/dojoGuardEnd.jsfrag"); 
     424                        } 
     425 
    400426                        //Store the layer URIs that are in this file as well as all files it depends on. 
    401427                        namedLayerUris[layer.name] = layerUris.concat(depList); 
     
    12121238} 
    12131239 
     1240buildUtil.setScopeNames = function(/*String*/fileContents, /*String*/scopeMap){ 
     1241        //summary: burns in the scope names into the file contents. 
     1242        //scopeMap should be a [["name","value"],["name","value"]] string. Notice the lack of spaces. 
     1243        //Single quotes can be used instead of double quotes. 
     1244        return fileContents.replace(/var\s+sMap\s+=\s+null/, "var sMap = " + scopeMap); 
     1245} 
     1246 
    12141247buildUtil.symctr = 0; 
    12151248buildUtil.symtbl = null; 
  • util/trunk/buildscripts/jslib/buildUtilXd.js

    r11782 r12009  
    4444        /*String*/prefixPath, 
    4545        /*Array*/prefixes, 
    46         /*RegExp*/optimizeIgnoreRegExp 
     46        /*RegExp*/optimizeIgnoreRegExp, 
     47        /*Object*/kwArgs 
    4748){ 
    4849        //summary: generates the .xd.js files for a build. 
     
    6667                        //need to have special xd contents. 
    6768                        if(jsFileName.match(/\/nls\//) && fileContents.indexOf("dojo.provide(") == -1){ 
    68                                 var xdContents = buildUtilXd.makeXdBundleContents(prefixName, prefixPath, jsFileName, fileContents, prefixes);                   
     69                                var xdContents = buildUtilXd.makeXdBundleContents(prefixName, prefixPath, jsFileName, fileContents, prefixes, kwArgs);                   
    6970                        }else{ 
    70                                 xdContents = buildUtilXd.makeXdContents(fileContents, prefixes); 
     71                                xdContents = buildUtilXd.makeXdContents(fileContents, prefixes, kwArgs); 
    7172                        } 
    7273                        fileUtil.saveUtf8File(xdFileName, xdContents); 
     
    7778//START makeXdContents function 
    7879//Function that generates the XD version of the module file's contents 
    79 buildUtilXd.makeXdContents = function(fileContents, prefixes){ 
     80buildUtilXd.makeXdContents = function(fileContents, prefixes, kwArgs){ 
    8081        var dependencies = []; 
    8182 
     
    115116        //Build the xd file contents. 
    116117        var xdContentsBuffer = []; 
    117         xdContentsBuffer.push("dojo._xdResourceLoaded({\n"); 
     118        xdContentsBuffer.push((kwArgs.xdDojoScopeName || "dojo") + "._xdResourceLoaded({\n"); 
    118119         
    119120        //Add in dependencies section. 
     
    130131         
    131132        //Add the contents of the file inside a function. 
    132         //Pass in dojo as an argument to the function to help with 
    133         //allowing multiple versions of dojo in a page. 
    134         xdContentsBuffer.push("\ndefineResource: function(dojo){"); 
     133        //Pass in module names to allow for multiple versions of modules in a page. 
     134        var scopeArgs = kwArgs.xdScopeArgs || "dojo, dijit, dojox"; 
     135        xdContentsBuffer.push("\ndefineResource: function(" + scopeArgs + "){"); 
    135136        //Remove requireLocalization calls, since that will mess things up. 
    136137        //String() part is needed since fileContents is a Java object. 
     
    144145 
    145146//START makeXdBundleContents function 
    146 buildUtilXd.makeXdBundleContents = function(prefix, prefixPath, srcFileName, fileContents, prefixes){ 
     147buildUtilXd.makeXdBundleContents = function(prefix, prefixPath, srcFileName, fileContents, prefixes, kwArgs){ 
    147148        //logger.info("Flattening bundle: " + srcFileName); 
    148149 
     
    169170 
    170171        //Now make a proper xd.js file out of the content. 
    171         return buildUtilXd.makeXdContents(fileContents, prefixes); 
     172        return buildUtilXd.makeXdContents(fileContents, prefixes, kwArgs); 
    172173} 
    173174//END makeXdBundleContents function 
  • util/trunk/buildscripts/jslib/dojoGuardEnd.jsfrag

    r7898 r12009  
    1 }; 
     1 
     2})(); 
  • util/trunk/buildscripts/jslib/dojoGuardStart.jsfrag

    r7898 r12009  
    1 if(typeof dojo == "undefined"){ 
     1;(function(){ 
     2 
     3        /* 
     4        dojo, dijit, and dojox must always be the first three, and in that order. 
     5        djConfig.scopeMap = [ 
     6                ["dojo", "fojo"], 
     7                ["dijit", "fijit"], 
     8                ["dojox", "fojox"] 
     9         
     10        ] 
     11        */ 
     12 
     13        //The null below can be relaced by a build-time value. 
     14        var sMap = null; 
     15         
     16        //See if new scopes need to be defined. 
     17        if((sMap || (typeof djConfig != "undefined" && djConfig.scopeMap)) && (typeof window != "undefined")){ 
     18                var scopeDef = "", scopePrefix = "", scopeSuffix = "", scopeMap = {}, scopeMapRev = {}; 
     19                sMap = sMap || djConfig.scopeMap; 
     20                for(var i = 0; i < sMap.length; i++){ 
     21                        //Make local variables, then global variables that use the locals. 
     22                        var newScope = sMap[i]; 
     23                        scopeDef += "var " + newScope[0] + " = {}; " + newScope[1] + " = " + newScope[0] + ";" + newScope[1] + "._scopeName = '" + newScope[1] + "';"; 
     24                        scopePrefix += (i == 0 ? "" : ",") + newScope[0]; 
     25                        scopeSuffix += (i == 0 ? "" : ",") + newScope[1]; 
     26                        scopeMap[newScope[0]] = newScope[1]; 
     27                        scopeMapRev[newScope[1]] = newScope[0]; 
     28                } 
     29 
     30                eval(scopeDef + "dojo._scopeArgs = [" + scopeSuffix + "];"); 
     31 
     32                dojo._scopePrefixArgs = scopePrefix; 
     33                dojo._scopePrefix = "(function(" + scopePrefix + "){"; 
     34                dojo._scopeSuffix = "})(" + scopeSuffix + ")"; 
     35                dojo._scopeMap = scopeMap; 
     36                dojo._scopeMapRev = scopeMapRev; 
     37        }