From 1c89b341f22e75916e0f06d00bd2add2328aa418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Mon, 2 Mar 2015 12:04:02 +0100 Subject: [PATCH] Add directive partials to build.js --- CONST_Makefile | 6 ++++- build.json | 3 ++- geoportailv3/templates/index.html | 12 ++++++++- templatecache.mako.js | 43 +++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 templatecache.mako.js diff --git a/CONST_Makefile b/CONST_Makefile index ac082e554..11ed9ef1d 100644 --- a/CONST_Makefile +++ b/CONST_Makefile @@ -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))) @@ -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 diff --git a/build.json b/build.json index 49c2d2ed5..c16cc0192 100644 --- a/build.json +++ b/build.json @@ -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", diff --git a/geoportailv3/templates/index.html b/geoportailv3/templates/index.html index 05f0a9cd1..160f9d625 100644 --- a/geoportailv3/templates/index.html +++ b/geoportailv3/templates/index.html @@ -190,15 +190,25 @@

infos

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 })(); diff --git a/templatecache.mako.js b/templatecache.mako.js new file mode 100644 index 000000000..204432335 --- /dev/null +++ b/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. + +<% + 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); +})();\