Skip to content

Commit d093487

Browse files
committed
Merge pull request #140 from hannu/initial-progress
Emit progress information from gulp task to client. Implement progress bar
2 parents 1a51f07 + b4424b8 commit d093487

File tree

15 files changed

+167
-145
lines changed

15 files changed

+167
-145
lines changed

README.md

+12-34
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ Options passed to gulp-less
153153

154154
This class is added to all preview blocks in the generated styleguide. If your styles have some namespace class that needs to be added to every block and you do not want to add it to every example you can use commonClass option.
155155

156+
**server** (boolean, optional)
157+
158+
Enable built-in web-server. To enable Desiger tools styleguide must be server with built-in web-server. Server has also ability to refresh changed styles or KSS markup without doing the full page reload.
159+
160+
**port** (number, optional)
161+
162+
Port of the server. Default is 3000.
163+
164+
**rootPath** (string, optional)
165+
166+
Server root path. This must be defined if you run built-in server via gulp or grunt task. Point to the same path as styleguide output folder.
167+
156168
**appRoot** (string, optional)
157169

158170
Define `appRoot` parameter if you host styleguide in other than root folder of the HTTP serve. If
@@ -184,40 +196,6 @@ Configuration array containing paths to the dependencies of the hosted applicati
184196

185197
Note: When using templateUrl in directives, the template path is relative to styleguide index.html, not the hosted application root.
186198

