'use strict';

// Requirements
const JspRenderer = require('entoj-export-jsp').export.JspRenderer;


/**
 * @memberOf export
 * @extends export.Renderer
 */
class CmRenderer extends JspRenderer
{
    /**
     * @inheritDocs
     */
    static get className()
    {
        return 'export/CmRenderer';
    }


    /**
     * @inheritDocs
     */
    renderPreface(configuration)
    {
        const promise = super.renderPreface(configuration)
            .then((source) =>
            {
                source+= '<%@ taglib prefix="cm" uri="http://www.coremedia.com/2004/objectserver-1.0-2.0"%>';
                source+= '<%@ taglib prefix="bp" uri="http://www.coremedia.com/2012/blueprint"%>';
                source+= '<!-- <%--@elvariable id="settingsService" type="com.coremedia.blueprint.base.settings.SettingsService"--%> -->';
                return source;
            });
        return promise;
    }


    /**
     * @inheritDocs
     */
    static get injections()
    {
        return { 'parameters': ['export/CmRenderer.nodeRenderers', 'export/CmRenderer.options'] };
    }
}


// Exports
module.exports.CmRenderer = CmRenderer;

@@ -476,24 +476,160 @@
           %7B%0A
+                return configuration.getMacroConfiguration(configuration.macro.name).then((macroConfiguration) =%3E%0A                %7B%0A    
             
@@ -722,24 +722,28 @@
 .0-2.0%22%25%3E';%0A
+    
             
@@ -837,32 +837,36 @@
                 
+    
 source+= '%3C!-- %3C
@@ -992,21 +992,471 @@
     
-return source
+    if(macroConfiguration && macroConfiguration.namespace && macroConfiguration.type)%7B%0A                        source+='%3C!-- %3C%25--@elvariable id=%22self%22 type=%22' + macroConfiguration.namespace + '.' + macroConfiguration.type + '%22--%25%3E --%3E';%0A                        source+='%3C!-- %3C%25--@elvariable id=%22model%22 type=%22' + macroConfiguration.namespace + '.' + macroConfiguration.type + '%22--%25%3E --%3E';%0A                    %7D%0A                    return source;%0A                %7D)
 ;%0A  

add elvariables for self and model