From af4743eb95fd552c31afaf2ebaba9404381c30e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Schr=C3=B6der?= Date: Thu, 21 May 2015 17:19:03 +0200 Subject: [PATCH] Added draft for static compilation script --- luciexpress/compile.sh | 23 +++++++++++++++++++ luciexpress/htdocs/index.html | 9 ++------ luciexpress/htdocs/js/app.js | 40 ++++++++++++++++++++++++++++++++++ luciexpress/htdocs/js/juci.js | 12 ++++++---- luciexpress/htdocs/js/theme.js | 8 +++++-- 5 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 luciexpress/compile.sh diff --git a/luciexpress/compile.sh b/luciexpress/compile.sh new file mode 100644 index 000000000..2a91dbb6e --- /dev/null +++ b/luciexpress/compile.sh @@ -0,0 +1,23 @@ +LIBFILES=(htdocs/lib/js/async.js htdocs/lib/js/js-schema.min.js htdocs/lib/js/require.js htdocs/lib/js/jquery.min.js htdocs/lib/js/angular.min.js htdocs/lib/js/angular-ui.min.js htdocs/lib/js/angular-ui-router.min.js htdocs/lib/js/angular-gettext.min.js htdocs/lib/js/bootstrap-select.min.js htdocs/lib/js/select.min.js htdocs/lib/js/angular-animate.min.js htdocs/lib/js/angular-ui-bootstrap-luci.min.js htdocs/lib/js/jquery-jsonrpc.js htdocs/lib/js/translations.js htdocs/lib/js/bootstrap.min.js htdocs/lib/js/angular-ui-switch.min.js htdocs/lib/js/angular-modal-service.min.js htdocs/lib/js/angular-checklist-model.js) +PLUGINFILES=$(find htdocs/plugins -type f -name "*js" | grep -v "test-") +THEMEFILES=$(find htdocs/themes -type f -name "*js" | grep -v "test-") +COREFILES=(htdocs/js/rpc.js htdocs/js/uci.js htdocs/js/juci.js htdocs/js/app.js htdocs/js/localStorage.js htdocs/js/config.js htdocs/js/navigation.js htdocs/js/status.js htdocs/js/session.js htdocs/js/tr.js htdocs/js/theme.js htdocs/js/timeout.js) +FILES=("${LIBFILES[@]}" "${COREFILES[@]}" "${PLUGINFILES[@]}" "${THEMEFILES[@]}"); + +echo "var JUCI_COMPILED = 1;" > htdocs/__all.js +for file in ${FILES[@]}; do + echo "FILE: $file"; + echo ";" >> htdocs/__all.js; + cat $file >> htdocs/__all.js; +done; + +HTMLFILES=$(find htdocs -type f -name "*html"|grep -v "index.html" | grep -v "__all.html") + +echo "" > htdocs/__all.html +for file in ${HTMLFILES[@]}; do + file=$(echo $file | sed 's/htdocs\///gi') + echo "HTML: $file"; + echo "' >> htdocs/__all.html; +done; diff --git a/luciexpress/htdocs/index.html b/luciexpress/htdocs/index.html index 026e008ad..147273536 100644 --- a/luciexpress/htdocs/index.html +++ b/luciexpress/htdocs/index.html @@ -21,8 +21,9 @@
+ + - @@ -40,11 +41,6 @@ - - - @@ -57,6 +53,5 @@ - diff --git a/luciexpress/htdocs/js/app.js b/luciexpress/htdocs/js/app.js index 26fc1eb53..8c9df2beb 100644 --- a/luciexpress/htdocs/js/app.js +++ b/luciexpress/htdocs/js/app.js @@ -1,5 +1,8 @@ //! Author: Martin K. Schröder +// TODO: make this automatic +var JUCI_COMPILED = 0; + $.jsonRPC.setup({ endPoint: '/ubus', namespace: 'luci' @@ -177,6 +180,43 @@ JUCI.app.config(function ($stateProvider, $locationProvider, $compileProvider, $ } }}]); +/* +JUCI.app.factory('$templateCache', function($cacheFactory, $http, $injector) { + var cache = $cacheFactory('templates'); + var allTplPromise; + + return { + get: function(url) { + var fromCache = cache.get(url); + + // already have required template in the cache + if (fromCache) { + return fromCache; + } + + // first template request ever - get the all tpl file + if (!allTplPromise) { + allTplPromise = $http.get('__all.html').then(function(response) { + // compile the response, which will put stuff into the cache + $injector.get('$compile')(response.data); + return response; + }); + } + + // return the all-tpl promise to all template requests + return allTplPromise.then(function(response) { + return { + status: response.status, + data: cache.get(url) + }; + }); + }, + + put: function(key, value) { + cache.put(key, value); + } + }; +});*/ // make autofocus directive work as expected JUCI.app.directive('autofocus', ['$timeout', function($timeout) { return { diff --git a/luciexpress/htdocs/js/juci.js b/luciexpress/htdocs/js/juci.js index c8625d216..3b777b9f3 100644 --- a/luciexpress/htdocs/js/juci.js +++ b/luciexpress/htdocs/js/juci.js @@ -17,7 +17,7 @@ var plugin = self.plugins[name]; var juci = self; return { - plugin_root: plugin.plugin_root, + plugin_root: ((plugin||{}).plugin_root||"plugins/"+name+"/"), directive: function(name, fn){ return angular.module("luci").directive(name, fn); }, @@ -64,7 +64,7 @@ $.getJSON(plugin_root + "/plugin.json") .done(function(data){ console.log("found plugin "+id); - $juci.module(id, plugin_root, data); + $juci.module(id, plugin_root, {}); $juci.plugins[id] = data; if(data && data.scripts){ data.scripts.map(function(x){scripts.push(plugin_root + "/" + x); }); @@ -166,9 +166,13 @@ }); }, function(next){ - require(scripts, function(module){ + if(!JUCI_COMPILED){ + require(scripts, function(module){ + next(); + }); + } else { next(); - }); + } }, function(next){ // get the menu navigation diff --git a/luciexpress/htdocs/js/theme.js b/luciexpress/htdocs/js/theme.js index af6052dee..0d6924f5e 100644 --- a/luciexpress/htdocs/js/theme.js +++ b/luciexpress/htdocs/js/theme.js @@ -21,9 +21,13 @@ if(data.scripts){ async.eachSeries(data.scripts, function(script, next){ console.log("Loading "+theme_root + "/"+script); - require([theme_root + "/"+script], function(module){ + if(!JUCI_COMPILED){ + require([theme_root + "/"+script], function(module){ + next(); + }); + } else { next(); - }); + } }, function(){ deferred.resolve(data); });