Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

Commit

Permalink
refactor(service-generator): fix break in Angular-Sub-Generator API o…
Browse files Browse the repository at this point in the history
…f service-generator, remove argument --type and create own generators for each type
  • Loading branch information
robinboehm authored and btford committed Jun 26, 2013
1 parent 54edc9d commit 5b6a4b6
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 20 deletions.
9 changes: 9 additions & 0 deletions constant/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Description:
Creates a new AngularJS service.
Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services

Example:
yo angular:constant thing [--coffee] [--minsafe]

This will create:
app/scripts/services/thing.js
20 changes: 20 additions & 0 deletions constant/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
var path = require('path');
var util = require('util');
var ScriptBase = require('../script-base.js');
var angularUtils = require('../util.js');


module.exports = Generator;

function Generator() {
ScriptBase.apply(this, arguments);
}

util.inherits(Generator, ScriptBase);

Generator.prototype.createServiceFiles = function createServiceFiles() {
this.appTemplate('service/constant', 'scripts/services/' + this.name);
this.testTemplate('spec/service', 'services/' + this.name);
this.addScriptToIndex('services/' + this.name);
};
9 changes: 9 additions & 0 deletions factory/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Description:
Creates a new AngularJS service.
Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services

Example:
yo angular:factory thing [--coffee] [--minsafe]

This will create:
app/scripts/services/thing.js
20 changes: 20 additions & 0 deletions factory/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
var path = require('path');
var util = require('util');
var ScriptBase = require('../script-base.js');
var angularUtils = require('../util.js');


module.exports = Generator;

function Generator() {
ScriptBase.apply(this, arguments);
}

util.inherits(Generator, ScriptBase);

Generator.prototype.createServiceFiles = function createServiceFiles() {
this.appTemplate('service/factory', 'scripts/services/' + this.name);
this.testTemplate('spec/service', 'services/' + this.name);
this.addScriptToIndex('services/' + this.name);
};
9 changes: 9 additions & 0 deletions provider/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Description:
Creates a new AngularJS service.
Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services

Example:
yo angular:provider thing [--coffee] [--minsafe]

This will create:
app/scripts/services/thing.js
20 changes: 20 additions & 0 deletions provider/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
var path = require('path');
var util = require('util');
var ScriptBase = require('../script-base.js');
var angularUtils = require('../util.js');


module.exports = Generator;

function Generator() {
ScriptBase.apply(this, arguments);
}

util.inherits(Generator, ScriptBase);

Generator.prototype.createServiceFiles = function createServiceFiles() {
this.appTemplate('service/provider', 'scripts/services/' + this.name);
this.testTemplate('spec/service', 'services/' + this.name);
this.addScriptToIndex('services/' + this.name);
};
21 changes: 1 addition & 20 deletions service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,12 @@ module.exports = Generator;

function Generator() {
ScriptBase.apply(this, arguments);

var allowedTypes = [
'constant',
'factory',
'provider',
'service',
'value'
];

this.argument('type', {
type: String,
defaults: 'factory',
banner: '[type]',
required: false
});

if (allowedTypes.indexOf(this.type) === -1) {
this.type = 'factory';
}
}

util.inherits(Generator, ScriptBase);

Generator.prototype.createServiceFiles = function createServiceFiles() {
this.appTemplate(path.join('service', this.type), 'scripts/services/' + this.name);
this.appTemplate('service/service', 'scripts/services/' + this.name);
this.testTemplate('spec/service', 'services/' + this.name);
this.addScriptToIndex('services/' + this.name);
};
9 changes: 9 additions & 0 deletions value/USAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Description:
Creates a new AngularJS service.
Docs: http://docs.angularjs.org/guide/dev_guide.services.creating_services

Example:
yo angular:value thing [--coffee] [--minsafe]

This will create:
app/scripts/services/thing.js
20 changes: 20 additions & 0 deletions value/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
var path = require('path');
var util = require('util');
var ScriptBase = require('../script-base.js');
var angularUtils = require('../util.js');


module.exports = Generator;

function Generator() {
ScriptBase.apply(this, arguments);
}

util.inherits(Generator, ScriptBase);

Generator.prototype.createServiceFiles = function createServiceFiles() {
this.appTemplate('service/constant', 'scripts/services/' + this.name);
this.testTemplate('spec/service', 'services/' + this.name);
this.addScriptToIndex('services/' + this.name);
};

0 comments on commit 5b6a4b6

Please sign in to comment.