Skip to content

Commit

Permalink
Made jQuery optional
Browse files Browse the repository at this point in the history
  • Loading branch information
danrouse committed Jun 15, 2015
1 parent 3ae927d commit 9e41f20
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
13 changes: 12 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ module.exports = generators.Base.extend({
value: 'includeModernizr',
checked: true
}]
}, {
type: 'confirm',
name: 'includeJQuery',
message: 'Would you like to include jQuery?',
default: true,
when: function (answers) {
return answers.features.indexOf('includeBootstrap') === -1;
}
}];

this.prompt(prompts, function (answers) {
Expand All @@ -90,6 +98,7 @@ module.exports = generators.Base.extend({
this.includeSass = hasFeature('includeSass');
this.includeBootstrap = hasFeature('includeBootstrap');
this.includeModernizr = hasFeature('includeModernizr');
this.includeJQuery = answers.includeJQuery;

done();
}.bind(this));
Expand Down Expand Up @@ -143,7 +152,8 @@ module.exports = generators.Base.extend({
name: _s.slugify(this.appname),
includeSass: this.includeSass,
includeBootstrap: this.includeBootstrap,
includeModernizr: this.includeModernizr
includeModernizr: this.includeModernizr,
includeJQuery: this.includeJQuery
}
);
},
Expand Down Expand Up @@ -218,6 +228,7 @@ module.exports = generators.Base.extend({
includeSass: this.includeSass,
includeBootstrap: this.includeBootstrap,
includeModernizr: this.includeModernizr,
includeJQuery: this.includeJQuery,
bsPath: bsPath,
bsPlugins: [
'affix',
Expand Down
2 changes: 1 addition & 1 deletion app/templates/_bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"dependencies": {<% if (includeBootstrap) { if (includeSass) { %>
"bootstrap-sass": "~3.3.1"<% } else { %>
"bootstrap": "~3.3.1"<% }} else { %>
"bootstrap": "~3.3.1"<% }} else if (includeJQuery) { %>
"jquery": "~2.1.1"<% } if (includeModernizr) { %>,
"modernizr": "~2.8.1" <% } %>
}
Expand Down
3 changes: 2 additions & 1 deletion app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ <h1>'Allo, 'Allo!</h1>
<ul>
<li>HTML5 Boilerplate</li><% if (includeSass) { %>
<li>Sass</li><% } %><% if (includeModernizr) { %>
<li>Modernizr</li><% } %>
<li>Modernizr</li><% } %><% if (includeJQuery) { %>
<li>jQuery</li><% } %>
</ul>
</div>
<% } %>
Expand Down
2 changes: 1 addition & 1 deletion test/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Bootstrap feature', function () {
.on('end', done);
});

it('shoud add the correct dependencies', function () {
it('should add the correct dependencies', function () {
assert.fileContent('bower.json', '"bootstrap-sass"');
assert.noFileContent('bower.json', '"jquery"');
});
Expand Down
40 changes: 40 additions & 0 deletions test/jquery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';
var path = require('path');
var helpers = require('yeoman-generator').test;
var assert = require('yeoman-assert');

describe('jQuery feature', function () {
describe('on', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../app'))
.inDir(path.join(__dirname, 'temp'))
.withOptions({'skip-install': true})
.withPrompts({
features: [],
includeJQuery: true
})
.on('end', done);
});

it('should add the correct dependencies', function () {
assert.fileContent('bower.json', '"jquery"');
});
});

describe('off', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../app'))
.inDir(path.join(__dirname, 'temp'))
.withOptions({'skip-install': true})
.withPrompts({
features: [],
includeJQuery: false
})
.on('end', done);
});

it('should add the correct dependencies', function () {
assert.noFileContent('bower.json', '"jquery"');
});
});
});

0 comments on commit 9e41f20

Please sign in to comment.