예제 #1
0
#!/usr/bin/env php
<?php 
require dirname(__FILE__) . "/jsontemplate.php";
if (count($argv) <= 1) {
    print "usage: " . $argv[0] . " 'Hello [var]!' '{\"var\":\"World\"}' '{\"meta\":\"[]\"}'\n";
}
if (isset($argv[2])) {
    $data = json_decode($argv[2]);
} else {
    $data = array();
}
if (isset($argv[3])) {
    $options = json_decode($argv[3]);
} else {
    $options = array();
}
try {
    print JsonTemplateModule::expand($argv[1], $data, $options);
} catch (Exception $e) {
    $class = preg_replace('/^JsonTemplate/', '', get_class($e));
    print "EXCEPTION: " . $class . ": " . $e->getMessage() . "\n";
}
 function testNestedRepeatedSections()
 {
     $t = "\n[header]\n---------\n[.section people]\n[.repeated section @]\n  [name]: [.repeated section attributes][@] [.end]\n[.end][.end]";
     $d = array('header' => 'People', 'people' => array(array('name' => 'Andy', 'attributes' => array('jerk', 'cool')), array('name' => 'Bob', 'attributes' => array('nice', 'mean', 'fun'))));
     $e = "\nPeople\n---------\n  Andy: jerk cool \n  Bob: nice mean fun \n";
     $o = array('meta' => '[]');
     $this->assertEquals(JsonTemplateModule::expand($t, $d, $o), $e);
 }