Skip to content

Instantly share code, notes, and snippets.

@liferealized
Created June 9, 2010 15:30
Show Gist options
  • Save liferealized/431649 to your computer and use it in GitHub Desktop.
Save liferealized/431649 to your computer and use it in GitHub Desktop.
// create directory and unzip code for the most recent version of each plugin
if (loc.pluginFiles.recordCount)
{
loc.iEnd = loc.pluginFiles.recordCount;
for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
{
loc.name = loc.pluginFiles["name"][loc.i];
loc.pluginName = ListFirst(loc.name, "-");
if (!StructKeyExists(application.wheels.plugins, loc.pluginName))
{
loc.pluginVersion = Replace(ListLast(loc.name, "-"), ".zip", "", "one");
loc.thisPluginFile = loc.pluginFolder & "/" & loc.name;
loc.thisPluginFolder = loc.pluginFolder & "/" & LCase(loc.pluginName);
if (!DirectoryExists(loc.thisPluginFolder))
$directory(action="create", directory=loc.thisPluginFolder);
$zip(action="unzip", destination=loc.thisPluginFolder, file=loc.thisPluginFile, overwrite=application.wheels.overwritePlugins);
loc.fileName = LCase(loc.pluginName) & "." & loc.pluginName;
loc.plugin = $createObjectFromRoot(path=application.wheels.pluginComponentPath, fileName=loc.fileName, method="init");
loc.plugin.pluginVersion = loc.pluginVersion;
if (!StructKeyExists(loc.plugin, "version") || ListFind(loc.plugin.version, SpanExcluding(application.wheels.version, " ")) || application.wheels.loadIncompatiblePlugins)
{
application.wheels.plugins[loc.pluginName] = loc.plugin;
if (StructKeyExists(loc.plugin, "version") && !ListFind(loc.plugin.version, SpanExcluding(application.wheels.version, " ")))
application.wheels.incompatiblePlugins = ListAppend(application.wheels.incompatiblePlugins, loc.pluginName);
}
}
}
// store plugin injection information in application scope so we don't have to run this code on each injection
loc.iEnd = ListLen(application.wheels.mixableComponents);
for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
{
application.wheels.mixins[ListGetAt(application.wheels.mixableComponents, loc.i)] = {};
}
loc.iList = StructKeyList(application.wheels.plugins);
loc.iEnd = ListLen(loc.iList);
for (loc.i=1; loc.i <= loc.iEnd; loc.i++)
{
loc.iItem = ListGetAt(loc.iList, loc.i);
loc.pluginMeta = GetMetaData(application.wheels.plugins[loc.iItem]); // grab meta data of the plugin
if (!StructKeyExists(loc.pluginMeta, "environment") || ListFindNoCase(loc.pluginMeta.environment, application.wheels.environment))
{
loc.pluginMixins = "global"; // by default and for backwards compatibility, we inject all methods into all objects
if (StructKeyExists(loc.pluginMeta, "mixin"))
loc.pluginMixins = loc.pluginMeta["mixin"]; // if the component has a default mixin value, assign that value
// loop through all plugin methods and enter injection info accordingly (based on the mixin value on the method or the default one set on the entire component)
loc.jList = StructKeyList(application.wheels.plugins[loc.iItem]);
loc.jEnd = ListLen(loc.jList);
for (loc.j=1; loc.j <= loc.jEnd; loc.j++)
{
loc.jItem = ListGetAt(loc.jList, loc.j);
if (IsCustomFunction(application.wheels.plugins[loc.iItem][loc.jItem]) && loc.jItem != "init")
{
loc.methodMeta = GetMetaData(application.wheels.plugins[loc.iItem][loc.jItem]);
loc.methodMixins = loc.pluginMixins;
if (StructKeyExists(loc.methodMeta, "mixin"))
loc.methodMixins = loc.methodMeta["mixin"];
// mixin all methods except those marked as none
if (loc.methodMixins != "none")
{
loc.kEnd = ListLen(application.wheels.mixableComponents);
for (loc.k=1; loc.k <= loc.kEnd; loc.k++)
{
loc.kItem = ListGetAt(application.wheels.mixableComponents, loc.k);
if (loc.methodMixins == "global" || ListFindNoCase(loc.methodMixins, loc.kItem))
{
application.wheels.mixins[loc.kItem][loc.jItem] = application.wheels.plugins[loc.iItem][loc.jItem];
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment