PHP Classes

File: test/test-alignment.php

Recommend this page to a friend!
  Classes of Nikos M.   Grammar Template   test/test-alignment.php   Download  
File: test/test-alignment.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Grammar Template
Template engine in PHP and other languages
Author: By
Last change:
Date: 4 years ago
Size: 1,724 bytes
 

Contents

Class file image Download
<?php
include "../src/php/GrammarTemplate.php";
function
echo_($s='')
{
    echo
$s . PHP_EOL;
}

echo_('GrammarTemplate.VERSION = ' . GrammarTemplate::VERSION);
echo_();

$tpl = "<:BLOCK>:=[BLOCK <.name>\n{\n[ <@.blocks:BLOCKS>?\n]}]<:BLOCKS>:=[<@block:BLOCK>[\n<@block:BLOCK>*]]<@blocks:BLOCKS>";

$aligned = new GrammarTemplate($tpl, null, true);

echo_("input template:");
echo_($tpl);

echo_( );

echo_("output:");
echo_($aligned->render((object)array(
   
'blocks' => array(
    array(
       
'name' => "block1",
       
'blocks' => null
   
),
    array(
       
'name' => "block2",
       
'blocks' => array(
            array(
               
'name' => "block21",
               
'blocks' => array(
                    array(
                       
'name' => "block211",
                       
'blocks' => array(
                            array(
                               
'name' => "block2111",
                               
'blocks' => null
                           
),
                            array(
                               
'name' => "block2112"
                           
)
                        )
                    ),
                    array(
                       
'name' => "block212"
                   
)
                )
            ),
            array(
               
'name' => "block22",
               
'blocks' => array(
                    array(
                       
'name' => "block221"
                   
),
                    array(
                       
'name' => "block222"
                   
)
                )
            )
        )
    ),
    array(
       
'name' => "block3"
   
)
)
)));