make the boot script extendable so that we can use it with Skywriter's

larger collection of plugins

Commit feacf6c33ab369aae1bc8bcda0a3bbb3d24f08f7
Author: Kevin Dangoor <kid@blazingthings.com>
Date:   Tue Nov 2 13:38:59 2010 -0400
This commit is contained in:
Joe Walker 2010-11-16 14:10:51 +00:00
Родитель d95c4f9e6d
Коммит aa7dd8b839
3 изменённых файлов: 57 добавлений и 160 удалений

Просмотреть файл

@ -1,128 +0,0 @@
commit feacf6c33ab369aae1bc8bcda0a3bbb3d24f08f7
Author: Kevin Dangoor <kid@blazingthings.com>
Date: Tue Nov 2 13:38:59 2010 -0400
make the boot script extendable so that we can use it with Skywriter's
larger collection of plugins
diff --git a/scripts/boot.js b/scripts/boot.js
index c9fafa1..d1b721b 100644
--- a/scripts/boot.js
+++ b/scripts/boot.js
@@ -35,43 +35,65 @@
*
* ***** END LICENSE BLOCK ***** */
-
-require.ready(function() {
- var knownPlugins = ["util", "rangeutils", "events", "types", "settings", "canon",
- "edit_session", "syntax_manager", "undomanager",
- "keyboard"];
- var knownSingleFilePlugins = ["worker_manager", "syntax_directory", "environment"];
-
- var pluginPackageInfo = [
- {
- name: "plugins",
- main: "index"
- }
- ];
+// TODO: Yuck! A global function
+var setupPlugins = function(config) {
+ config = config || {};
+ if (!config.pluginDirs) {
+ config.pluginDirs = {};
+ }
+ config.pluginDirs["../plugins"] = {
+ packages: ["util", "rangeutils", "events", "types", "settings", "canon",
+ "edit_session", "syntax_manager", "undomanager",
+ "keyboard"],
+ singleFiles: ["worker_manager", "syntax_directory", "environment"]
+ };
+ config.pluginDirs["../thirdparty"] = {
+ singleFiles: ["underscore"]
+ };
- var thirdpartySingleFile = ["underscore"];
+ var knownPlugins = [];
- // set up RequireJS to know that our plugins all have a main module called "index"
- knownPlugins.forEach(function(pluginName) {
- pluginPackageInfo.push({
- name: pluginName,
- main: "index"
- });
- });
+ var pluginPackageInfo = {
+ "../plugins": [
+ {
+ name: "plugins",
+ main: "index"
+ }
+ ]
+ };
var paths = {};
- thirdpartySingleFile.forEach(function(pluginName) {
- paths[pluginName] = "../thirdparty/" + pluginName;
- });
- knownSingleFilePlugins.forEach(function(pluginName) {
- paths[pluginName] = "../plugins/" + pluginName;
- knownPlugins.push(pluginName);
- });
+ var i;
+ var location;
+
+ // set up RequireJS to know that our plugins all have a main module called "index"
+ for (var pluginDir in config.pluginDirs) {
+ var dirInfo = config.pluginDirs[pluginDir];
+ if (dirInfo.packages) {
+ location = pluginPackageInfo[pluginDir];
+ if (location === undefined) {
+ pluginPackageInfo[pluginDir] = location = [];
+ }
+ var packages = dirInfo.packages;
+ for (i = 0; i < packages.length; i++) {
+ location.push({
+ name: packages[i],
+ main: "index"
+ });
+ knownPlugins.push(packages[i]);
+ }
+ }
+ if (dirInfo.singleFiles) {
+ for (i = 0; i < dirInfo.singleFiles.length; i++) {
+ var pluginName = dirInfo.singleFiles[i];
+ paths[pluginName] = pluginDir + "/" + pluginName;
+ knownPlugins.push(pluginName);
+ }
+ }
+ }
require({
- packagePaths: {
- "../plugins": pluginPackageInfo
- },
+ packagePaths: pluginPackageInfo,
paths: paths
});
require(["plugins"], function() {
@@ -98,4 +120,4 @@ require.ready(function() {
});
});
-});
+};
diff --git a/test.html b/test.html
index b8e0eb2..aaaddc0 100644
--- a/test.html
+++ b/test.html
@@ -11,5 +11,8 @@
</script>
<script src="scripts/require.js"></script>
<script src="scripts/boot.js"></script>
+ <script>
+ setupPlugins();
+ </script>
</body>
</html>
\ No newline at end of file

Просмотреть файл

@ -35,43 +35,65 @@
*
* ***** END LICENSE BLOCK ***** */
require.ready(function() {
var knownPlugins = ["util", "rangeutils", "events", "types", "settings", "canon",
"edit_session", "syntax_manager", "undomanager",
"keyboard"];
var knownSingleFilePlugins = ["worker_manager", "syntax_directory", "environment"];
// TODO: Yuck! A global function
var setupPlugins = function(config) {
config = config || {};
if (!config.pluginDirs) {
config.pluginDirs = {};
}
config.pluginDirs["../plugins"] = {
packages: ["util", "rangeutils", "events", "types", "settings", "canon",
"edit_session", "syntax_manager", "undomanager",
"keyboard"],
singleFiles: ["worker_manager", "syntax_directory", "environment"]
};
config.pluginDirs["../thirdparty"] = {
singleFiles: ["underscore"]
};
var pluginPackageInfo = [
{
name: "plugins",
main: "index"
}
];
var knownPlugins = [];
var thirdpartySingleFile = ["underscore"];
// set up RequireJS to know that our plugins all have a main module called "index"
knownPlugins.forEach(function(pluginName) {
pluginPackageInfo.push({
name: pluginName,
main: "index"
});
});
var pluginPackageInfo = {
"../plugins": [
{
name: "plugins",
main: "index"
}
]
};
var paths = {};
thirdpartySingleFile.forEach(function(pluginName) {
paths[pluginName] = "../thirdparty/" + pluginName;
});
knownSingleFilePlugins.forEach(function(pluginName) {
paths[pluginName] = "../plugins/" + pluginName;
knownPlugins.push(pluginName);
});
var i;
var location;
// set up RequireJS to know that our plugins all have a main module called "index"
for (var pluginDir in config.pluginDirs) {
var dirInfo = config.pluginDirs[pluginDir];
if (dirInfo.packages) {
location = pluginPackageInfo[pluginDir];
if (location === undefined) {
pluginPackageInfo[pluginDir] = location = [];
}
var packages = dirInfo.packages;
for (i = 0; i < packages.length; i++) {
location.push({
name: packages[i],
main: "index"
});
knownPlugins.push(packages[i]);
}
}
if (dirInfo.singleFiles) {
for (i = 0; i < dirInfo.singleFiles.length; i++) {
var pluginName = dirInfo.singleFiles[i];
paths[pluginName] = pluginDir + "/" + pluginName;
knownPlugins.push(pluginName);
}
}
}
require({
packagePaths: {
"../plugins": pluginPackageInfo
},
packagePaths: pluginPackageInfo,
paths: paths
});
require(["plugins"], function() {
@ -98,4 +120,4 @@ require.ready(function() {
});
});
});
};

Просмотреть файл

@ -11,5 +11,8 @@
</script>
<script src="scripts/require.js"></script>
<script src="scripts/boot.js"></script>
<script>
setupPlugins();
</script>
</body>
</html>