wilton/loader
Load resource files using logical module names.
More...
Functions | |
String | findModuleDirectory (Object|String module, Function|Undefined callback) |
Find out the full path to the specified module direcotory. | |
String | findModulePath (Object|String module, Function|Undefined callback) |
Find out the full path to the specified module. | |
Object | loadAppConfig (Object startupModule, Function|Undefined callback) |
Load config.json file from appdir/conf/ directory. | |
Object | loadModuleJson (String modname, Function|Undefined callback) |
Load JSON file using logical module path. | |
String | loadModuleResource (String modname, Object|Undefined options, Function|Undefined callback) |
Load resource file using logical module path. |
This module allows to load resource files that are stored inside the JavaScript source tree in file system directories on inside ZIP files.
Additonally it contains loadAppConfig()
function that loads config.json
file from its expected location inside appdir/conf/
directory.
Usage example:
String loader::findModuleDirectory | ( | Object|String | module, |
Function|Undefined | callback | ||
) |
Finds out directory where resides file of the specified module.
module | Object|String either module object or module ID String |
callback | Function|Undefined callback to receive result or error |
String
path to module directory String loader::findModulePath | ( | Object|String | module, |
Function|Undefined | callback | ||
) |
Returns the full path to the specified module. Returned path may point either to file system or to ZIP path.
Note, that to get the path to module file in FS input module ID must include the file extension, example: module.id + ".js"
.
module | Object|String either module object or module ID String |
callback | Function|Undefined callback to receive result or error |
String
full path to the specified module Object loader::loadAppConfig | ( | Object | startupModule, |
Function|Undefined | callback | ||
) |
This method expects that application is running using the "standard" directory structure:
appdir
: application directory, can have arbitrary namebin
: (optional) contains executables and librariesconf
: contains config.json
log
: contains log output fileswork
: contains temporary filesindex.js
: startup moduleLoaded file contents are preprocessed replacing references to {{{appdir}}}
with an actual path to application directory.
startupModule | Object RequireJS startup module |
callback | Function|Undefined callback to receive result or error |
Object
configuration object parsed from config.json
file Object loader::loadModuleJson | ( | String | modname, |
Function|Undefined | callback | ||
) |
Loads JSON file with the specified logical module path from file system or from ZIP file.
Loaded JSON file is parsed and returned as an Object
.
modname | String logical module path to the JSON file |
callback | Function|Undefined callback to receive result or error |
Object
parsed contents of the specified JSON file String loader::loadModuleResource | ( | String | modname, |
Object|Undefined | options, | ||
Function|Undefined | callback | ||
) |
Loads text resource file with the specified logical module path from file system or from ZIP file.
modname | String logical module path to the resource file |
options | Object|Undefined configuration object, can be omitted, see possible options below |
callback | Function|Undefined callback to receive result or error |
String
contents of the specified fileOptions
Boolean
whether data read from specified resources needs to be converted to HEX format before returning it to caller; false
by default