forked from troopjs/troopjs-requirejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.js
53 lines (43 loc) · 1018 Bytes
/
json.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @license MIT http://troopjs.mit-license.org/
*/
define([
"text",
"troopjs-util/select",
"poly/json"
], function (text, select) {
"use strict";
/**
* RequireJS json plugin
* @class requirejs.json
* @static
* @alias plugin.requirejs
*/
//TODO Add usage docs
var NULL = null;
var PATTERN = /(.+?)#(.+)$/;
var buildMap = {};
return {
"load": function (name, req, load, config) {
var key = name;
var query = "";
var matches;
if ((matches = PATTERN.exec(name)) !== NULL) {
name = matches[1];
query = matches[2];
}
text.get(req.toUrl(name), function (source) {
var compiled = select.call(JSON.parse(source), query);
if (config.isBuild) {
buildMap[key] = compiled;
}
load(compiled);
}, load.error);
},
write : function (pluginName, moduleName, write) {
if (moduleName in buildMap) {
write("define('" + pluginName + "!" + moduleName + "', function(){ return " + JSON.stringify(buildMap[moduleName]) + "});");
}
}
};
});