'use strict';
var util = require('util');
var yeoman = require('yeoman-generator');
var fs = require('fs');
var path = require('path');
var capitalize = function(name){
  return name[0].toUpperCase() + name.slice(1,name.length);
}

var CollectionGenerator = module.exports = function ModelGenerator(args, options, config) {

  // By calling `NamedBase` here, we get the argument to the subgenerator call
  // as `this.name`.
  yeoman.generators.NamedBase.apply(this, arguments);
  console.log('You called the collection subgenerator with the argument ' + this.name + '.');
};

util.inherits(CollectionGenerator, yeoman.generators.NamedBase);
CollectionGenerator.prototype.askFor = function askFor() {
  var cb = this.async();
  var prompts = [{
    name: 'modelName',
    message: "What model do you want to link with collection (without \"Model\" postfix)?",
    default: this.name
  }];
  this.prompt(prompts, function (props) {
    this.model_name = capitalize(props.modelName) + "Model";
    cb();
  }.bind(this));
}

CollectionGenerator.prototype.files = function files() {
    this.normalize_name = capitalize(this.name) + "Collection"
    this.copy('collection.coffee',  'app/scripts/collection/' + this.normalize_name + '.coffee');
}

@@ -738,16 +738,37 @@
 ts = %5B%7B%0A
+    type: %22confirm%22,%0A
     name
@@ -775,19 +775,24 @@
 : 'model
-Nam
+_generat
 e',%0A    
@@ -807,81 +807,59 @@
  %22Wh
-at model do you want to link with collection (without %5C%22Model%5C%22 postfix)?
+ould ypu like generate model %22 + this.name + %22Model
 %22,%0A 
@@ -871,23 +871,18 @@
 fault: t
-his.nam
+ru
 e%0A  %7D%5D;%0A
@@ -949,45 +949,75 @@
 e = 
-capitalize(props.modelName) + %22Model%22
+this.name + %22Model%22;%0A    this.model_generate = props.model_generate
 ;%0A  
@@ -1262,10 +1262,111 @@
 ffee');%0A
+    if(this.model_generate)%7B%0A      this.invoke(%22sp:model%22,%7B%0A        args:%5Bthis.name%5D%0A      %7D);%0A    %7D%0A
 %7D%0A

update collection