187-
## Built-in server
188-
189-
Styleguide contains built-in web-server to host the styleguide. To enable [Desiger tools](#designer-tools) styleguide must be server with built-in web-server.
190-
191-
### Using CLI
192-
193-
Built-in server is started when styleguide is started with `--server` or with `--watch` parameters.
194-
195-
### Using Gulp
196-
197-
var server = require("sc5-styleguide").server;
198-
199-
gulp.task("server", function() {
200-
styleguide.server({
201-
rootPath: <styleguide root path>,
202-
sassVariables: <path to sass variables file>
203-
});
204-
});
205-
206-
### Automatically apply changed styles to styleguide
207-
208-
Styleguide has ability to use changed styles without reloading the whole page. To enable this feature you must call `server.io.emitChanges()` when the styleguide is generated.
209-
210-
return gulp.src(sourcePaths)
211-
.pipe(styleguide(options))
212-
.pipe(gulp.dest(outputPath))
213-
.on('end', function() {
214-
// Styleguide is updated
215-
// Send message to active clients to refresh the new CSS
216-
if (server && server.io) {
217-
server.io.emitChanges();
218-
}
219-
});
220-
221199
## Documenting syntax
222200

223201
Document your CSS components with [KSS](http://warpspire.com/kss/)

bin/styleguide

+5-26
Original file line numberDiff line numberDiff line change
@@ -50,46 +50,25 @@ if (config.sassVariables) {
5050
config.sassVariables = path.resolve(path.dirname(argv.config), config.sassVariables);
5151
}
5252
options = extend({
53-
socketIo: !!argv.server,
5453
sass: {
5554
includePaths: neat.includePaths
56-
}
55+
},
56+
server: !!argv.server,
57+
port: argv.port,
58+
rootPath: outputPath
5759
}, config);
5860

5961
gulp.task('styleguide', function() {
6062
gulp.src(sourceFiles)
6163
.pipe(styleguide(options))
62-
.pipe(gulp.dest(outputPath))
63-
.on('end', function() {
64-
// Styleguide is updated. Send message to active clients to refresh the new CSS
65-
if (server && server.io) {
66-
server.io.emitChanges();
67-
}
68-
});
69-
});
70-
71-
gulp.task('serve', function() {
72-
server = require('../lib/server')({
73-
rootPath: outputPath,
74-
sassVariables: options.sassVariables
75-
}),
76-
app = serverModule.app,
77-
server = serverModule.server;
78-
79-
app.set('port', util.env.port || 3000);
80-
server = server.listen(app.get('port'), function() {
81-
console.log('Express server listening on port ' + server.address().port);
82-
});
64+
.pipe(gulp.dest(outputPath));
8365
});
8466

8567
gulp.task('watch', function() {
8668
gulp.watch(sourceFiles, ['styleguide']);
8769
});
8870

8971
var tasks = ['styleguide'];
90-
if (argv.server) {
91-
tasks.push('serve');
92-
}
9372
if (argv.watch) {
9473
tasks.push('watch');
9574
}

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"angular-bootstrap-colorpicker": "3.0.8",
1010
"angular-local-storage": "0.1.0",
1111
"ui-router": "0.2.11",
12-
"oclazyload": "0.3.8"
12+
"oclazyload": "0.3.8",
13+
"ngprogress": "~1.0.7"
1314
},
1415
"devDependencies": {},
1516
"resolutions": {

gulpfile.js

+18-32
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ var gulp = require('gulp'),
2020
configPath = util.env.config ? util.env.config.replace(/\/$/, '') : null,
2121
outputPath = util.env.output ? util.env.output.replace(/\/$/, '') : '',
2222
sourcePath = util.env.source ? util.env.source.replace(/\/$/, '') : '',
23-
options = {},
23+
options = {
24+
sass: {
25+
includePaths: neat.includePaths
26+
}
27+
},
2428
server;
2529

26-
function parseOptions() {
30+
function getBuildOptions() {
2731
var config = configPath ? require(configPath) : {};
2832
// Resolve overviewPath in relation to config file location
2933
if (config.overviewPath) {
@@ -35,26 +39,11 @@ function parseOptions() {
3539
config.styleVariables = path.resolve(path.dirname(configPath), config.sassVariables);
3640
}
3741

38-
options = extend({
39-
sass: {
40-
includePaths: neat.includePaths
41-
},
42-
socketIo: false
43-
}, config);
42+
return extend({
43+
rootPath: outputPath
44+
}, options, config);
4445
}
4546

46-
parseOptions();
47-
48-
/* Tasks for development */
49-
gulp.task('serve', function() {
50-
// Since we are running our own server we can enable socketIO
51-
options.socketIo = true;
52-
server = styleguide.server({
53-
rootPath: outputPath,
54-
styleVariables: options.styleVariables
55-
});
56-
});
57-
5847
gulp.task('jscs', function() {
5948
return gulp.src([
6049
'lib/**/*.js',
@@ -79,14 +68,8 @@ gulp.task('styleguide', function() {
7968
return 1;
8069
}
8170
return gulp.src([sourcePath + '/**/*.scss'])
82-
.pipe(styleguide(options))
83-
.pipe(gulp.dest(outputPath))
84-
.on('end', function() {
85-
// Styleguide is updated. Send message to active clients to refresh the new CSS
86-
if (server && server.io) {
87-
server.io.emitChanges();
88-
}
89-
});
71+
.pipe(styleguide(getBuildOptions()))
72+
.pipe(gulp.dest(outputPath));
9073
});
9174

9275
gulp.task('js:app', function() {
@@ -127,18 +110,17 @@ gulp.task('sass', function() {
127110
});
128111

129112
gulp.task('demo', function() {
113+
options.server = true;
130114
configPath = __dirname + '/lib/app/styleguide_config.json';
131115
sourcePath = __dirname + '/lib/app';
132116
outputPath = __dirname + '/demo-output';
133117

134-
// We need to re-parse options since configPath has changed
135-
parseOptions();
136118
// Watch changed styles in demo mode
137119
gulp.watch(sourcePath + '/**/*.scss', function() {
138120
runSequence('sass', 'styleguide');
139121
});
140122
// Run serve first so socketIO options is enabled when building styleguide
141-
return runSequence('serve', 'styleguide');
123+
return runSequence('styleguide');
142124
});
143125

144126
gulp.task('html', function() {
@@ -152,8 +134,12 @@ gulp.task('assets', function() {
152134
});
153135

154136
gulp.task('watch', [], function() {
137+
// Enable server by default when watching
138+
// Config have possibility to still override this
139+
options.server = true;
140+
155141
// Do intial full build and create styleguide
156-
runSequence(['serve', 'build'], 'styleguide');
142+
runSequence('build', 'styleguide');
157143

158144
gulp.watch('lib/app/sass/**/*.scss', function() {
159145
runSequence('sass', 'styleguide');

lib/app/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<link rel="icon" href="assets/img/favicon.ico">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
67
<link rel="stylesheet" type="text/css" href="{{{appRoot}}}/css/app.css">
78
<link rel="stylesheet" type="text/css" href="{{{appRoot}}}/styleguide.css">
89
<link rel="stylesheet" type="text/css" href="{{{appRoot}}}/styleguide_pseudo_styles.css">

lib/app/js/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ angular.module('sgApp', [
44
'colorpicker.module',
55
'hljs',
66
'LocalStorageModule',
7-
'oc.lazyLoad'
7+
'oc.lazyLoad',
8+
'ngProgress'
89
])
910
.config(function($stateProvider, $urlRouterProvider, $locationProvider, localStorageServiceProvider, $ocLazyLoadProvider) {
1011
$stateProvider

lib/app/js/controllers/appCtrl.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
'use strict';
22

33
angular.module('sgApp')
4-
.controller('AppCtrl', function($scope) {
4+
.controller('AppCtrl', function($scope, ngProgress) {
5+
6+
// ngProgress do not respect styles assigned via CSS if we do not pass empty parameters
7+
// See: https://github.com/VictorBjelkholm/ngProgress/issues/33
8+
ngProgress.height('');
9+
ngProgress.color('');
510

611
$scope.$on('$viewContentLoaded', function() {
712
window.scrollTo(0, 0);
813
});
914

15+
$scope.$on('progress start', function() {
16+
ngProgress.start();
17+
});
18+
19+
$scope.$on('progress end', function() {
20+
ngProgress.complete();
21+
});
22+
23+
$scope.$on('styles changed', function() {
24+
var links = document.getElementsByTagName('link');
25+
for (var l in links) {
26+
var link = links[l];
27+
if (typeof link === 'object' && link.getAttribute('type') === 'text/css') {
28+
link.href = link.href.split('?')[0] + '?id=' + new Date().getTime();
29+
}
30+
}
31+
});
1032
}
1133
);

lib/app/js/controllers/main.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
angular.module('sgApp')
44
.controller('MainCtrl', function($scope, $location, $state, $rootScope,
5-
Styleguide, Variables, localStorageService) {
5+
Styleguide, Variables, localStorageService, ngProgress) {
66

77
var socket;
88

@@ -71,16 +71,6 @@ angular.module('sgApp')
7171
};
7272
});
7373

74-
$scope.$on('styles changed', function() {
75-
var links = document.getElementsByTagName('link');
76-
for (var l in links) {
77-
var link = links[l];
78-
if (typeof link === 'object' && link.getAttribute('type') === 'text/css') {
79-
link.href = link.href.split('?')[0] + '?id=' + new Date().getTime();
80-
}
81-
}
82-
});
83-
8474
// Clear search
8575
$scope.clearSearch = function() {
8676
if ($scope.search) {

lib/app/js/services/Variables.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@
4141
var _this = this;
4242
socket = newSocket;
4343
if (socket) {
44-
socket.on('styles changed', function() {
44+
socket.on('styleguide progress start', function() {
45+
$rootScope.$broadcast('progress start');
46+
});
47+
socket.on('styleguide progress end', function() {
48+
$rootScope.$broadcast('progress end');
4549
$rootScope.$broadcast('styles changed');
4650
});
4751
}
+14-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
$default-action-color: #1695A3;
2-
$designer-tool-width: 30%;
3-
$header-height: 50px;
4-
$primary-action-color: #EB7F00;
1+
// Main color definitions
52
$primary-color: #1c3849;
6-
$primary-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
73
$secondary-color: #E4E4E4;
8-
$secondary-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
4+
$tertiary-color: #F7FCF1;
5+
6+
// Button and link colors
7+
$primary-action-color: #EB7F00;
8+
$default-action-color: #1695A3;
99
$action-color-change: 5%;
10-
$tertiary-color: #F7FCF1;
10+
11+
// Fonts
12+
$primary-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
13+
$secondary-font: "Helvetica Neue", Helvetica, Arial, sans-serif;
14+
15+
// Misc
16+
$designer-tool-width: 30%;
17+
$header-height: 60px;

lib/app/sass/app.scss

+35-2
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ $mobile: new-breakpoint(max-width 480px);
801801
z-index: 9000;
802802

803803
background: rgba(#fff, 1);
804-
@include transition(all 0.3s ease-out);
804+
@include transition(left 0.3s ease-out);
805805

806806
.handle {
807807
position: absolute;
@@ -832,7 +832,6 @@ $mobile: new-breakpoint(max-width 480px);
832832
}
833833

834834
.sg.design-content {
835-
@include transition(all 0.4s ease-out);
836835
position: relative;
837836
overflow-y: auto;
838837
overflow-x: auto;
@@ -882,6 +881,40 @@ $mobile: new-breakpoint(max-width 480px);
882881
border-top: 1px solid $secondary-color;
883882
}
884883

884+
// Progress bar
885+
//
886+
// markup:
887+
// <div id="ngProgress" style="width: 70%; opacity: 1;""></div>
888+
//
889+
// Styleguide 4.2
890+
891+
#ngProgress {
892+
margin: 0;
893+
padding: 0;
894+
z-index: 99998;
895+
background-color: $primary-action-color;
896+
color: $primary-action-color;
897+
box-shadow: 0 0 3px 0; /* Inherits the font color */
898+
height: 4px;
899+
opacity: 0;
900+
/* Add CSS3 styles for transition smoothing */
901+
-webkit-transition: all 0.5s ease-in-out;
902+
-moz-transition: all 0.5s ease-in-out;
903+
-o-transition: all 0.5s ease-in-out;
904+
transition: all 0.5s ease-in-out;
905+
}
906+
907+
#ngProgress-container {
908+
position: fixed;
909+
margin: 0;
910+
padding: 0;
911+
top: 0;
912+
left: 0;
913+
right: 0;
914+
z-index: 99999;
915+
}
916+
917+
885918
// Helper elements
886919
//
887920
// Helper elements are meant to be used for displaying various attributes that

0 commit comments

Comments
 (0)