diff --git a/.travis.yml b/.travis.yml index 808889cb6..50550918b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,10 @@ cache: python: - "3.4" - "3.5" +env: + - TRAVIS_NODE_VERSION="4" +before_install: + - "nvm install $TRAVIS_NODE_VERSION" install: - "pip install --upgrade setuptools" - "pip install --upgrade --requirement requirements.txt" diff --git a/DEVELOPMENT.rst b/DEVELOPMENT.rst index 0e2358029..97628c1fe 100644 --- a/DEVELOPMENT.rst +++ b/DEVELOPMENT.rst @@ -74,6 +74,10 @@ avoid opening new browser windows:: $ python manage.py runserver +Use gulp watch in a second command-line interface:: + + $ node_modules/.bin/gulp watch + 2. Installation on Windows -------------------------- diff --git a/gulpfile.js b/gulpfile.js index 2ba192360..97f513d6c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -26,6 +26,8 @@ var argv = require('yargs').argv, mainBowerFiles = require('main-bower-files'), path = require('path'), rename = require('gulp-rename'), + sourcemaps = require('gulp-sourcemaps'), + templateCache = require('gulp-angular-templatecache'), through = require('through2'), uglify = require('gulp-uglify'), vsprintf = require('sprintf-js').vsprintf; @@ -38,13 +40,44 @@ var output_directory = path.join('openslides', 'static'); * Default tasks to be run before start. */ +// Catches all JavaScript files from all core apps and concats them to one +// file js/openslides.js. In production mode the file is uglified. +gulp.task('js', function () { + return gulp.src(path.join('openslides', '*', 'static', 'js', '**', '*.js')) + .pipe(sourcemaps.init()) + .pipe(concat('openslides.js')) + .pipe(sourcemaps.write()) + .pipe(gulpif(argv.production, uglify())) + .pipe(gulp.dest(path.join(output_directory, 'js'))); +}); + // Catches all JavaScript files from all bower components and concats them to // one file js/openslides-libs.js. In production mode the file is uglified. gulp.task('js-libs', function () { return gulp.src(mainBowerFiles({ filter: /\.js$/ })) + .pipe(sourcemaps.init()) .pipe(concat('openslides-libs.js')) + .pipe(sourcemaps.write()) + .pipe(gulpif(argv.production, uglify())) + .pipe(gulp.dest(path.join(output_directory, 'js'))); +}); + +// Catches all template files from all core apps and concats them to one +// file js/openslides-templates.js. In production mode the file is uglified. +gulp.task('templates', function () { + return gulp.src(path.join('openslides', '*', 'static', 'templates', '**', '*.html')) + .pipe(templateCache('openslides-templates.js', { + module: 'OpenSlidesApp-templates', + standalone: true, + moduleSystem: 'IIFE', + transformUrl: function (url) { + var pathList = url.split(path.sep); + pathList.shift(); + return pathList.join(path.sep); + }, + })) .pipe(gulpif(argv.production, uglify())) .pipe(gulp.dest(path.join(output_directory, 'js'))); }); @@ -117,13 +150,19 @@ gulp.task('translations', function () { }); // Gulp default task. Runs all other tasks before. -gulp.task('default', ['js-libs', 'css-libs', 'fonts-libs', 'tinymce', 'angular-chosen-img', 'translations'], function () {}); +gulp.task('default', ['js', 'js-libs', 'templates', 'css-libs', 'fonts-libs', 'tinymce', 'angular-chosen-img', 'translations'], function () {}); /** * Extra tasks that have to be called manually. Useful for development. */ +// Watches changes in JavaScript and templates. +gulp.task('watch', ['js', 'templates'], function () { + gulp.watch(path.join('openslides', '*', 'static', 'js', '**', '*.js'), ['js']); + gulp.watch(path.join('openslides', '*', 'static', 'templates', '**', '*.html'), ['templates']); +}); + // Extracts translatable strings using angular-gettext and saves them in file // openslides/locale/angular-gettext/template-en.pot. gulp.task('pot', function () { diff --git a/openslides/agenda/apps.py b/openslides/agenda/apps.py index 3afd71758..81e71f295 100644 --- a/openslides/agenda/apps.py +++ b/openslides/agenda/apps.py @@ -6,7 +6,6 @@ class AgendaAppConfig(AppConfig): verbose_name = 'OpenSlides Agenda' angular_site_module = True angular_projector_module = True - js_files = ['js/agenda/base.js', 'js/agenda/site.js', 'js/agenda/projector.js'] def ready(self): # Load projector elements. diff --git a/openslides/assignments/apps.py b/openslides/assignments/apps.py index b58449ede..6ce05de3a 100644 --- a/openslides/assignments/apps.py +++ b/openslides/assignments/apps.py @@ -6,7 +6,6 @@ class AssignmentsAppConfig(AppConfig): verbose_name = 'OpenSlides Assignments' angular_site_module = True angular_projector_module = True - js_files = ['js/assignments/base.js', 'js/assignments/site.js', 'js/assignments/projector.js'] def ready(self): # Load projector elements. diff --git a/openslides/core/apps.py b/openslides/core/apps.py index 2f30af10a..d6a0987c8 100644 --- a/openslides/core/apps.py +++ b/openslides/core/apps.py @@ -6,7 +6,6 @@ class CoreAppConfig(AppConfig): verbose_name = 'OpenSlides Core' angular_site_module = True angular_projector_module = True - js_files = ['js/core/base.js', 'js/core/site.js', 'js/core/projector.js'] def ready(self): # Load projector elements. diff --git a/openslides/core/static/js/core/base.js b/openslides/core/static/js/core/base.js index 4b3a34c44..8a0885c5d 100644 --- a/openslides/core/static/js/core/base.js +++ b/openslides/core/static/js/core/base.js @@ -10,7 +10,8 @@ angular.module('OpenSlidesApp.core', [ 'ngSanitize', // TODO: only use this in functions that need it. 'ui.bootstrap', 'ui.tree', - 'pdf' + 'pdf', + 'OpenSlidesApp-templates', ]) .config([ diff --git a/openslides/core/static/js/core/site.js b/openslides/core/static/js/core/site.js index 7fdf2cb34..ab6c379c1 100644 --- a/openslides/core/static/js/core/site.js +++ b/openslides/core/static/js/core/site.js @@ -869,7 +869,7 @@ angular.module('OpenSlidesApp.core.site', [ return { restrict: 'E', scope: true, - templateUrl: '/static/templates/config-form-field.html', + templateUrl: 'static/templates/config-form-field.html', link: function ($scope, iElement, iAttrs, controller, transcludeFn) { var field = $parse(iAttrs.field)($scope); var config = Config.get(field.key); diff --git a/openslides/core/static/templates/index.html b/openslides/core/static/templates/index.html index 3115a5b0b..c162ff0ad 100644 --- a/openslides/core/static/templates/index.html +++ b/openslides/core/static/templates/index.html @@ -10,6 +10,8 @@ + +
@@ -199,5 +201,4 @@
- - + diff --git a/openslides/core/static/templates/projector-container.html b/openslides/core/static/templates/projector-container.html index 175901169..62e904561 100644 --- a/openslides/core/static/templates/projector-container.html +++ b/openslides/core/static/templates/projector-container.html @@ -9,6 +9,8 @@ + +
@@ -42,4 +44,4 @@
- + diff --git a/openslides/core/static/templates/projector.html b/openslides/core/static/templates/projector.html index c58bf49e0..12aa50275 100644 --- a/openslides/core/static/templates/projector.html +++ b/openslides/core/static/templates/projector.html @@ -8,6 +8,8 @@ + +