Skip to content

Commit

Permalink
feat(directive): prompt for style file creation
Browse files Browse the repository at this point in the history
  • Loading branch information
meriadec committed Mar 10, 2015
1 parent eff21d3 commit a24ea96
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
31 changes: 31 additions & 0 deletions directive/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 @@ -19,8 +25,14 @@ var BangularGenerator = yeoman.generators.NamedBase.extend({
name: 'template',
message: 'Do this directive needs an html template?',
default: false
}, {
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.needTemplate = props.template;
self.import = props.import;
done();
});

Expand All @@ -37,6 +49,25 @@ var BangularGenerator = yeoman.generators.NamedBase.extend({
this.template('directive.html', basePath + '.html');
}

if (this.import) {

this.template('style.scss', basePath + '.scss');

genUtils.appendNeedleOrOnTop({
needle: '// imports',
file: 'client/styles/app.scss',
append: '@import "../directives/' + 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
Empty file added directive/templates/style.scss
Empty file.
19 changes: 19 additions & 0 deletions test/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ describe('Launching directive tests', function () {
});
});

it('should create a file with a style', function (done) {
bangDirective = helpers.createGenerator('bangular:directive', [bangDir + '/directive'], 'flammenkuche');
helpers.mockPrompt(bangDirective, { import: true });
bangDirective.run(function () {
assert.file('client/directives/flammenkuche/flammenkuche.directive.js');
assert.file('client/directives/flammenkuche/flammenkuche.spec.js');
assert.file('client/directives/flammenkuche/flammenkuche.scss');

assert.fileContent('client/directives/flammenkuche/flammenkuche.directive.js', '.directive(\'flammenkuche\', function () {');
assert.fileContent('client/directives/flammenkuche/flammenkuche.spec.js', 'angular.element(\'<flammenkuche></flammenkuche>\');');

setTimeout(function () {
assert.fileContent('client/styles/app.scss', '@import "../directives/flammenkuche/flammenkuche";');
done();
}, 250);

});
});

});

});

0 comments on commit a24ea96

Please sign in to comment.