var Template = require('./template')
    , Resource = require('./resource');

function Stack(name, description) {
    if (!(this instanceof Stack)) {
        return new Stack(name);
    }

    this.name = name;
    this.description = description;
    this.templates = [];
}

Stack.prototype.add = function(template) {
    if (!(template instanceof Template)) {
        throw new Error('template must be instanceof Template');
    }

    this.templates.push(template);
}

Stack.prototype.toJson = function() {
    var cft = Template();
    this.templates.forEach(function(template) {
        for (key in template.resources) {
            cft.addResource(template.resources[key]);
        }
        for (key in template.outputs) {
            cft.addOutput(template.outputs[key]);
        }
    });
    return cft.toJson(this.description);
}

module.exports = Stack;
@@ -520,19 +520,138 @@
 t = 
-Template();
+%7B%0A        AWSTemplateFormatVersion: '2010-09-09'%0A    %7D;%0A%0A    if (this.description) %7B%0A        cft.Description = description;%0A    %7D%0A
 %0A   
@@ -757,20 +757,74 @@
 cft.
-addResource(
+Resources = cft.Resources %7C%7C %7B%7D;%0A            cft.Resources%5Bkey%5D = 
 temp
@@ -838,24 +838,34 @@
 sources%5Bkey%5D
+.toObject(
 );%0A        %7D
@@ -861,24 +861,25 @@
 ;%0A        %7D%0A
+%0A
         for 
@@ -926,18 +926,68 @@
 cft.
-add
 Output
-(
+s = cft.Outputs %7C%7C %7B%7D;%0A            cft.Outputs%5Bkey%5D = 
 temp
@@ -1003,16 +1003,26 @@
 uts%5Bkey%5D
+.toObject(
 );%0A     
@@ -1034,16 +1034,17 @@
     %7D);%0A
+%0A
     retu
@@ -1050,35 +1050,352 @@
 urn 
-cft.toJson(this.description
+JSON.stringify(cft, function(key, value) %7B%0A        if (typeof value === 'boolean') %7B%0A            return value.toString();%0A        %7D%0A%0A        if (typeof value === 'number') %7B%0A            return value.toString();%0A        %7D%0A%0A        if (value instanceof Resource) %7B%0A            return %7B Ref: value.name %7D;%0A        %7D%0A%0A        return value;%0A    %7D, 2
 );%0A%7D

Make novaform stack output the full stack json instead of the template