Skip to content

Commit 30483c7

Browse files
committed
Clean-up for release. Refactoring some of the code into directives.
1 parent aa19687 commit 30483c7

File tree

14 files changed

+219
-213
lines changed

14 files changed

+219
-213
lines changed

bower.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"dependencies": {
44
"angular": "1.6.7",
55
"angular-contentful": "^2.2.0",
6+
"angular-marked": "^1.2.2",
67
"angular-sanitize": "^1.6.8",
7-
"bootstrap": "^4.0.0",
88
"angular-ui-router": "^1.0.13",
9+
"bootstrap": "^4.0.0",
910
"font-awesome": "^4.7.0",
1011
"jquery": "^3.3.1",
12+
"marked": "^0.3.12",
1113
"ngmap": "^1.18.4",
12-
"tether": "^1.4.3",
13-
"angular-marked": "^1.2.2",
14-
"marked": "^0.3.12"
14+
"tether": "^1.4.3"
1515
},
1616
"devDependencies": {}
1717
}

gulpfile.js

Lines changed: 46 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,54 +14,23 @@ var gulp = require("gulp"),
1414
connect = require("gulp-connect");
1515
sass = require('gulp-sass');
1616

17-
1817
var pkg = require("./package.json"),
18+
cssFile = "index.css", // CSS page name
19+
root = ".", // index page path
20+
pages = [ "index" ]; // list all pages
1921

20-
// CSS page name
21-
cssFile = "index.css",
22-
23-
// index page path
24-
root = ".",
25-
26-
// list all pages
27-
pages = [
28-
"index"
29-
];
30-
31-
var banner = [
32-
"/* " + pkg.name + " v" + pkg.version + " " + dateformat(new Date(), "yyyy-mm-dd"),
33-
" * " + pkg.homepage,
34-
" * License: " + pkg.license,
35-
" */\n\n"
36-
].join("\n"),
37-
22+
// Variable Definitions
23+
var banner = [ "/* " + pkg.name + " v" + pkg.version + " " + dateformat(new Date(), "yyyy-mm-dd"), " * " + pkg.homepage, " * License: " + pkg.license, " */\n\n" ].join("\n"),
3824
paths = {
3925
"tmpl": [root+"/src/**/*.html"],
4026
"js": ["!**/*.tmp.js", "!**/*.test.js", "!"+root+"/src/**/*.min.js", root+"/src/**/*.js"],
4127
"css": ["!"+root+"/src/**/*.min.scss", root+"/src/**/*.scss"]
4228
},
4329
ngModule = pkg.name;
4430

