'use strict';

var through = require('through2');
var utils = require('../utils');

module.exports = function init_() {
  var verb = this, id = this.gettask();

  // create a template type for vinyl files
  if (!verb.hasOwnProperty(id)) {
    verb.create(id, ['task']);
  }

  return through.obj(function (file, enc, cb) {
    if (file.isNull()) {
      this.push(file);
      return cb();
    }
    if (file.isStream()) {
      this.emit('error', new utils.PluginError('verb/plugins/init:', 'Streaming is not supported.'));
      return cb();
    }

    // Convert vinyl file to verb template and add to collection
    verb[id](file);
    cb();
  }, function (cb) {
    var plural = verb.collection[id];
    pushToStream(verb.views[plural], this);
    cb();
  });
};

function pushToStream(collection, stream, fn) {
  var files = Object.keys(collection);
  var len = files.length;
  var i = 0;

  while (i < len) {
    var name = files[i++];
    var file = collection[name];
    stream.push(fn ? fn(file) : file);
  }
}

@@ -8,16 +8,46 @@
 rict';%0A%0A
+var chalk = require('chalk');%0A
 var thro
@@ -227,16 +227,37 @@
 yl files
+ and give it a loader
 %0A  if (!
@@ -749,16 +749,80 @@
 on%5Bid%5D;%0A
+    // Convert template back to vinyl file and push into stream%0A
     push
@@ -935,28 +935,33 @@
 var 
-files = Object.keys(
+i = 0;%0A  for (var key in 
 coll
@@ -971,97 +971,55 @@
 ion)
-;%0A  var len = files.length;%0A  var i = 0;%0A%0A  while (i %3C len) %7B%0A    var name = files%5Bi++%5D;%0A
+ %7B%0A    if (collection.hasOwnProperty(key)) %7B%0A  
     
@@ -1044,15 +1044,16 @@
 ion%5B
-name
+key
 %5D;%0A
+  
     
@@ -1076,16 +1076,21 @@
  fn(file
+, i++
 ) : file
@@ -1092,14 +1092,20 @@
  file);%0A
+    %7D%0A
   %7D%0A%7D%0A

use `for in` on `pushToStream`