Skip to content

Commit

Permalink
Merge pull request #1274 from JoelParke/master
Browse files Browse the repository at this point in the history
feat(main, testAngular.spec): Added a new directive text-angular-version
  • Loading branch information
JoelParke authored Aug 17, 2016
2 parents 454030f + 974a701 commit 1ffa6f7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
3 changes: 3 additions & 0 deletions src/globals.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};
Expand Down Expand Up @@ -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);
}
};
}
]);
15 changes: 15 additions & 0 deletions test/textAngular.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1280,4 +1280,19 @@ describe('textAngular', function(){
expect($rootScope.html).toBe('<p><b>Changed Content</b></p>');
}));
});

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('<div text-angular-version></div>')($rootScope);
$rootScope.$digest();
var html = element[0].outerHTML;
expect(html).toBe('<div text-angular-version="" class="ng-scope">'+version+'</div>');
}));
});

});
6 changes: 6 additions & 0 deletions test/textAngularManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit 1ffa6f7

Please sign in to comment.