45-
// generate path of pages
46-
pages.forEach(function(page) {
47-
var name = page + ".src.html";
48-
paths[name] = paths[name] || [];
49-
paths[name].push(root + "/" + name);
50-
51-
name = page + ".html";
52-
paths[name] = paths[name] || [];
53-
paths[name].push(root + "/" + name);
54-
});
55-
56-
gulp.task("build", sync.sync([
57-
// Build resources
58-
["css", "js", "tmpl", "bower.json"],
59-
60-
// Build page sources
61-
pages.map(function(page) { return page + ".src.html"; }),
62-
63-
// Build release pages
64-
pages.map(function(page) { return page + ".html"; })
31+
gulp.task("build", sync.sync([ ["css", "js", "tmpl", "bower.json"],
32+
pages.map(function(page) { return page + ".src.html"; }), // Build page sources
33+
pages.map(function(page) { return page + ".html"; }) // Build release pages
6534
]));
6635

6736
// Default Task - Build & Watch
@@ -71,7 +40,7 @@ gulp.task("default", sync.sync([ ["build"], ["watch"] ]));
7140
gulp.task("dev", ["watch"]);
7241

7342
// gulp up (update npm & bower)
74-
gulp.task("up", ["update-npm", "update-bower"]);
43+
gulp.task("update", ["update-npm", "update-bower"]);
7544

7645
// gulp CSS (compile sass, concat into single file and reload)
7746
gulp.task("css", function(done) {
@@ -89,8 +58,7 @@ gulp.task("js", function(done) {
8958
.on("end", done);
9059
});
9160

92-
// gulp tmpl
93-
// All angular templates get put into a template cache
61+
// gulp tmpl (build the template cache)
9462
gulp.task("tmpl", function(done) {
9563
gulp.src(paths.tmpl)
9664
.pipe(templatecache("angular-template.tmp.js", {
@@ -102,6 +70,7 @@ gulp.task("tmpl", function(done) {
10270
.on("end", done);
10371
});
10472

73+
// Watch the files for changes
10574
gulp.task("watch", function() { ["tmpl", "css", "js"]
10675
.concat(pages.map(function(page) { return page + ".src.html"; }))
10776
.forEach(function(i) {
@@ -124,6 +93,41 @@ gulp.task("watch", function() { ["tmpl", "css", "js"]
12493
});
12594
});
12695

96+
gulp.task("bower.json", function(done) {
97+
gulp.src(["bower.json"])
98+
.pipe(replace(/"name": "[^"]*"/, "\"name\": \"" + pkg.name + "\""))
99+
.pipe(gulp.dest("./"))
100+
.on("end", done);
101+
});
102+
103+
gulp.task("update-npm", function(done) {
104+
var cmd = "sh -c './node_modules/npm-check-updates/bin/npm-check-updates -u'";
105+
run(cmd).exec().on("end", done);
106+
});
107+
108+
gulp.task("update-bower", function(done) {
109+
var bowerjson = require("./bower.json");
110+
var deps = [];
111+
var i, cmd;
112+
113+
for (i in bowerjson.dependencies) {
114+
deps.push(i);
115+
}
116+
117+
cmd = "bower install --save --force-latest " + deps.join(" ");
118+
run(cmd).exec().on("end", done);
119+
});
120+
121+
// generate path of pages
122+
pages.forEach(function(page) {
123+
var name = page + ".src.html";
124+
paths[name] = paths[name] || [];
125+
paths[name].push(root + "/" + name);
126+
127+
name = page + ".html";
128+
paths[name] = paths[name] || [];
129+
paths[name].push(root + "/" + name);
130+
});
127131

128132
// generate task of pages
129133
pages.forEach(function(page) {
@@ -162,29 +166,4 @@ pages.forEach(function(page) {
162166
.on("end", done);
163167
});
164168
})(page);
165-
});
166-
167-
gulp.task("bower.json", function(done) {
168-
gulp.src(["bower.json"])
169-
.pipe(replace(/"name": "[^"]*"/, "\"name\": \"" + pkg.name + "\""))
170-
.pipe(gulp.dest("./"))
171-
.on("end", done);
172-
});
173-
174-
gulp.task("update-npm", function(done) {
175-
var cmd = "sh -c './node_modules/npm-check-updates/bin/npm-check-updates -u'";
176-
run(cmd).exec().on("end", done);
177-
});
178-
179-
gulp.task("update-bower", function(done) {
180-
var bowerjson = require("./bower.json");
181-
var deps = [];
182-
var i, cmd;
183-
184-
for (i in bowerjson.dependencies) {
185-
deps.push(i);
186-
}
187-
188-
cmd = "bower install --save --force-latest " + deps.join(" ");
189-
run(cmd).exec().on("end", done);
190169
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-contentful-starter",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "AngularJS Contentful Starter Kit",
55
"devDependencies": {
66
"dateformat": "^1.0.11",

src/config/app.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
// Initialize the Angular Module.
1+
/**
2+
* AngularJS Starter Kit
3+
* @author Josh Hebb
4+
*
5+
*/
6+
7+
// Initialize the Angular Module and load any libraries.
28
var app = angular.module("angular-contentful-starter", [
39
"ui.router",
410
"contentful",
@@ -9,6 +15,8 @@ var app = angular.module("angular-contentful-starter", [
915

1016
// Configure Contentful with the space ID & API access token so we can query Contentful.
1117
app.config(function(contentfulProvider){
18+
19+
// You can get your option values from Contentful (https://www.contentful.com/developers/docs/references/authentication/)
1220
contentfulProvider.setOptions({
1321
space: 'hpty8kufn7nl',
1422
accessToken: '3cdfdbcbd12558162e4f8a4105674661f02f8c26afa9e8423e29703e8915427e'
@@ -20,7 +28,7 @@ app.config(['markedProvider', function (markedProvider) {
2028
markedProvider.setOptions({gfm: true});
2129
}]);
2230

23-
// Send the user to the top of the page when we route them
31+
// Send the user to the top of the page when we route them anywhere.
2432
app.run(['$transitions', function ($transitions) {
2533
$transitions.onSuccess({}, function () {
2634
document.body.scrollTop = document.documentElement.scrollTop = 0;

src/config/route.js

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,86 +8,104 @@ app.config(["$stateProvider", "$urlRouterProvider", function ($stateProvider, $u
88
.state("home", {
99
url: "/",
1010
templateUrl: "src/views/home.html",
11+
// Inline Controller. Can be defined in this file, or it's own file and referenced by name.
12+
controller: function ($scope, $stateParams, contentful) {
13+
// Query the product lines from Contentful.
14+
contentful
15+
.entries('content_type=productLine').then(
16+
function (response) {
17+
if (response.data && response.data.items && response.data.items.length > 0) {
18+
$scope.productLines = response.data.items; } } );
19+
// Query the blog articles from Contentful.
20+
contentful
21+
.entries('content_type=blogArticle&limit=3&order=-sys.updatedAt').then(
22+
function (response) {
23+
if (response.data && response.data.items && response.data.items.length > 0) {
24+
$scope.articles = response.data.items; } } );
25+
// Query the locations (shops) from Contentful.
26+
contentful
27+
.entries('content_type=event&limit=5&order=fields.date').then(
28+
function (response) {
29+
if (response.data && response.data.items && response.data.items.length > 0) {
30+
$scope.stores = response.data.items; } } );
31+
}
1132
})
1233

1334
// Products Landing Page. Pulls a 'Line of Products' from contentful.
35+
// i.e. /products/headphones
1436
.state("products", {
1537
url: "/products/:productLine",
1638
templateUrl: "src/views/products.html",
17-
// Inline Controller. Can be defined in this file, or it's own file and referenced by name.
1839
controller: function ($scope, $stateParams, contentful) {
40+
// Query the Product Lines from Contentful.
1941
contentful
2042
.entries('content_type=productLine&fields.urlSlug=' + $stateParams.productLine).then(
2143
function (response) {
44+
console.log(response);
2245
if (response.data && response.data.items && response.data.items.length > 0) {
23-
$scope.productLine = response.data.items[0].fields;
24-
}
25-
}
26-
);
46+
$scope.productLine = response.data.items[0].fields; } } );
2747
}
2848
})
2949

30-
// Product Landing Page (Single Product) accessed from a Product Line (i.e. /headphones/beats-by-dre/)
50+
// Product Landing Page (Single Product) accessed from a Product Line
51+
// i.e. /products/headphones/beats-by-dre/
3152
.state("product", {
3253
url: "/products/:productLine/:product",
3354
templateUrl: "src/views/product.html",
3455
controller: function ($scope, $stateParams, contentful) {
56+
// Query the Product from Contentful.
3557
contentful
3658
.entries('content_type=product&fields.urlSlug=' + $stateParams.product).then(
3759
function (response) {
3860
if (response.data && response.data.items && response.data.items.length > 0) {
39-
$scope.product = response.data.items[0].fields;
40-
}
41-
}
42-
);
61+
$scope.product = response.data.items[0].fields; } } );
4362
}
4463
})
4564

65+
// Product Landing Page (Single Product) accessed outside of the context of a product line
66+
// i.e. /product/beats-solo-3
4667
.state("singleProduct", {
4768
url: "/product/:product",
4869
templateUrl: "src/views/product.html",
4970
controller: function ($scope, $stateParams, contentful) {
71+
// Query the Product from Contentful
5072
contentful
5173
.entries('content_type=product&fields.urlSlug=' + $stateParams.product).then(
5274
function (response) {
5375
if (response.data && response.data.items && response.data.items.length > 0) {
54-
$scope.product = response.data.items[0].fields;
55-
}
56-
}
76+
$scope.product = response.data.items[0].fields; } }
5777
);
5878
}
5979
})
6080

81+
// Article Landing Page (single article).
82+
// i.e. /article/contentful-intro
6183
.state("article", {
6284
url: "/article/:articleTitle",
6385
templateUrl: "src/views/article.html",
6486
controller: function ($scope, $stateParams, contentful) {
87+
// Query the Article from Contentful.
6588
contentful
6689
.entries('content_type=blogArticle&fields.urlSlug=' + $stateParams.articleTitle).then(
6790
function (response) {
6891
if (response.data && response.data.items && response.data.items.length > 0) {
69-
$scope.article = response.data.items[0].fields;
70-
}
71-
}
72-
);
92+
$scope.article = response.data.items[0].fields; } } );
7393
}
7494
})
7595

96+
// Location Landing Page (Store)
97+
// i.e. /location/pasadena
7698
.state("location", {
7799
url: "/location/:locationTitle",
78100
templateUrl: "src/views/location.html",
79101
controller: function ($scope, $stateParams, contentful) {
102+
// Query the Location from Contentful based on the URL Slug.
80103
contentful
81104
.entries('content_type=event&fields.urlSlug=' + $stateParams.locationTitle) .then(
82105
function (response) {
83106
if (response.data && response.data.items && response.data.items.length > 0) {
84-
$scope.store = response.data.items[0].fields;
85-
}
86-
}
87-
);
107+
$scope.store = response.data.items[0].fields; } } );
88108
}
89109
});
90110

91-
92-
93111
}]);

src/directives/carousel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Carousel.js
2+
* carousel.js
33
*
44
* Query banner objects to be rendered in the carousel with content from Contentful.
55
* @Author Josh Hebb

src/directives/footer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* footer.js
3+
*
4+
* Render out the footer.
5+
* @Author Josh Hebb
6+
*
7+
*/
18
app.directive("footerSection", function() {
29
return {
310
restrict: 'E',

src/directives/header.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* header.js
3+
*
4+
* Render out the header. Simple :).
5+
* @Author Josh Hebb
6+
*
7+
*/
8+
app.directive("header", function() {
9+
return {
10+
restrict: 'E',
11+
templateUrl: "src/views/header.html"
12+
}
13+
});

src/directives/navigation.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/views/featured-products.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- Featured List of Products (w/ border) -->
12
<ul class="list-group">
23
<li class="list-group-item" ng-repeat="product in products">
34
<a href="#" ui-sref="singleProduct({ product: product.fields.urlSlug })">

0 commit comments

Comments
 (0)