1 // ==========================================================================
  2 // Project:   SproutCore - JavaScript Application Framework
  3 // Copyright: ©2006-2011 Strobe Inc. and contributors.
  4 //            Portions ©2008-2011 Apple Inc. All rights reserved.
  5 // License:   Licensed under MIT license (see license.js)
  6 // ==========================================================================
  7 
  8 
  9 /** 
 10   Extend `SC.Page` to emit a design document for the entire page.
 11 */
 12 SC.Page.prototype.emitDesign = function() {
 13 
 14   // awake all views.  this is needed to emit the design for them.
 15   this.awake();
 16 
 17   // the pageName must be set on the page so we can emit properly
 18   var pageName = this.get('pageName');
 19   
 20   // now encode the page.
 21   var ret = SC.DesignCoder.encode(this);
 22   
 23   // and add some wrapper
 24   ret = ['// SproutCore ViewBuilder Design Format v1.0',
 25     '// WARNING: This file is automatically generated.  DO NOT EDIT.  Changes you',
 26     '// make to this file will be lost.', '',
 27     '%@ = %@;'.fmt(pageName, ret),''].join("\n");
 28   
 29   return ret ;
 30 };
 31 
 32 /**
 33   Extend `SC.Page` to create a `PageDesignController` on demand.
 34   
 35   @property {SC.PageDesignController}
 36 */
 37 SC.Page.prototype.designController = function() {
 38   if (!this._designController) {
 39     this._designController = SC.PageDesignController.create({ page: this });
 40   }
 41   return this._designController ;
 42 }.property().cacheable();
 43 
 44 /** @private implement support for encoders */
 45 SC.Page.prototype.encodeDesign = function(c) {
 46   // step through and find all views.  encode them.
 47   for(var key in this) {
 48     if(!this.hasOwnProperty(key)) continue;
 49     var view = this[key];
 50     if (key !== '__sc_super__' && key !== '_designController' &&
 51         (view instanceof SC.View || view instanceof SC.Controller || view instanceof SC.Object)){
 52      c.js(key, view.emitDesign());      
 53     }
 54   }
 55   
 56   // save page name;
 57   c.string('pageName', this.get('pageName'));
 58 };
 59   
 60 
 61