Skip to content

Commit 6075505

Browse files
hannuHannu Pelkonen
authored andcommitted
Merge pull request SC5#137 from varya/features/gonzales-4-writing
Use real parser to update changed variables to source SASS/LESS file
2 parents 84bd3d6 + a9819c1 commit 6075505

File tree

16 files changed

+389
-156
lines changed

16 files changed

+389
-156
lines changed

README.md

Lines changed: 12 additions & 34 deletions
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

Lines changed: 5 additions & 26 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 18 additions & 32 deletions
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/js/app.js

Lines changed: 2 additions & 1 deletion
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/main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
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

9+
ngProgress.height('4px');
10+
911
$scope.isNavCollapsed = false;
1012

1113
// Because localStorage only saves String type values, try to convert to boolean
@@ -71,6 +73,14 @@ angular.module('sgApp')
7173
};
7274
});
7375

76+
$scope.$on('progress start', function() {
77+
ngProgress.start();
78+
});
79+
80+
$scope.$on('progress end', function() {
81+
ngProgress.complete();
82+
});
83+
7484
$scope.$on('styles changed', function() {
7585
var links = document.getElementsByTagName('link');
7686
for (var l in links) {

lib/app/js/services/Variables.js

Lines changed: 5 additions & 1 deletion
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
}
Lines changed: 14 additions & 7 deletions
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: 50px;

lib/app/sass/app.scss

Lines changed: 1 addition & 2 deletions
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;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Styling for the ngProgress itself */
2+
#ngProgress {
3+
margin: 0;
4+
padding: 0;
5+
z-index: 99998;
6+
background-color: green;
7+
color: green;
8+
box-shadow: 0 0 10px 0; /* Inherits the font color */
9+
height: 10px;
10+
opacity: 0;
11+
12+
/* Add CSS3 styles for transition smoothing */
13+
-webkit-transition: all 0.5s ease-in-out;
14+
-moz-transition: all 0.5s ease-in-out;
15+
-o-transition: all 0.5s ease-in-out;
16+
transition: all 0.5s ease-in-out;
17+
}
18+
19+
/* Styling for the ngProgress-container */
20+
#ngProgress-container {
21+
position: fixed;
22+
margin: 0;
23+
padding: 0;
24+
top: 0;
25+
left: 0;
26+
right: 0;
27+
z-index: 99999;
28+
}

0 commit comments

Comments
 (0)