From 5fd7c99d7aa67d1c89682adb952b9d7a6a757eb7 Mon Sep 17 00:00:00 2001 From: Mark Lagendijk Date: Mon, 29 Dec 2014 12:06:12 +0100 Subject: [PATCH] Version 1.2.1 - Allow defining 'parent' as string - Some cleanup --- bower.json | 2 +- gulpfile.js | 8 ++-- statehelper.js | 2 +- statehelper.min.js | 2 +- test/statehelperSpec.js | 86 ++++++++++++++++++++--------------------- 5 files changed, 51 insertions(+), 49 deletions(-) diff --git a/bower.json b/bower.json index a57018c..ca2800c 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "angular-ui-router.stateHelper", "main": "statehelper.js", - "version": "1.2.0", + "version": "1.2.1", "homepage": "https://github.com/marklagendijk/ui-router.stateHelper", "authors": [ "Mark Lagendijk " diff --git a/gulpfile.js b/gulpfile.js index f309289..daee063 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -7,7 +7,7 @@ var karma = require("gulp-karma"); var config = require('./config/config.js'); gulp.task("test", ["minify"], function(){ - gulp.src(config.testFiles) + return gulp.src(config.testFiles) .pipe(karma({ configFile: 'config/karma.conf.js', action: 'run' @@ -15,9 +15,11 @@ gulp.task("test", ["minify"], function(){ }); gulp.task("minify", function(){ - gulp.src("statehelper.js") + return gulp.src("statehelper.js") .pipe(ngmin()) .pipe(uglify()) .pipe(rename("statehelper.min.js")) .pipe(gulp.dest("./")); -}); \ No newline at end of file +}); + +gulp.task("default", ["minify", "test"]); \ No newline at end of file diff --git a/statehelper.js b/statehelper.js index 7a59575..3f9c246 100644 --- a/statehelper.js +++ b/statehelper.js @@ -28,7 +28,7 @@ angular.module('ui.router.stateHelper', [ 'ui.router' ]) if(state.children && state.children.length){ state.children.forEach(function(childState){ childState.parent = state; - self.setNestedState(childState, keepOriginalNames); + self.state(childState, keepOriginalNames); }); } diff --git a/statehelper.min.js b/statehelper.min.js index 8fa7fa2..84a70a9 100644 --- a/statehelper.min.js +++ b/statehelper.min.js @@ -1 +1 @@ -angular.module("ui.router.stateHelper",["ui.router"]).provider("stateHelper",["$stateProvider",function(t){function e(t){t.parent&&(t.name=t.parent.name+"."+t.name)}var n=this;this.state=function(r,a){return a||e(r),t.state(r),r.children&&r.children.length&&r.children.forEach(function(t){t.parent=r,n.setNestedState(t,a)}),n},this.setNestedState=this.state,n.$get=angular.noop}]); \ No newline at end of file +angular.module("ui.router.stateHelper",["ui.router"]).provider("stateHelper",["$stateProvider",function(t){function e(t){t.parent&&(t.name=(angular.isObject(t.parent)?t.parent.name:t.parent)+"."+t.name)}var n=this;this.state=function(r,a){return a||e(r),t.state(r),r.children&&r.children.length&&r.children.forEach(function(t){t.parent=r,n.state(t,a)}),n},this.setNestedState=this.state,n.$get=angular.noop}]); \ No newline at end of file diff --git a/test/statehelperSpec.js b/test/statehelperSpec.js index 791d665..a393925 100644 --- a/test/statehelperSpec.js +++ b/test/statehelperSpec.js @@ -1,35 +1,35 @@ /* globals: beforeEach, describe, it, module, inject, expect */ describe('ui-router.stateHelper', function(){ - var stateHelperProvider, $stateProvider, rootState, expectedState; + var stateHelperProvider, $stateProvider, rootState, expectedState; - beforeEach(module('ui.router.stateHelper', function(_stateHelperProvider_, _$stateProvider_){ + beforeEach(module('ui.router.stateHelper', function(_stateHelperProvider_, _$stateProvider_){ stateHelperProvider = _stateHelperProvider_; - $stateProvider = _$stateProvider_; - })); - - beforeEach(inject(function(){ - rootState = { - name: 'root', - children: [ - { - name: 'login', - templateUrl: '/partials/views/login.html' - }, - { - name: 'backup', - children: [ - { - name: 'dashboard' - } - ] - } - ] - }; - - spyOn($stateProvider, 'state'); - })); - - describe('.state', function(){ + $stateProvider = _$stateProvider_; + })); + + beforeEach(inject(function(){ + rootState = { + name: 'root', + children: [ + { + name: 'login', + templateUrl: '/partials/views/login.html' + }, + { + name: 'backup', + children: [ + { + name: 'dashboard' + } + ] + } + ] + }; + + spyOn($stateProvider, 'state'); + })); + + describe('.state', function(){ beforeEach(inject(function(){ expectedState = { name: 'root', @@ -52,26 +52,26 @@ describe('ui-router.stateHelper', function(){ stateHelperProvider.state(rootState); })); - it('should set each state', function(){ - expect($stateProvider.state.callCount).toBe(4); - }); + it('should set each state', function(){ + expect($stateProvider.state.callCount).toBe(4); + }); - it('should convert names to dot notation, set parent references', function(){ - // Since the states are objects which contain references to each other, we are testing the eventual - // root state object (and not the root state object as it is passed to $stateProvider.$state). - // Because of this we have to test everything at once + it('should convert names to dot notation, set parent references', function(){ + // Since the states are objects which contain references to each other, we are testing the eventual + // root state object (and not the root state object as it is passed to $stateProvider.$state). + // Because of this we have to test everything at once - expectedState.children[0].parent = expectedState; - expectedState.children[1].parent = expectedState; - expectedState.children[1].children[0].parent = expectedState.children[1]; + expectedState.children[0].parent = expectedState; + expectedState.children[1].parent = expectedState; + expectedState.children[1].children[0].parent = expectedState.children[1]; - expect($stateProvider.state.argsForCall[0][0]).toEqual(expectedState); - }); + expect($stateProvider.state.argsForCall[0][0]).toEqual(expectedState); + }); it('should return itself to support chaining', function(){ - expect($stateProvider.state(rootState)).toBe($stateProvider); - }) - }); + expect(stateHelperProvider.state(rootState)).toBe(stateHelperProvider); + }); + }); describe('.state with keepOriginalNames set to true', function(){ beforeEach(inject(function(){