Skip to content
This repository was archived by the owner on Sep 10, 2019. It is now read-only.

Commit a839fe2

Browse files
committed
Merge pull request #296 from zurb/gulpfile
Gulpfile refactor
2 parents 570a172 + 15be8b4 commit a839fe2

File tree

7 files changed

+214
-138
lines changed

7 files changed

+214
-138
lines changed
File renamed without changes.

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<link rel="shortcut icon" href="assets/img/favicon.ico">
88
<link href="assets/css/app.css" rel="stylesheet" type="text/css">
99
<script src="assets/js/routes.js"></script>
10+
<script src="assets/js/foundation.js"></script>
1011
<script src="assets/js/app.js"></script>
11-
<script src="assets/js/angular-app.js"></script>
1212
</head>
1313
<body zf-esc-close>
1414

gulpfile.js

Lines changed: 137 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
'use strict'
22

3+
// Foundation for Apps
4+
//
5+
// We use this Gulpfile to assemble the documentation, run unit tests,
6+
// and deploy changes to the live documentation and CDN.
7+
//
8+
// The tasks are grouped into these categories:
9+
// 1. Libraries
10+
// 2. Variables
11+
// 3. Cleaning files
12+
// 4. Copying files
13+
// 5. Stylesheets
14+
// 6. JavaScript
15+
// 7. Testing
16+
// 8. Server
17+
// 9. Deployment
18+
// 10. Default tasks
19+
20+
// 1. LIBRARIES
21+
// - - - - - - - - - - - - - - -
22+
323
var gulp = require('gulp'),
424
rimraf = require('rimraf'),
525
runSequence = require('run-sequence'),
@@ -14,23 +34,46 @@ var gulp = require('gulp'),
1434
modRewrite = require('connect-modrewrite'),
1535
dynamicRouting = require('./bin/gulp-dynamic-routing'),
1636
karma = require('gulp-karma'),
17-
rsync = require('gulp-rsync');
37+
rsync = require('gulp-rsync'),
38+
merge = require('merge-stream');
1839

19-
// Deploy
20-
gulp.task('deploy', ['build'], function() {
21-
return gulp.src('build/**')
22-
.pipe(rsync({
23-
root: 'build',
24-
hostname: 'deployer@72.32.134.77',
25-
destination: '/home/deployer/sites/foundation-apps/current'
26-
}));
27-
});
40+
// 2. VARIABLES
41+
// - - - - - - - - - - - - - - -
42+
43+
var foundationJS = [
44+
'bower_components/fastclick/lib/fastclick.js',
45+
'bower_components/viewport-units-buggyfill/viewport-units-buggyfill.js',
46+
'bower_components/tether/tether.js',
47+
'bower_components/angular/angular.js',
48+
'bower_components/angular-animate/angular-animate.js',
49+
'bower_components/ui-router/release/angular-ui-router.js',
50+
'js/vendor/**/*.js',
51+
'js/angular/**/*.js'
52+
];
53+
var docsJS = [
54+
'bower_components/marked/lib/marked.js',
55+
'bower_components/angular-highlightjs/angular-highlightjs.js',
56+
'bower_components/highlightjs/highlight.pack.js',
57+
'bower_components/allmighty-autocomplete/script/autocomplete.js',
58+
'docs/assets/js/app.js'
59+
];
60+
61+
// 3. CLEANIN' FILES
62+
// - - - - - - - - - - - - - - -
2863

2964
// Clean build directory
3065
gulp.task('clean', function(cb) {
3166
rimraf('./build', cb);
3267
});
3368

