1 var Class = require("../lib/mootools/mootools-node.js").Class;
  2 var Event = require('../lib/core/event/Event.js').Event;
  3 var Template = require('../lib/Template.js').Template;
  4 var stylus = require('stylus');
  5 
  6 
  7 /**
  8  * @class StylusTemplate Stylus engine implementation. Do not use it !!!
  9  * @deprecated This is only proof of concept Class. Currently unstable not for production use
 10  * @extends Template
 11  * @require Class | Event | Template | stylus
 12  */
 13 var StylusTemplate = function(){
 14 
 15     /** @ignore */
 16     this.Extends = Template;
 17 
 18     /**
 19      * Executing stylus template rendering
 20      * @param {Object}
 21      */
 22     this.render = function(data){
 23         if(!GLOBAL.hasOwnProperty('stylus') || !GLOBAL['stylus'].hasOwnProperty(this._configuration.template)){
 24             throw "Template: " + this._configuration.template + " doesn't exist";
 25         }
 26 
 27         // create new stylus object passing stylus css source code
 28         var stylusInstance = stylus(GLOBAL['stylus'][this._configuration.template]);
 29 
 30         // setting mock filename for better error reporting
 31         stylusInstance.set('filename', this._configuration.template);
 32 
 33         // defining stylesheet variables
 34         if(data && data.hasOwnProperty('data')){
 35             for(var dataKey in data.data ){
 36                 if(data.data.hasOwnProperty(dataKey)){
 37                     stylusInstance.define(dataKey, new stylus.nodes.Unit(data.data[dataKey]));
 38                 }
 39             }
 40         }
 41 
 42         // rendering stylesheet template
 43         var that = this;
 44         stylusInstance.render(function(err, css){
 45             if(err) throw err;
 46             that.setRenderedData(css);
 47         });
 48         
 49     };
 50 
 51 };
 52 
 53 StylusTemplate = new Class(new StylusTemplate());
 54 exports.StylusTemplate = StylusTemplate;