plugin wrapper code - convert to use build.py macros. this ensures it's identical in all plugins, so the mobile app can remove/modify it without issues. also makes it easy to change if required
This commit is contained in:
30
build.py
30
build.py
@ -61,6 +61,33 @@ distUrlBase = settings.get('distUrlBase')
|
||||
buildMobile = settings.get('buildMobile')
|
||||
|
||||
|
||||
# plugin wrapper code snippets. handled as macros, to ensure that
|
||||
# 1. indentation caused by the "function wrapper()" doesn't apply to the plugin code body
|
||||
# 2. the wrapper is formatted correctly for removal by the IITC Mobile android app
|
||||
pluginWrapperStart = """
|
||||
function wrapper() {
|
||||
// ensure plugin framework is there, even if iitc is not yet loaded
|
||||
if(typeof window.plugin !== 'function') window.plugin = function() {};
|
||||
|
||||
"""
|
||||
pluginWrapperEnd = """
|
||||
if(window.iitcLoaded && typeof setup === 'function') {
|
||||
setup();
|
||||
} else {
|
||||
if(window.bootPlugins)
|
||||
window.bootPlugins.push(setup);
|
||||
else
|
||||
window.bootPlugins = [setup];
|
||||
}
|
||||
} // wrapper end
|
||||
// inject code into site context
|
||||
var script = document.createElement('script');
|
||||
script.appendChild(document.createTextNode('('+ wrapper +')();'));
|
||||
(document.body || document.head || document.documentElement).appendChild(script);
|
||||
|
||||
"""
|
||||
|
||||
|
||||
def readfile(fn):
|
||||
with io.open(fn, 'Ur', encoding='utf8') as f:
|
||||
return f.read()
|
||||
@ -137,6 +164,9 @@ def doReplacements(script,updateUrl,downloadUrl):
|
||||
script = script.replace('@@UPDATEURL@@', updateUrl)
|
||||
script = script.replace('@@DOWNLOADURL@@', downloadUrl)
|
||||
|
||||
script = script.replace('@@PLUGINSTART@@', pluginWrapperStart)
|
||||
script = script.replace('@@PLUGINEND@@', pluginWrapperEnd)
|
||||
|
||||
return script
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user