コード例 #1
0
ファイル: RenderJsCompiler.php プロジェクト: JeCat/framework
    public function compile(IObject $aObject, ObjectContainer $aObjectContainer, TargetCodeOutputStream $aDev, CompilerManager $aCompilerManager)
    {
        $aObject instanceof \org\jecat\framework\ui\xhtml\Node;
        if (!($sFuncName = $aObject->attributes()->string('function'))) {
            throw new Exception("render:js 节点缺少function属性(line:%d)", $aObject->line());
        }
        $aDev->output(<<<JSCODE
<script>
// 模板渲染函数
function {$sFuncName}(aVariables)
{
\t// 输出缓存对像
\tvar aDevice = {
\t\t_buffer: ''
\t\t, write: function(data){
\t\t\tthis._buffer+= data ;
\t\t}
\t}
JSCODE
);
        // 指定的模板文件
        if ($aObject->attributes()->string('template')) {
        } else {
            if ($aObject->tailTag()) {
                $aChildCompiledBuff = new TargetCodeOutputStream();
                $aChildCompiledBuff->useHereDoc(false);
                $this->compileChildren($aObject, $aObjectContainer, $aChildCompiledBuff, $aCompilerManager);
                $aJsBuff = new OutputStreamBuffer();
                JavascriptTranslaterFactory::singleton()->create()->compile(new InputStreamCache('<?php ' . $aChildCompiledBuff->bufferBytes(false)), $aJsBuff);
                $aDev->output($aJsBuff);
            } else {
            }
        }
        $aDev->output(<<<JSCODE

\treturn aDevice._buffer ;
}
</script>\t\t\t
JSCODE
);
    }