69+
// Clean the partials directory
70+
gulp.task('clean:partials', function(cb) {
71+
rimraf('./build/partials', cb);
72+
});
73+
74+
// 4. COPYING FILES
75+
// - - - - - - - - - - - - - - -
76+
3477
// Copy static files (but not the Angular templates, Sass, or JS)
3578
gulp.task('copy', function() {
3679
var dirs = [
@@ -47,17 +90,32 @@ gulp.task('copy', function() {
4790
.pipe(gulp.dest('build/assets/img/iconic/'));
4891
});
4992

50-
gulp.task('clean-partials', function(cb) {
51-
rimraf('./build/partials', cb);
93+
// Copy page templates and generate routes
94+
gulp.task('copy:templates', ['copy'], function() {
95+
var config = [];
96+
97+
return gulp.src('./docs/templates/**/*.html')
98+
.pipe(dynamicRouting({
99+
path: 'build/assets/js/routes.js',
100+
root: 'docs'
101+
}))
102+
.pipe(markdown())
103+
.pipe(highlight())
104+
.pipe(gulp.dest('./build/templates'))
105+
;
52106
});
53107

54-
gulp.task('copy-partials', ['clean-partials'], function() {
108+
// Copy Foundation directive partials
109+
gulp.task('copy:partials', ['clean:partials'], function() {
55110
return gulp.src(['js/angular/partials/**.*'])
56111
.pipe(gulp.dest('./build/partials/'));
57112
});
58113

114+
// 5. STYLESHEETS
115+
// - - - - - - - - - - - - - - -
116+
117+
// Inject styles for docs-specific libraries
59118
gulp.task('css', ['sass'], function() {
60-
//copy css
61119
var dirs = [
62120
'bower_components/allmighty-autocomplete/style/autocomplete.css',
63121
'build/assets/css/app.css'
@@ -66,16 +124,15 @@ gulp.task('css', ['sass'], function() {
66124
.pipe(concat('app.css'))
67125
.pipe(gulp.dest('build/assets/css'))
68126
;
69-
70127
});
71128

129+
// Compile stylesheets with Ruby Sass
72130
gulp.task('sass', function() {
73-
return gulp.src('docs/assets/scss/app.scss')
74-
.pipe(sass({
131+
return sass('docs/assets/scss/', {
75132
loadPath: ['scss'],
76133
style: 'nested',
77134
bundleExec: true
78-
}))
135+
})
79136
.on('error', function(e) {
80137
console.log(e);
81138
})
@@ -85,6 +142,7 @@ gulp.task('sass', function() {
85142
.pipe(gulp.dest('./build/assets/css/'));
86143
});
87144

145+
// Compile stylesheets with node-sass
88146
gulp.task('node-sass', function() {
89147
return gulp.src('docs/assets/scss/app.scss')
90148
.pipe(nodeSass({
@@ -99,67 +157,38 @@ gulp.task('node-sass', function() {
99157
.pipe(gulp.dest('./build/assets/css/'));
100158
});
101159

102-
// Process Foundation JS
103-
gulp.task('uglify', ['uglify-app'], function() {
104-
var libs = [
105-
'bower_components/fastclick/lib/fastclick.js',
106-
'bower_components/viewport-units-buggyfill/viewport-units-buggyfill.js',
107-
'bower_components/notify.js/notify.js',
108-
'bower_components/tether/tether.js',
109-
'bower_components/marked/lib/marked.js',
110-
'bower_components/angular/angular.js',
111-
'bower_components/allmighty-autocomplete/script/autocomplete.js',
112-
'bower_components/angular-animate/angular-animate.js',
113-
'bower_components/ui-router/release/angular-ui-router.js',
114-
'bower_components/angular-highlightjs/angular-highlightjs.js',
115-
'bower_components/highlightjs/highlight.pack.js',
116-
'js/vendor/**/*.js',
117-
];
160+
// 6. JAVASCRIPT
161+
// - - - - - - - - - - - - - - -
118162

119-
return gulp.src(libs)
163+
// Compile Foundation JavaScript
164+
gulp.task('javascript', function() {
165+
return gulp.src(foundationJS)
120166
.pipe(uglify({
121167
beautify: true,
122168
mangle: false
123169
}).on('error', function(e) {
124170
console.log(e);
125171
}))
126-
.pipe(concat('app.js'))
172+
.pipe(concat('foundation.js'))
127173
.pipe(gulp.dest('./build/assets/js/'))
128174
;
129175
});
130176

131-
// Process Angular JS
132-
gulp.task('uglify-app', function() {
133-
var libs = [
134-
'docs/assets/js/angular.js',
135-
'js/angular/**/*.js',
136-
'!js/angular/app.js'
137-
];
138-
139-
return gulp.src(libs)
177+
// Compile documentation-specific JavaScript
178+
gulp.task('javascript:docs', function() {
179+
return gulp.src(docsJS)
140180
.pipe(uglify({
141181
beautify: true,
142182
mangle: false
143183
}))
144-
.pipe(concat('angular-app.js'))
184+
.pipe(concat('app.js'))
145185
.pipe(gulp.dest('./build/assets/js/'))
146186
;
147187

148188
});
149189

150-
gulp.task('copy-templates', ['copy'], function() {
151-
var config = [];
152-
153-
return gulp.src('./docs/templates/**/*.html')
154-
.pipe(dynamicRouting({
155-
path: 'build/assets/js/routes.js',
156-
root: 'docs'
157-
}))
158-
.pipe(markdown())
159-
.pipe(highlight())
160-
.pipe(gulp.dest('./build/templates'))
161-
;
162-
});
190+
// 7. SERVER
191+
// - - - - - - - - - - - - - - -
163192

164193
gulp.task('server:start', function() {
165194
connect.server({
@@ -172,7 +201,10 @@ gulp.task('server:start', function() {
172201
});
173202
});
174203

175-
gulp.task('karma-test', ['build', 'node-sass'], function() {
204+
// 8. TESTING
205+
// - - - - - - - - - - - - - - -
206+
207+
gulp.task('karma:test', ['build', 'node-sass'], function() {
176208
var testFiles = [
177209
'build/assets/js/app.js',
178210
'build/assets/js/angular-app.js',
@@ -195,31 +227,64 @@ gulp.task('karma-test', ['build', 'node-sass'], function() {
195227

196228
});
197229

198-
gulp.task('test', ['karma-test'], function() {
230+
gulp.task('test', ['karma:test'], function() {
199231
console.log('Tests finished.');
200232
});
201233

234+
// 9. DEPLOYMENT
235+
// - - - - - - - - - - - - - - -
236+
237+
// Deploy documentation
238+
gulp.task('deploy', ['build'], function() {
239+
return gulp.src('build/**')
240+
.pipe(rsync({
241+
root: 'build',
242+
hostname: 'deployer@72.32.134.77',
243+
destination: '/home/deployer/sites/foundation-apps/current'
244+
}));
245+
});
246+
247+
// Deploy to CDN
248+
gulp.task('deploy:cdn', function() {
249+
var js = gulp.src(foundationJS)
250+
.pipe(uglify())
251+
.pipe(concat('foundation.js'));
252+
var css = sass('scss/', {
253+
sourcemap: false, style: 'compressed'
254+
});
255+
256+
merge(js, css)
257+
.pipe(rsync({
258+
hostname: 'deployer@72.32.134.77',
259+
destination: '/home/deployer/sites/foundation-apps/current/cdn'
260+
}));
261+
});
262+
263+
// 10. NOW BRING IT TOGETHER
264+
// - - - - - - - - - - - - - - -
265+
266+
// Build the documentation once
202267
gulp.task('build', function(cb) {
203-
runSequence('clean', ['copy', 'copy-partials', 'css', 'uglify'], 'copy-templates', function() {
268+
runSequence('clean', ['copy', 'copy:partials', 'css', 'javascript', 'javascript:docs'], 'copy:templates', function() {
204269
console.log('Successfully built.');
205270
cb();
206271
});
207272
});
208273

209-
274+
// Build the documentation, start a test server, and re-compile when files change
210275
gulp.task('default', ['build', 'server:start'], function() {
211-
// Watch Sass
212-
gulp.watch(['./docs/assets/scss/**/*', './scss/**/*'], ['css']);
213-
214-
// Watch JavaScript
215-
gulp.watch(['./docs/assets/js/**/*', './js/**/*'], ['uglify']);
216-
217276
// Watch static files
218277
gulp.watch(['./docs/**/*.*', '!./docs/templates/**/*.*', '!./docs/assets/{scss,js}/**/*.*'], ['copy']);
219278

279+
// Watch Angular templates
280+
gulp.watch(['docs/templates/**/*.html'], ['copy:templates']);
281+
220282
// Watch Angular partials
221-
gulp.watch(['js/angular/partials/**.*'], ['copy-partials']);
283+
gulp.watch(['js/angular/partials/**.*'], ['copy:partials']);
222284

223-
// Watch Angular templates
224-
gulp.watch(['docs/templates/**/*.html'], ['copy-templates']);
285+
// Watch Sass
286+
gulp.watch(['./docs/assets/scss/**/*', './scss/**/*'], ['css']);
287+
288+
// Watch JavaScript
289+
gulp.watch(['./docs/assets/js/**/*', './js/**/*'], ['javascript']);
225290
});

js/angular/common/foundation.init.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ angular.module('foundation.init.state', ['ui.router'])
143143
return {
144144
templateUrl: path,
145145
controller: getController(state),
146-
}
146+
};
147147
}
148148

149149
function getController(state) {
@@ -156,3 +156,22 @@ angular.module('foundation.init.state', ['ui.router'])
156156
return ctrl;
157157
}
158158
}]);
159+
160+
angular.module('foundation.init.state')
161+
.controller('DefaultController', ['$scope', '$stateParams', '$state', function($scope, $stateParams, $state) {
162+
var params = [];
163+
angular.forEach($stateParams, function(value, key) {
164+
params[key] = value;
165+
});
166+
167+
$scope.params = params;
168+
$scope.current = $state.current.name;
169+
170+
if($state.current.views) {
171+
$scope.vars = $state.current.data.vars;
172+
$scope.composed = $state.current.data.vars.children;
173+
} else {
174+
$scope.vars = $state.current.data.vars;
175+
}
176+
}
177+
]);

js/angular/controllers.js

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

0 commit comments

Comments
 (0)