Skip to content

Commit

Permalink
Add directive partials to build.js
Browse files Browse the repository at this point in the history
  • Loading branch information
elemoine committed Mar 2, 2015
1 parent b8b5c27 commit 1c89b34
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CONST_Makefile
Expand Up @@ -75,6 +75,7 @@ OL_JS_FILES = $(shell find node_modules/openlayers/src/ol -type f -name '*.js' 2
NGEO_JS_FILES = $(shell find node_modules/ngeo/src -type f -name '*.js' 2> /dev/null)
APP_JS_FILES = $(shell find $(PACKAGE)/static/js -type f -name '*.js')
APP_HTML_FILES = $(shell find $(PACKAGE)/templates -type f -name '*.html')
APP_PARTIALS_FILES := $(shell find $(PACKAGE)/static/js -type f -name '*.html')
LESS_FILES = $(shell find $(PACKAGE)/static/less -type f -name '*.less' 2> /dev/null)
JSON_CLIENT_LOCALISATION_FILES = $(addprefix $(OUTPUT_DIR)/locale/, $(addsuffix /$(PACKAGE).json, $(LANGUAGES)))

Expand Down Expand Up @@ -420,9 +421,12 @@ $(OUTPUT_DIR)/build.css: $(LESS_FILES) .build/node_modules.timestamp
mkdir -p $(dir $@)
./node_modules/.bin/lessc $(PACKAGE)/static/less/$(PACKAGE).less $@

.build/build.js: build.json $(OL_JS_FILES) $(NGEO_JS_FILES) $(APP_JS_FILES) .build/externs/angular-1.3.js .build/externs/angular-1.3-q.js .build/externs/angular-1.3-http-promise.js .build/externs/jquery-1.9.js .build/node_modules.timestamp
.build/build.js: build.json $(OL_JS_FILES) $(NGEO_JS_FILES) $(APP_JS_FILES) .build/templatecache.js .build/externs/angular-1.3.js .build/externs/angular-1.3-q.js .build/externs/angular-1.3-http-promise.js .build/externs/jquery-1.9.js .build/node_modules.timestamp
node tasks/build.js $< $@

.build/templatecache.js: templatecache.mako.js
.build/venv/bin/mako-render --var "partials=$(APP_PARTIALS_FILES)" $< > $@

.build/externs/angular-1.3.js:
mkdir -p $(dir $@)
wget -O $@ https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/angular-1.3.js
Expand Down
3 changes: 2 additions & 1 deletion build.json
Expand Up @@ -4,7 +4,8 @@
"node_modules/openlayers/src/**/*.js",
"node_modules/openlayers/build/ol.ext/**/*.js",
"node_modules/ngeo/src/**/*.js",
"geoportailv3/static/js/**/*.js"
"geoportailv3/static/js/**/*.js",
".build/templatecache.js"
],
"compile": {
"closure_entry_point": "app_main",
Expand Down
12 changes: 11 additions & 1 deletion geoportailv3/templates/index.html
Expand Up @@ -190,15 +190,25 @@ <h2 translate>infos</h2>
appModule.constant('internalWmsUrl', "${request.route_url('wms') })}");
appModule.constant('defaultExtent', [425152.9429259216, 6324465.99999133, 914349.9239510496, 6507914.867875754]);

% if debug:
appModule.value('ngeoLayertreeTemplateUrl', '${request.static_url('geoportailv3:static/js/catalog/layertree.html')}');
appModule.value('ngeoLayertreenodeTemplateUrl', '${request.static_url('geoportailv3:static/js/catalog/layertreenode.html')}');
appModule.value('ngeoPopupTemplateUrl', '${request.static_url('geoportailv3:static/js/layerinfo/popup.html')}');

appModule.value('appBackgroundlayerTemplateUrl', '${request.static_url('geoportailv3:static/js/backgroundlayer/backgroundlayer.html')}');
appModule.value('appLayermanagerTemplateUrl', '${request.static_url('geoportailv3:static/js/layermanager/layermanager.html')}');
appModule.value('appMeasureTemplateUrl', '${request.static_url('geoportailv3:static/js/measure/measure.html')}');
appModule.value('appLayerinfoTemplateUrl', '${request.static_url('geoportailv3:static/js/layerinfo/layerinfo.html')}');
appModule.value('appAuthenticationTemplateUrl', '${request.static_url('geoportailv3:static/js/authentication/authentication.html')}');
% else:
appModule.value('ngeoLayertreeTemplateUrl', 'catalog/layertree.html');
appModule.value('ngeoLayertreenodeTemplateUrl', 'catalog/layertreenode.html');
appModule.value('ngeoPopupTemplateUrl', 'layerinfo/popup.html');
appModule.value('appBackgroundlayerTemplateUrl', 'backgroundlayer/backgroundlayer.html');
appModule.value('appLayermanagerTemplateUrl', 'layermanager/layermanager.html');
appModule.value('appMeasureTemplateUrl', 'measure/measure.html');
appModule.value('appLayerinfoTemplateUrl', 'layerinfo/layerinfo.html');
appModule.value('appAuthenticationTemplateUrl', 'authentication/authentication.html');
% endif
})();
</script>
</body>
Expand Down
43 changes: 43 additions & 0 deletions templatecache.mako.js
@@ -0,0 +1,43 @@
## -*- coding: utf-8 -*-
<%doc>
This is a Mako template that generates Angular code putting the contents of
HTML partials into Angular's $templateCache. The generated code is then built
with the rest of JavaScript code. The generated script is not used at all in
development mode, where HTML partials are loaded through Ajax.
</%doc>
<%
import re
import os
_partials = {}
for partial in partials.split(' '):
f = file(partial)
content = unicode(f.read().decode('utf8'))
content = re.sub(r'>\s*<' , '><', content)
content = re.sub(r'\s\s+', ' ', content)
content = re.sub(r'\n', '', content)
content = re.sub(r"'", "\\'", content)
dirname, filename = os.path.split(partial)
subdirname = os.path.basename(dirname.rstrip(os.sep))
_partials[os.path.join(subdirname, filename)] = content
%>\
/**
* @fileoverview Directive templates cache.
*
* GENERATED FILE. DO NOT EDIT.
*/

goog.require('app');

(function() {
/**
* @param {angular.$cacheFactory.Cache} $templateCache
* @ngInject
*/
var runner = function($templateCache) {
% for partial in _partials:
$templateCache.put('${partial}', '${_partials[partial]}');
%endfor
};

app.module.run(runner);
})();\

0 comments on commit 1c89b34

Please sign in to comment.