Skip to content

Commit 1ffa6f7

Browse files
authored
Merge pull request #1274 from JoelParke/master
feat(main, testAngular.spec): Added a new directive text-angular-version
2 parents 454030f + 974a701 commit 1ffa6f7

5 files changed

+52
-5
lines changed

Gruntfile.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,21 @@ module.exports = function (grunt) {
2121
grunt.registerTask('test', ['clean:coverage', 'jshint', 'karma', 'coverage']);
2222
grunt.registerTask('travis-test', ['concat', 'umd', 'copy:setupFiles', 'jshint', 'karma', 'coverage', 'coveralls']);
2323

24-
grunt.registerTask('release', ['bump-only','compile', 'demo_pages', 'changelog','gitcommit','bump-commit', 'shell:publish']);
25-
grunt.registerTask('release:patch', ['bump-only:patch','compile','changelog','gitcommit','bump-commit', 'shell:publish']);
26-
grunt.registerTask('release:minor', ['bump-only:minor','compile','changelog','gitcommit','bump-commit', 'shell:publish']);
27-
grunt.registerTask('release:major', ['bump-only:major','compile','changelog','gitcommit','bump-commit', 'shell:publish']);
28-
grunt.registerTask('release:prerelease', ['bump-only:prerelease','compile','changelog','gitcommit','bump-commit', 'shell:publish']);
24+
grunt.registerTask('release', ['bump-only', 'setVersion', 'compile', 'demo_pages', 'changelog','gitcommit','bump-commit', 'shell:publish']);
25+
grunt.registerTask('release:patch', ['bump-only:patch','setVersion','compile','changelog','gitcommit','bump-commit', 'shell:publish']);
26+
grunt.registerTask('release:minor', ['bump-only:minor','setVersion','compile','changelog','gitcommit','bump-commit', 'shell:publish']);
27+
grunt.registerTask('release:major', ['bump-only:major','setVersion','compile','changelog','gitcommit','bump-commit', 'shell:publish']);
28+
grunt.registerTask('release:prerelease', ['bump-only:prerelease','setVersion','compile','changelog','gitcommit','bump-commit', 'shell:publish']);
29+
30+
grunt.registerTask('setVersion', function () {
31+
var pkgJson = require('./package.json');
32+
var version = pkgJson.version;
33+
//grunt.log.writeln('textAngular version:'+version);
34+
var contents = grunt.file.read('./src/globals.js');
35+
contents = contents.replace(/textAngularVersion = 'v\d+.\d+.\d+'/i, "textAngularVersion = 'v"+version+"'");
36+
grunt.file.write('./src/globals.js', contents);
37+
console.log('Updated src/globals.js to textAngular version: v'+version);
38+
});
2939

3040
var testConfig = function (configFile, customOptions) {
3141
var options = { configFile: configFile, keepalive: true };

src/globals.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// NOTE: textAngularVersion must match the Gruntfile.js 'setVersion' task.... and have format v/d+./d+./d+
2+
var textAngularVersion = 'v1.5.5'; // This is automatically updated during the build process to the current release!
3+
14

25
// IE version detection - http://stackoverflow.com/questions/4169160/javascript-ie-detection-why-not-use-simple-conditional-comments
36
// We need this as IE sometimes plays funny tricks with the contenteditable.

src/main.js

+13
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,8 @@ textAngular.service('textAngularManager', ['taToolExecuteAction', 'taTools', 'ta
929929
// the inital state is correct.
930930
//
931931
updateStyles: updateStyles,
932+
// return the current version of textAngular in use to the user
933+
getVersion: function () { return textAngularVersion; },
932934
// for testing
933935
getToolbarScopes: function () { return toolbarScopes; }
934936
};
@@ -1115,3 +1117,14 @@ textAngular.directive('textAngularToolbar', [
11151117
};
11161118
}
11171119
]);
1120+
textAngular.directive('textAngularVersion', ['textAngularManager',
1121+
function(textAngularManager) {
1122+
var version = textAngularManager.getVersion();
1123+
return {
1124+
restrict: "EA",
1125+
link: function (scope, element, attrs) {
1126+
element.html(version);
1127+
}
1128+
};
1129+
}
1130+
]);

test/textAngular.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -1280,4 +1280,19 @@ describe('textAngular', function(){
12801280
expect($rootScope.html).toBe('<p><b>Changed Content</b></p>');
12811281
}));
12821282
});
1283+
1284+
describe('textAngularVersion directive', function(){
1285+
beforeEach(inject(function(_textAngularManager_){
1286+
textAngularManager = _textAngularManager_;
1287+
}));
1288+
it('functions', inject(function($window, _$rootScope_, $compile, $document, $timeout){
1289+
$rootScope = _$rootScope_;
1290+
var version = textAngularManager.getVersion();
1291+
element = $compile('<div text-angular-version></div>')($rootScope);
1292+
$rootScope.$digest();
1293+
var html = element[0].outerHTML;
1294+
expect(html).toBe('<div text-angular-version="" class="ng-scope">'+version+'</div>');
1295+
}));
1296+
});
1297+
12831298
});

test/textAngularManager.spec.js

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ describe('textAngularManager', function(){
22
'use strict';
33
beforeEach(module('textAngular'));
44

5+
describe('getVersion', function(){
6+
it('should return a valid version in the correct format!', inject(function(textAngularManager){
7+
expect(/v\d+.\d+.\d+/i.test(textAngularManager.getVersion())).toBe(true);
8+
}));
9+
});
10+
511
describe('toolbar', function(){
612
describe('registration', function(){
713
it('should require a scope object', inject(function(textAngularManager){

0 commit comments

Comments
 (0)