Changeset 6929

Show
Ignore:
Timestamp:
12/20/06 22:40:10 (2 years ago)
Author:
jburke
Message:

Fixes #2196: now have a intern-strings option for things that do not use templatePath and templateCssPath. Also moved intern-strings from python into javascript

Location:
trunk
Files:
2 added
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/buildscripts/build.xml

    r6924 r6929  
    813813                ]]> 
    814814                </script> 
    815                 <script language="jython"> 
    816                         <![CDATA[ 
    817 import sys 
    818 # make the python standard library avialable 
    819 sys.path.append(project.resolveFile("lib/pyLib.zip").getPath()) 
    820 sys.path.append(project.resolveFile(".").getPath()) 
    821  
    822 # import re 
    823 import os 
    824 from buildUtil import * 
    825  
    826 print "Interning strings for directory: " + dojo.getProperty("release_dir") 
    827 internTemplateStrings(project.resolveFile(dojo.getProperty("profileFile")).getPath(), dojo.getProperty("dojoLoader"), project.resolveFile(dojo.getProperty("release_dir")).getPath()) 
    828 ]]> 
    829                 </script> 
     815                 
     816                <java jar="./lib/custom_rhino.jar" failonerror="true" fork="true" 
     817                        logError="true"> 
     818                        <arg value="internStrings.js" /> 
     819                        <arg value="${profileFile}" /> 
     820                        <arg value="${dojoLoader}" /> 
     821                        <arg value="${release_dir}" /> 
     822                </java> 
    830823        </target> 
    831824        <!-- end intern-strings task --> 
  • trunk/buildscripts/buildUtil.js

    r6847 r6929  
    196196} 
    197197 
    198  
    199 buildUtil.getPrefixesFromProfile = function(profileFile){ 
    200         //summary: Load the profile file to get resource paths for external modules. 
     198buildUtil.getDependencyPropertyFromProfile = function(/*String*/profileFile, /*String*/propName){ 
     199        //summary: Gets a dependencies property from the profile file. The value 
     200        //of the property is assumed to be an array. An array will always be returned, 
     201        //but it may be an empty array. 
     202 
    201203        //Use new String to make sure we have a JS string (not a Java string) 
    202204        //readText is from hostenv_rhino.js, so be sure to load Dojo before calling this function. 
    203205        var profileText = new String(readText(profileFile)); 
    204         var result = null; 
    205          
    206         //Extract only dependencies.prefixes. 
    207         var dependencies = { 
    208                 prefixes: [] 
    209         }; 
    210          
    211206        //Get rid of CR and LFs since they seem to mess with the regexp match. 
    212207        //Using the "m" option on the regexp was not enough. 
    213208        profileText = profileText.replace(/\r/g, ""); 
    214209        profileText = profileText.replace(/\n/g, ""); 
    215          
    216         var matches = profileText.match(/(dependencies\.prefixes\s*=\s*\[.*\]\s*\;)/m); 
     210 
     211 
     212        var result = []; 
     213        var matchRegExp = new RegExp("(dependencies\\." + propName + "\\s*=\\s*\\[[^;]*\\s*\\])", "m"); 
     214 
     215        var matches = profileText.match(matchRegExp); 
     216        //Create a shell object to hold the evaled properties. 
     217        var dependencies = {}; 
     218         
    217219        if(matches && matches.length > 0){ 
    218220                eval(matches[0]); 
    219                 if(dependencies && dependencies.prefixes && dependencies.prefixes.length > 0){ 
    220                         result = dependencies.prefixes; 
    221                 } 
    222         } 
    223  
    224         return result; //Array of arrays 
     221                if(dependencies && dependencies[propName] && dependencies[propName].length > 0){ 
     222                        result = dependencies[propName]; 
     223                } 
     224        } 
     225 
     226        return result; //Array 
    225227} 
    226228 
    227229buildUtil.configPrefixes = function(profileFile){ 
    228230        //summary: Get the resource prefixes from the profile and registers the prefixes with Dojo. 
    229         var prefixes = this.getPrefixesFromProfile(profileFile); 
     231        var prefixes = this.getDependencyPropertyFromProfile(profileFile, "prefixes"); 
    230232        if(prefixes && prefixes.length > 0){ 
    231233                for(i = 0; i < prefixes.length; i++){ 
  • trunk/buildscripts/buildUtil.py

    r6590 r6929  
    1010import glob 
    1111import string 
    12  
    13 def escape(instr): 
    14         out = [] 
    15         for x in xrange(len(instr)): 
    16                 if instr[x] == "\\": 
    17                         out.append("\\\\") 
    18                 elif instr[x] == "\n": 
    19                         out.append("\\n") 
    20                 elif instr[x] == "\"": 
    21                         out.append("\\\"") 
    22                 else: 
    23                     out.append(instr[x]) 
    24         return string.join(out, "") 
    25  
    26 def makeResourceUri(resourceName, templatePath, srcRoot, prefixes): 
    27         # Find best matching prefix. 
    28         bestPrefix = "" 
    29         bestPrefixPath = "" 
    30         if prefixes: 
    31                 for prefix in prefixes: 
    32                         # Prefix must match from the start of the resourceName string. 
    33                         if resourceName.find(prefix[0]) == 0: 
    34                                 if len(prefix[0]) > len(bestPrefix): 
    35                                         bestPrefix = prefix[0] 
    36                                         bestPrefixPath = prefix[1] 
    37  
    38                 if bestPrefixPath != "": 
    39                         # Convert resourceName to a path 
    40                         resourceName = resourceName.replace(bestPrefix, "", 1); 
    41                         if resourceName.find(".") == 0: 
    42                                 resourceName = resourceName[1:len(resourceName)] 
    43                         resourceName = resourceName.replace(".", "/"); 
    44  
    45                         # Final path construction 
    46                         finalPath = srcRoot 
    47                         finalPath += bestPrefixPath + "/" 
    48                         if resourceName: 
    49                                 finalPath += resourceName + "/" 
    50                         finalPath += templatePath 
    51                          
    52                         return finalPath 
    53  
    54         return srcRoot + templatePath 
    55  
    56 def regexpMagic(loader, pkgString, srcRoot, prefixes, skiplist=[]): 
    57         uriMethod = "dojo.uri.dojoUri" 
    58         #if loader == "xdomain": 
    59         #       uriMethod = "dojo.uri.dojoUriXd" 
    60         # "Now they have two problems" -- jwz 
    61         #       http://en.wikiquote.org/wiki/Jamie_Zawinski 
    62         matches = re.findall('((templatePath|templateCssPath)\s*(=|:)\s*(dojo\.uri\.(dojo|module)?Uri\(\s*)?[\"\']([\w\.\/]+)[\"\'](([\,\s]*)[\"\']([\w\.\/]*)[\"\'])?(\s*\))?)', pkgString) 
    63         filePath = "" 
    64         for x in matches: 
    65                 # Build file path 
    66                 if x[4] == "dojo": 
    67                         print "Dojo match: " + x[5] 
    68                         filePath = srcRoot + x[5] 
    69                         resourceNsName = "dojo:"+x[5]; 
    70                 else: 
    71                         print "Module match: " + x[5] + " and " + x[8] 
    72                         filePath = makeResourceUri(x[5], x[8], srcRoot, prefixes) 
    73                         resourceNsName = x[5]+':'+x[8] 
    74  
    75                 if resourceNsName in skiplist: 
    76                         print "Skip intern resource " + filePath 
    77                         continue 
    78  
    79                 print "Interning resource path: " + filePath 
    80  
    81                 if x[1] == "templatePath": 
    82                         # Replace templatePaths 
    83                         replacement = "templateString" + x[2] + "\"" + escape(open(filePath).read()) + "\"" 
    84                         pkgString = string.replace(pkgString, x[0], replacement) 
    85                 else: 
    86                         # Dealing with templateCssPath 
    87                         # For the CSS we need to keep the template path in there 
    88                         # since the widget loading stuff uses the template path to 
    89                         # know whether the CSS has been processed yet. 
    90                         # Could have matched assignment via : or =. Need different statement separators at the end. 
    91                         assignSeparator = x[2] 
    92                         statementSeparator = "," 
    93                         statementPrefix = "" 
    94  
    95                         # FIXME: this is a little weak because it assumes a "this" in front of the templateCssPath 
    96                         # when it is assigned using an "=", as in 'this.templateCssPath = dojo.uri.dojoUri("some/path/to/Css.css");' 
    97                         # In theory it could be something else, but in practice it is not, and it gets a little too weird 
    98                         # to figure out, at least for now. 
    99                         if assignSeparator == "=": 
    100                                 statementSeparator = ";" 
    101                                 statementPrefix = "this." 
    102  
    103                         replacement = "templateCssString" + assignSeparator + "\"" + escape(open(filePath).read()) + "\"" + statementSeparator + statementPrefix + x[0] 
    104                         pkgString = string.replace(pkgString, x[0], replacement) 
    105  
    106         return pkgString 
    107  
    108 def internTemplateStringsInFile(loader, packageFile, srcRoot, prefixes, skiplist): 
    109                 print packageFile 
    110                 pfd = open(packageFile) 
    111                 pkgString = pfd.read() 
    112                 pfd.close() 
    113  
    114                 pkgString = regexpMagic(loader, pkgString, srcRoot, prefixes, skiplist) 
    115  
    116                 pfd = open(packageFile, "w") 
    117                 pfd.write(pkgString) 
    118                 pfd.close() # flush is implicit 
    119  
    120  
    121 def internXdFiles(loader, xdDir, srcRoot, prefixes, skiplist): 
    122         xdFiles = glob.glob1(xdDir, "*.xd.js") 
    123         for name in xdFiles: 
    124                 print "XD INTERNING: " + name 
    125                 internTemplateStringsInFile(loader, xdDir+os.sep+name, srcRoot, prefixes, skiplist) 
    126  
    127  
    128 def internTemplateStrings(profileFile, loader="default", packageDir="../release/dojo", srcRoot="../"): 
    129         #Fix up dojo.js 
    130         print "loader: " + loader 
    131         print "packageDir - " + packageDir 
    132         packageFile = packageDir+"/dojo.js" 
    133  
    134  
    135         #Load the profile file so we can get module prefixes. 
    136         pfd = open(profileFile) 
    137         profileString = pfd.read() 
    138         pfd.close() 
    139  
    140         # Parse out the module prefixes and build a python list of lists object. 
    141         compiledRe = re.compile('(dependencies\.prefixes\s*=\s*(\[\s*([^;]*)\s*\]))', re.DOTALL | re.MULTILINE) 
    142         matches = compiledRe.findall(profileString) 
    143  
    144         if matches: 
    145                 exec("prefixes = " + matches[0][1]) 
    146                 print "Using the following prefixes: " 
    147                 print prefixes 
    148         else: 
    149                 prefixes = [] 
    150  
    151         skiplistRe =  re.compile('(dependencies\.internSkipList\s*=\s*(\[\s*([^;]*)\s*\]))', re.DOTALL | re.MULTILINE) 
    152         matches = skiplistRe.findall(profileString) 
    153  
    154         if matches: 
    155                 exec("skiplist = " + matches[0][1]) 
    156                 print "Using the following skip list: " 
    157                 print skiplist 
    158         else: 
    159                 skiplist = [] 
    160         #try: 
    161         internTemplateStringsInFile(loader, packageFile, srcRoot, prefixes, skiplist) 
    162         #except: 
    163         #       packageFile = packageDir+"/__package__.js" 
    164         #       internTemplateStringsInFile(loader, packageFile, srcRoot) 
    165  
    166         #If doing xdomain, then need to fix up the .xd.js files in the widget subdir. 
    167         #Hack alert! I am not patient enough to figure out how to do dir recursion 
    168         #in python right now. 
    169         internXdFiles(loader, packageDir+"/src/widget", srcRoot, prefixes, skiplist) 
    170         internXdFiles(loader, packageDir+"/src/widget/html", srcRoot, prefixes, skiplist) 
    171         internXdFiles(loader, packageDir+"/src/widget/svg", srcRoot, prefixes, skiplist) 
    172         internXdFiles(loader, packageDir+"/src/widget/vml", srcRoot, prefixes, skiplist) 
    173  
    17412 
    17513def replaceVersion(fileName, version): 
  • trunk/src/widget/DomWidget.js

    r6794 r6929  
    5555                } 
    5656        } 
     57 
    5758        if((!obj.templateString)&&(!avoidCache)){ 
    5859                obj.templateString = templateString || ts["string"]; 
    5960        } 
     61        if(obj.templateString){ 
     62                obj.templateString = this._sanitizeTemplateString(obj.templateString); 
     63        } 
     64 
    6065        if((!obj.templateNode)&&(!avoidCache)){ 
    6166                obj.templateNode = ts["node"]; 
     
    6469                // fetch a text fragment and assign it to templateString 
    6570                // NOTE: we rely on blocking IO here! 
    66                 var tstring = dojo.hostenv.getText(tpath); 
    67                 if(tstring){ 
    68                         // strip <?xml ...?> declarations so that external SVG and XML 
    69                         // documents can be added to a document without worry 
    70                         tstring = tstring.replace(/^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im, ""); 
    71                         var matches = tstring.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im); 
    72                         if(matches){ 
    73                                 tstring = matches[1]; 
    74                         } 
    75                 }else{ 
    76                         tstring = ""; 
    77                 } 
     71                var tstring = this._sanitizeTemplateString(dojo.hostenv.getText(tpath)); 
    7872 
    7973                obj.templateString = tstring; 
     
    8680        } 
    8781} 
     82 
     83dojo.widget._sanitizeTemplateString = function(/*String*/tString){ 
     84        //summary: Strips <?xml ...?> declarations so that external SVG and XML 
     85        //documents can be added to a document without worry. Also, if the string 
     86        //is an HTML document, only the part inside the body tag is returned. 
     87        if(tString){ 
     88                tString = tString.replace(/^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im, ""); 
     89                var matches = tString.match(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im); 
     90                if(matches){ 
     91                        tString = matches[1]; 
     92                } 
     93        }else{ 
     94                tString = ""; 
     95        } 
     96        return tString; //String 
     97} 
     98 
    8899dojo.widget._templateCache.dummyCount = 0; 
    89100 
  • trunk/src/widget/Editor2.js

    r6773 r6929  
    55dojo.require("dojo.widget.Editor2Toolbar"); 
    66dojo.require("dojo.i18n.common"); 
     7dojo.require("dojo.uri.cache"); 
    78dojo.requireLocalization("dojo.widget", "Editor2"); 
    89dojo.requireLocalization("dojo.widget", "Editor2BrowserCommand"); 
     
    206207                // toolbarTemplatePath: dojo.uri.Uri 
    207208                //              to specify the template file for the toolbar 
    208                 toolbarTemplatePath: dojo.uri.dojoUri("src/widget/templates/EditorToolbarOneline.html"), 
     209                toolbarTemplatePath: dojo.uri.cache.allow(dojo.uri.dojoUri("src/widget/templates/EditorToolbarOneline.html")), 
    209210 
    210211                // toolbarTemplateCssPath: dojo.uri.Uri 
    211212                //              to specify the css file for the toolbar 
    212                 toolbarTemplateCssPath: dojo.uri.dojoUri("src/widget/templates/EditorToolbar.css"), 
     213                toolbarTemplateCssPath: dojo.uri.cache.allow(dojo.uri.dojoUri("src/widget/templates/EditorToolbar.css")), 
    213214 
    214215                // toolbarPlaceHolder: String 
    215216                //              element id to specify where to attach the toolbar 
    216217                toolbarPlaceHolder: '', 
    217  
    218 //              toolbarTemplatePath: dojo.uri.dojoUri("src/widget/templates/Editor2/EditorToolbarFCKStyle.html"), 
    219 //              toolbarTemplateCssPath: dojo.uri.dojoUri("src/widget/templates/Editor2/FCKDefault/EditorToolbarFCKStyle.css"), 
    220218 
    221219                _inSourceMode: false, 
     
    260258                                if(!this.toolbarWidget){ 
    261259                                                var tbOpts = {shareGroup: this.toolbarGroup, parent: this, lang: this.lang}; 
    262                                                 tbOpts.templatePath = this.toolbarTemplatePath; 
     260                                                tbOpts.templateString = dojo.uri.cache.get(this.toolbarTemplatePath); 
    263261                                                if(this.toolbarTemplateCssPath){ 
    264262                                                        tbOpts.templateCssPath = this.toolbarTemplateCssPath; 
     263                                                        tbOpts.templateCssString = dojo.uri.cache.get(this.toolbarTemplateCssPath); 
    265264                                                } 
    266265                                                if(this.toolbarPlaceHolder){ 
  • trunk/src/widget/Editor2Plugin/DropDownList.js

    r6588 r6929  
    5151                        this._contentPane = dojo.widget.createWidget("ContentPane", {preload: 'true'}); 
    5252                        this._contentPane.addOnLoad(this, "setup"); 
    53                         this._contentPane.setUrl(this.href); 
     53                        this._contentPane.setContent(dojo.uri.cache.get(this.href)); 
    5454                } 
    5555        }, 
     
    101101        // summary: dojo.widget.Editor2ToolbarFormatBlockSelect is an improved format block setting item 
    102102 
    103         href: dojo.uri.dojoUri("src/widget/templates/Editor2/EditorToolbar_FormatBlock.html"), 
     103        href: dojo.uri.cache.allow(dojo.uri.dojoUri("src/widget/templates/Editor2/EditorToolbar_FormatBlock.html")), 
    104104 
    105105        setup: function(){ 
     
    172172        // summary: dojo.widget.Editor2ToolbarFontSizeSelect provides a dropdown list for setting fontsize 
    173173 
    174         href: dojo.uri.dojoUri("src/widget/templates/Editor2/EditorToolbar_FontSize.html"), 
     174        href: dojo.uri.cache.allow(dojo.uri.dojoUri("src/widget/templates/Editor2/EditorToolbar_FontSize.html")), 
    175175 
    176176        setup: function(){ 
     
    240240dojo.declare("dojo.widget.Editor2ToolbarFontNameSelect", dojo.widget.Editor2ToolbarFontSizeSelect, { 
    241241        // summary: dojo.widget.Editor2ToolbarFontNameSelect provides a dropdown list for setting fontname 
    242         href: dojo.uri.dojoUri("src/widget/templates/Editor2/EditorToolbar_FontName.html") 
    243 }); 
     242        href: dojo.uri.cache.allow(dojo.uri.dojoUri("src/widget/templates/Editor2/EditorToolbar_FontName.html")) 
     243}); 
  • trunk/src/widget/Editor2Plugin/FindReplace.js

    r6608 r6929  
    5151                                {contentFile: "dojo.widget.Editor2Plugin.FindReplaceDialog",  
    5252                                contentClass: "Editor2ReplaceDialog", 
    53                                 href: dojo.uri.dojoUri("src/widget/templates/Editor2/Dialog/replace.html"),  
     53                                href: dojo.uri.cache.allow(dojo.uri.dojoUri("src/widget/templates/Editor2/Dialog/replace.html")),  
    5454                                title: "Replace", width: "350px", height: "200px", modal: false}); 
    5555                }