source: Dev/branches/rest-dojo-ui/client/util/build/plugins/text.js @ 274

Last change on this file since 274 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.7 KB
Line 
1define(["../buildControl", "dojo/json"], function(bc, json) {
2        // note: this builder plugin only writes text that is part of a package
3        var makePluginPseudoModule= function(module, moduleInfo) {
4                        return {
5                                module:module,
6                                pid:moduleInfo.pid,
7                                mid:moduleInfo.mid,
8                                deps:[],
9                                getText:function(){
10                                        return json.stringify(this.module.text+"");
11                                },
12                                internStrings:function(){
13                                        return ["url:" + this.mid, json.stringify(this.module.text+"")];
14                                }
15                        };
16                },
17
18                start= function(
19                        mid,
20                        referenceModule,
21                        bc
22                ) {
23                        var textPlugin= bc.amdResources["dojo/text"];
24                        if (!textPlugin) {
25                                throw new Error("text! plugin missing");
26                        }
27
28                        // mid may contain a pragma (e.g. "!strip"); remove
29                        mid= mid.split("!")[0];
30
31                        // the following taken from the loader toUrl function
32                        // name must include a filetype; fault tolerate to allow no filetype (but things like "path/to/version2.13" will assume filetype of ".13")
33                        var
34                                match = mid.match(/(.+)(\.[^\/\.]+?)$/),
35                                root = (match && match[1]) || mid,
36                                ext = (match && match[2]) || "",
37                                moduleInfo =  bc.getSrcModuleInfo(root, referenceModule),
38                                url= moduleInfo.url;
39                        // recall, getModuleInfo always returns a url with a ".js" suffix iff pid; therefore, we've got to trim it
40                        url= (typeof moduleInfo.pid == "string" ? url.substring(0, url.length - 3) : url) + ext;
41
42                        // fixup the moduleInfo to reflect type filetype extention
43                        moduleInfo.url= url;
44                        moduleInfo.mid+= ext;
45
46                        var textResource= bc.resources[url];
47                        if (!textResource) {
48                                throw new Error("text resource (" + url + ") missing");
49                        }
50                        if(bc.internStrings){
51                                textResource.tag.noWrite= 0;
52                        }
53                        return [textPlugin, makePluginPseudoModule(textResource, moduleInfo)];
54                };
55
56        return {
57                start:start
58        };
59});
Note: See TracBrowser for help on using the repository browser.