diff --git a/Gruntfile.js b/Gruntfile.js index c68931d8..e964c24e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -21,11 +21,21 @@ module.exports = function (grunt) { grunt.registerTask('test', ['clean:coverage', 'jshint', 'karma', 'coverage']); grunt.registerTask('travis-test', ['concat', 'umd', 'copy:setupFiles', 'jshint', 'karma', 'coverage', 'coveralls']); - grunt.registerTask('release', ['bump-only','compile', 'demo_pages', 'changelog','gitcommit','bump-commit', 'shell:publish']); - grunt.registerTask('release:patch', ['bump-only:patch','compile','changelog','gitcommit','bump-commit', 'shell:publish']); - grunt.registerTask('release:minor', ['bump-only:minor','compile','changelog','gitcommit','bump-commit', 'shell:publish']); - grunt.registerTask('release:major', ['bump-only:major','compile','changelog','gitcommit','bump-commit', 'shell:publish']); - grunt.registerTask('release:prerelease', ['bump-only:prerelease','compile','changelog','gitcommit','bump-commit', 'shell:publish']); + grunt.registerTask('release', ['bump-only', 'setVersion', 'compile', 'demo_pages', 'changelog','gitcommit','bump-commit', 'shell:publish']); + grunt.registerTask('release:patch', ['bump-only:patch','setVersion','compile','changelog','gitcommit','bump-commit', 'shell:publish']); + grunt.registerTask('release:minor', ['bump-only:minor','setVersion','compile','changelog','gitcommit','bump-commit', 'shell:publish']); + grunt.registerTask('release:major', ['bump-only:major','setVersion','compile','changelog','gitcommit','bump-commit', 'shell:publish']); + grunt.registerTask('release:prerelease', ['bump-only:prerelease','setVersion','compile','changelog','gitcommit','bump-commit', 'shell:publish']); + + grunt.registerTask('setVersion', function () { + var pkgJson = require('./package.json'); + var version = pkgJson.version; + //grunt.log.writeln('textAngular version:'+version); + var contents = grunt.file.read('./src/globals.js'); + contents = contents.replace(/textAngularVersion = 'v\d+.\d+.\d+'/i, "textAngularVersion = 'v"+version+"'"); + grunt.file.write('./src/globals.js', contents); + console.log('Updated src/globals.js to textAngular version: v'+version); + }); var testConfig = function (configFile, customOptions) { var options = { configFile: configFile, keepalive: true }; diff --git a/src/globals.js b/src/globals.js index 78f13c69..956d0243 100644 --- a/src/globals.js +++ b/src/globals.js @@ -1,3 +1,6 @@ +// NOTE: textAngularVersion must match the Gruntfile.js 'setVersion' task.... and have format v/d+./d+./d+ +var textAngularVersion = 'v1.5.5'; // This is automatically updated during the build process to the current release! + // IE version detection - http://stackoverflow.com/questions/4169160/javascript-ie-detection-why-not-use-simple-conditional-comments // We need this as IE sometimes plays funny tricks with the contenteditable. diff --git a/src/main.js b/src/main.js index 7c38a813..763162a5 100644 --- a/src/main.js +++ b/src/main.js @@ -929,6 +929,8 @@ textAngular.service('textAngularManager', ['taToolExecuteAction', 'taTools', 'ta // the inital state is correct. // updateStyles: updateStyles, + // return the current version of textAngular in use to the user + getVersion: function () { return textAngularVersion; }, // for testing getToolbarScopes: function () { return toolbarScopes; } }; @@ -1115,3 +1117,14 @@ textAngular.directive('textAngularToolbar', [ }; } ]); +textAngular.directive('textAngularVersion', ['textAngularManager', + function(textAngularManager) { + var version = textAngularManager.getVersion(); + return { + restrict: "EA", + link: function (scope, element, attrs) { + element.html(version); + } + }; + } +]); diff --git a/test/textAngular.spec.js b/test/textAngular.spec.js index 1edb96e0..ecdf5890 100644 --- a/test/textAngular.spec.js +++ b/test/textAngular.spec.js @@ -1280,4 +1280,19 @@ describe('textAngular', function(){ expect($rootScope.html).toBe('

Changed Content

'); })); }); + + describe('textAngularVersion directive', function(){ + beforeEach(inject(function(_textAngularManager_){ + textAngularManager = _textAngularManager_; + })); + it('functions', inject(function($window, _$rootScope_, $compile, $document, $timeout){ + $rootScope = _$rootScope_; + var version = textAngularManager.getVersion(); + element = $compile('
')($rootScope); + $rootScope.$digest(); + var html = element[0].outerHTML; + expect(html).toBe('
'+version+'
'); + })); + }); + }); diff --git a/test/textAngularManager.spec.js b/test/textAngularManager.spec.js index 83ec0023..2840df9f 100644 --- a/test/textAngularManager.spec.js +++ b/test/textAngularManager.spec.js @@ -2,6 +2,12 @@ describe('textAngularManager', function(){ 'use strict'; beforeEach(module('textAngular')); + describe('getVersion', function(){ + it('should return a valid version in the correct format!', inject(function(textAngularManager){ + expect(/v\d+.\d+.\d+/i.test(textAngularManager.getVersion())).toBe(true); + })); + }); + describe('toolbar', function(){ describe('registration', function(){ it('should require a scope object', inject(function(textAngularManager){