Skip to content

Commit

Permalink
feat(route): create & import style associated to view
Browse files Browse the repository at this point in the history
  • Loading branch information
meriadec committed Feb 27, 2015
1 parent 92829bb commit 7e90a4a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ gulp.task('watch', ['inject'], function () {
gulp.watch(['client/index.html', 'client/app.js'])
.on('change', $.livereload.changed);

$.watch('client/styles/**/*.scss', function () {
$.watch(['client/styles/**/*.scss', 'client/views/**/*.scss'], function () {
gulp.src('client/styles/app.scss')
.pipe($.plumber())
.pipe($.sass())
Expand All @@ -104,6 +104,7 @@ gulp.task('watch', ['inject'], function () {
'client/views',
'client/views/**/*.html',
'client/views/**/*.js',
'!client/views/**/*.scss',
'!client/views/**/*.spec.js',
'client/directives',
'client/directives/**/*.html',
Expand Down
38 changes: 38 additions & 0 deletions route/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
'use strict';

var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var genUtils = require('../util');

function bangLog (msg, color) {
console.log('[' + chalk.blue('bangular') + ']: ' + chalk[color](msg));
}

var BangularGenerator = yeoman.generators.NamedBase.extend({

Expand All @@ -18,8 +24,14 @@ var BangularGenerator = yeoman.generators.NamedBase.extend({
name: 'route',
message: 'Choose an url route',
default: '/' + self.dashName
}, {
type: 'confirm',
name: 'import',
message: 'Do you want to create and import the ' + chalk.blue(this.dashName + '.scss') + ' style in your app.scss?',
default: false
}], function (props) {
self.route = props.route;
self.import = props.import;
done();
});
},
Expand Down Expand Up @@ -62,6 +74,32 @@ var BangularGenerator = yeoman.generators.NamedBase.extend({
+ '.html'
);

if (this.import) {

this.template(
'style.scss',
'client/views/'
+ this.dashName
+ '/'
+ this.dashName
+ '.scss'
);

genUtils.appendNeedleOrOnTop({
needle: '// imports',
file: 'client/styles/app.scss',
append: '@import "../views/' + this.dashName + '/' + this.dashName + '";'
}, function importCallback (err) {
/* istanbul ignore if */
if (err) {
bangLog('There was an error importing the style.', 'red');
} else {
bangLog('Your style was successfully injected.', 'green');
}
});

}

}

});
Expand Down
3 changes: 3 additions & 0 deletions route/templates/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/**
* <%= dashName %>.scss
*/

0 comments on commit 7e90a4a

Please sign in to comment.