Skip to content

Commit

Permalink
Merge branch 'develop' into feature/incompatible-browser-warnings
Browse files Browse the repository at this point in the history
Conflicts:
	app/index.html
  • Loading branch information
edoparearyee committed Mar 27, 2015
2 parents 0e85ee0 + 3341b21 commit 0e87e31
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@ logs/*
!.gitkeep
node_modules/
app/components/
app/js/config/
dist/
docs/
css/
Expand Down
50 changes: 40 additions & 10 deletions Gruntfile.js
Expand Up @@ -5,13 +5,18 @@ var modRewrite = require("connect-modrewrite");
module.exports = function (grunt) {

var base = grunt.option("base-dir") || "",
env = grunt.option("env") || "development",
protractorConf = grunt.option("ci") ?
"./tests/e2e/protractor.saucelabs.conf.js" :
"./tests/e2e/protractor.conf.js" ;

grunt.initConfig({

pkg: grunt.file.readJSON("package.json"),
pkg: grunt.file.readJSON("./package.json"),

bower: grunt.file.readJSON("./bower.json"),

env: grunt.file.readJSON("./env.json")[env],

config: {
outputDir: "./dist/",
Expand Down Expand Up @@ -127,7 +132,10 @@ module.exports = function (grunt) {
keepRunner: true,
},
development: {
src: ["<%= config.applicationFiles %>"],
src: [
"<%= ngconstant.options.dest %>",
"<%= config.applicationFiles %>"
],
options: {
vendor: ["<%= config.vendorFiles %>"],
helpers:["./app/components/angular-mocks/angular-mocks.js"],
Expand Down Expand Up @@ -183,6 +191,7 @@ module.exports = function (grunt) {
production: {
src: [
"<%= config.vendorFiles %>",
"<%= ngconstant.options.dest %>",
"<%= config.applicationFiles %>"
],
dest: "<%= config.outputDir %>js/app.js"
Expand All @@ -202,6 +211,7 @@ module.exports = function (grunt) {
"<%= config.outputDir %>js/app.min.js":
[
"<%= config.vendorFiles %>",
"<%= ngconstant.options.dest %>",
"<%= config.applicationFiles %>"
]
}
Expand Down Expand Up @@ -238,16 +248,16 @@ module.exports = function (grunt) {

processhtml: {
options: {
strip: true
strip: true,
data: { url: "<%= env.BASE_URL %>" }
},
production: {
files: {
"<%= config.outputDir %>index.html": ["./app/index.html"]
}
files: { "<%= config.outputDir %>index.html": ["./app/index.html"] }
},
e2e: {
files: {
"<%= config.outputDir %>index.html": ["./app/index.html"]
files: { "<%= config.outputDir %>index.html": ["./app/index.html"] },
options: {
data: { url: "http://127.0.0.1:8000/" }
}
}
},
Expand Down Expand Up @@ -277,8 +287,20 @@ module.exports = function (grunt) {
push: true,
pushTo: "origin master"
}
}
},

ngconstant: {
options: {
name: "config",
dest: "./app/js/config/config.js",
constants: {
bower: "<%= bower %>",
pkg: "<%= pkg %>",
env: "<%= env %>"
}
},
dist: {}
}

});

Expand All @@ -295,11 +317,13 @@ module.exports = function (grunt) {
grunt.loadNpmTasks("grunt-protractor-runner");
grunt.loadNpmTasks("grunt-protractor-webdriver");
grunt.loadNpmTasks("grunt-processhtml");
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks("grunt-ng-constant");
grunt.loadNpmTasks("grunt-bump");

grunt.registerTask("build", [
"clean:beforeBuild",
"less:production",
"ngconstant",
"uglify",
"copy",
"processhtml:production"
Expand All @@ -313,38 +337,44 @@ module.exports = function (grunt) {

grunt.registerTask("server", [
"less:development",
"ngconstant",
"connect:server",
"watch:css"
]);

grunt.registerTask("serverjs", [
"less:development",
"ngconstant",
"connect:server",
"watch:javascript"
]);

grunt.registerTask("serverall", [
"less:development",
"ngconstant",
"connect:server",
"watch"
]);

grunt.registerTask("test", [
"clean:beforeBuild",
"ngconstant",
"jshint",
"uglify",
"jasmine:production",
"clean:afterTest"
]);

grunt.registerTask("test:development", [
"ngconstant",
"jshint",
"jasmine:development"
]);

grunt.registerTask("e2e", [
"uglify",
"less:production",
"ngconstant",
"copy",
"processhtml:e2e",
"connect:servertest",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -109,7 +109,7 @@ To run tests or compile less to css when the relevent files are updated.
To create a build to deploy for a production environment simply run:

```
grunt build
grunt build -env production
```

The build files will then be in the `dist/` directory.
Expand Down
6 changes: 5 additions & 1 deletion app/index.html
Expand Up @@ -12,7 +12,7 @@
<title>Angular Start</title>

<!-- build:template
<base href="/">
<base href="<%= url %>">
/build -->
<!-- build:remove -->
<base href="/app/">
Expand All @@ -24,6 +24,7 @@
</head>
<body>

<app-version></app-version>
<ng-view></ng-view>

<!--[if lt IE 8]>
Expand All @@ -43,10 +44,13 @@
<script src="components/angular/angular.js"></script>
<script src="components/angular-route/angular-route.js"></script>

<script src="js/config/config.js"></script>

<script src="js/soon-example/app.js"></script>
<script src="js/soon-example/config.js"></script>
<script src="js/soon-example/controllers/SearchCtrl.js"></script>
<script src="js/soon-example/controllers/ResultsCtrl.js"></script>
<script src="js/soon-example/directives/appVersion.js"></script>
<!-- /build -->
<!--<![endif]-->

Expand Down
4 changes: 3 additions & 1 deletion app/js/soon-example/app.js
Expand Up @@ -3,6 +3,8 @@
* @module sn.example
* @main sn.example
* @author SOON_
* @requires config constants defined from build process e.g.
* version number or environment variables
* @requires ngRoute {@link https://docs.angularjs.org/api/ngRoute}
*/
angular.module("sn.example", ["ngRoute"]);
angular.module("sn.example", ["config", "ngRoute"]);
6 changes: 4 additions & 2 deletions app/js/soon-example/controllers/SearchCtrl.js
Expand Up @@ -10,22 +10,24 @@ angular.module("sn.example").controller("SearchCtrl", [
"$rootScope",
"$http",
"$location",
"env",
/**
* @constructor
* @param {Object} $scope
* @param {Service} $rootScope
* @param {Service} $http
* @param {Service} $location
* @param {Object} env
*/
function ($scope, $rootScope, $http, $location) {
function ($scope, $rootScope, $http, $location, env) {

/**
* Search locations based on val
* @method getLocation
* @param {String} val location to query
*/
$scope.getLocation = function getLocation(val){
$http.get("http://maps.googleapis.com/maps/api/geocode/json", {
$http.get(env.GOOGLE_MAPS_API_ADDRESS + "maps/api/geocode/json", {
params: {
address: val,
sensor: false
Expand Down
31 changes: 31 additions & 0 deletions app/js/soon-example/directives/appVersion.js
@@ -0,0 +1,31 @@
"use strict";
/**
* Display the app version number in html
* @example
<app-version></app-version>
* @class appVersion
* @module sn.example
* @author SOON_
*/
angular.module("sn.example").directive("appVersion", [
"bower",
/**
* @constructor
* @param {Object} bower
*/
function (bower){
return {
restrict: "EAC",
scope: {},
template: "<p class=\"text-right\">App version: <b>{{ version }}</b></p>",
link: function($scope){

/**
* @property version
* @type {String}
*/
$scope.version = bower.version;
}
};
}
]);
2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -4,7 +4,7 @@
"version": "0.1.1",
"homepage": "https://github.com/thisissoon/angular-start",
"license": "MIT",
"private": true,
"private": false,
"dependencies": {
"angular": "~1.3.5",
"angular-route": "~1.3.5",
Expand Down
10 changes: 10 additions & 0 deletions env.json
@@ -0,0 +1,10 @@
{
"development": {
"BASE_URL": "/app/",
"GOOGLE_MAPS_API_ADDRESS": "http://maps.googleapis.com/"
},
"production": {
"BASE_URL": "/",
"GOOGLE_MAPS_API_ADDRESS": "http://maps.googleapis.com/"
}
}
3 changes: 2 additions & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "angular-start",
"private": true,
"private": false,
"version": "0.1.1",
"description": "The start of all angularjs projects. A base template for a typical angularjs application.",
"repository": "https://github.com/thisissoon/angular-start",
Expand All @@ -24,6 +24,7 @@
"grunt-contrib-uglify": "~0.6.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-contrib-yuidoc": "~0.5.2",
"grunt-ng-constant": "~1.1.0",
"grunt-processhtml": "~0.3.3",
"grunt-protractor-runner": "~1.1.4",
"grunt-protractor-webdriver": "~0.1.9",
Expand Down
3 changes: 2 additions & 1 deletion scripts.json
Expand Up @@ -7,6 +7,7 @@
"./app/js/soon-example/app.js",
"./app/js/soon-example/config.js",
"./app/js/soon-example/controllers/SearchCtrl.js",
"./app/js/soon-example/controllers/ResultsCtrl.js"
"./app/js/soon-example/controllers/ResultsCtrl.js",
"./app/js/soon-example/directives/appVersion.js"
]
}
4 changes: 4 additions & 0 deletions tests/e2e/specs/scenarios.js
Expand Up @@ -21,6 +21,10 @@ describe("sn.example", function() {
expect(element.all(by.css("ng-view h1")).first().getText()).toContain("Search");
});

it("should display version number", function() {
expect(element.all(by.css("app-version")).first().getText()).toContain("App version:");
});

it("should search for location", function() {
element(by.model("location")).sendKeys("London");
element(by.id("submit")).click();
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/soon-example/controllers/SearchCtrl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions tests/unit/soon-example/directives/appVersion.js
@@ -0,0 +1,26 @@
"use strict";

describe("appVersion", function() {
var $element, $scope, $rootScope, version;

beforeEach(module("sn.example"));

beforeEach(inject(function (_$rootScope_, $compile, $injector) {
$rootScope = _$rootScope_;

$scope = $rootScope.$new();

version = $injector.get("pkg").version;

$element = "<app-version></app-version>";

$element = $compile($element)($scope);
$scope.$digest();

}));

it("should display the correct version number", function(){
expect($element.html()).toContain(version);
});

});

0 comments on commit 0e87e31

Please sign in to comment.