Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

style javascript code #305

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
'use strict';

// Declare app level module which depends on views, and components
angular.module('myApp', [
'ngRoute',
'myApp.view1',
'myApp.view2',
'myApp.version'
]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.otherwise({redirectTo: '/view1'});
}]);
(function() {

'use strict';

// Declare app level module which depends on views, and components
angular
.module('myApp', [
'ngRoute',
'myApp.view1',
'myApp.view2',
'myApp.version'
])
.config(Config);

Config.$inject = ['$routeProvider'];

function Config($routeProvider) {
$routeProvider
.otherwise({
redirectTo: '/view1'
});
}

})();
22 changes: 15 additions & 7 deletions app/components/version/interpolate-filter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
'use strict';
(function() {

angular.module('myApp.version.interpolate-filter', [])
'use strict';

.filter('interpolate', ['version', function(version) {
return function(text) {
return String(text).replace(/\%VERSION\%/mg, version);
};
}]);
angular
.module('myApp.version.interpolate-filter', [])
.filter('interpolate', Interpolate);

Interpolate.$inject = ['version'];

function Interpolate(version) {
return function(text) {
return String(text).replace(/\%VERSION\%/mg, version);
};
}

})();
4 changes: 2 additions & 2 deletions app/components/version/interpolate-filter_test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

describe('myApp.version module', function() {
describe('module: myApp.version', function() {
beforeEach(module('myApp.version'));

describe('interpolate filter', function() {
describe('filter: interpolate', function() {
beforeEach(module(function($provide) {
$provide.value('version', 'TEST_VER');
}));
Expand Down
24 changes: 17 additions & 7 deletions app/components/version/version-directive.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
'use strict';
(function() {
'use strict';

angular.module('myApp.version.version-directive', [])
angular
.module('myApp.version.version-directive', [])
.directive('appVersion', AppVersion);

.directive('appVersion', ['version', function(version) {
return function(scope, elm, attrs) {
elm.text(version);
};
}]);
AppVersion.$inject = ['version'];

function AppVersion(version) {
return {
link: link
};

function link(scope, element, attrs) {
element.text(version);
}
}
})();
15 changes: 9 additions & 6 deletions app/components/version/version.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict';
(function() {
'use strict';

angular.module('myApp.version', [
'myApp.version.interpolate-filter',
'myApp.version.version-directive'
])
angular
.module('myApp.version', [
'myApp.version.interpolate-filter',
'myApp.version.version-directive'
])
.value('version', '0.1');

.value('version', '0.1');
})();
31 changes: 21 additions & 10 deletions app/view1/view1.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
'use strict';
(function() {

angular.module('myApp.view1', ['ngRoute'])
'use strict';

.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl'
});
}])
angular
.module('myApp.view1', [
'ngRoute'
])
.config(Config)
.controller('View1Ctrl', View1Ctrl);

.controller('View1Ctrl', [function() {
Config.$inject = ['$routeProvider'];

}]);
function Config($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl'
});
}

function View1Ctrl() {

}

})();
15 changes: 8 additions & 7 deletions app/view1/view1_test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'use strict';

describe('myApp.view1 module', function() {

describe('module: myApp.view1', function() {
beforeEach(module('myApp.view1'));

describe('view1 controller', function(){
describe('controller: View1Ctrl', function() {
var ctrl;

it('should ....', inject(function($controller) {
//spec body
var view1Ctrl = $controller('View1Ctrl');
expect(view1Ctrl).toBeDefined();
beforeEach(inject(function($controller) {
ctrl = $controller('View1Ctrl');
}));

it('should be defined', function() {
expect(ctrl).toBeDefined();
});
});
});
32 changes: 22 additions & 10 deletions app/view2/view2.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
'use strict';

angular.module('myApp.view2', ['ngRoute'])
(function() {
"use strict";

.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view2', {
templateUrl: 'view2/view2.html',
controller: 'View2Ctrl'
});
}])
angular
.module('myApp.view2', [
'ngRoute'
])
.config(Config)
.controller('View2Ctrl', View2Ctrl);

.controller('View2Ctrl', [function() {
Config.$inject = ['$routeProvider'];

}]);
function Config($routeProvider) {
$routeProvider
.when('/view2', {
templateUrl: 'view2/view2.html',
controller: 'View2Ctrl'
});
}

function View2Ctrl() {

}

})();
21 changes: 11 additions & 10 deletions app/view2/view2_test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
'use strict';

describe('myApp.view2 module', function() {
describe('module: myApp.view2', function() {
beforeEach(module('myApp.view2'));

beforeEach(module('myApp.view2'));
describe('controller: View2Ctrl', function() {
var ctrl;

describe('view2 controller', function(){
beforeEach(inject(function($controller) {
ctrl = $controller('View2Ctrl');
}));

it('should ....', inject(function($controller) {
//spec body
var view2Ctrl = $controller('View2Ctrl');
expect(view2Ctrl).toBeDefined();
}));

});
it('should be defined', function() {
expect(ctrl).toBeDefined();
});
});
});
49 changes: 25 additions & 24 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
module.exports = function(config){
config.set({
module.exports = function (config) {
config.set({

basePath : './',
basePath: './',

files : [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/components/**/*.js',
'app/view*/**/*.js'
],
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/components/**/*.js',
'app/view*/**/*.js'
],

autoWatch : true,
autoWatch: true,

frameworks: ['jasmine'],
frameworks: ['jasmine'],

browsers : ['Chrome'],
browsers: ['PhantomJS'],

plugins : [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine',
'karma-junit-reporter'
],
plugins: [
'karma-phantomjs-launcher',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine',
'karma-junit-reporter'
],

junitReporter : {
outputFile: 'test_out/unit.xml',
suite: 'unit'
}
junitReporter: {
outputFile: 'test_out/unit.xml',
suite: 'unit'
}

});
});
};
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,34 @@
"license": "MIT",
"devDependencies": {
"bower": "^1.3.1",
"cz-conventional-changelog": "^1.1.4",
"http-server": "^0.6.1",
"jasmine-core": "^2.3.4",
"karma": "~0.12",
"karma-chrome-launcher": "^0.1.12",
"karma-firefox-launcher": "^0.1.6",
"karma-jasmine": "^0.3.5",
"karma-junit-reporter": "^0.2.2",
"karma-phantomjs-launcher": "^0.2.1",
"protractor": "^2.1.0",
"shelljs": "^0.2.6"
},
"scripts": {
"postinstall": "bower install",

"prestart": "npm install",
"start": "http-server -a localhost -p 8000 -c-1",

"pretest": "npm install",
"test": "karma start karma.conf.js",
"test-single-run": "karma start karma.conf.js --single-run",

"preupdate-webdriver": "npm install",
"update-webdriver": "webdriver-manager update",

"preprotractor": "npm run update-webdriver",
"protractor": "protractor e2e-tests/protractor.conf.js",

"update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + sed(/sourceMappingURL=angular-loader.min.js.map/,'sourceMappingURL=bower_components/angular-loader/angular-loader.min.js.map','app/bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\""
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}