示例#1
0
文件: Proust.php 项目: sebcode/proust
 $m = new Proust\Proust($options);
 $methods = array();
 $code = "";
 foreach ($files as $file) {
     $tpl = file_get_contents($file);
     if (_getopt($opts, "c")) {
         /* store method name and code */
         array_push($methods, array(filenameToFunctionName($file), $tpl));
     } else {
         if (_getopt($opts, "e")) {
             var_dump($m->render($tpl, $context));
         } else {
             if (_getopt($opts, "t")) {
                 $code .= "Tokens for {$file}:\n" . print_r($m->getTokens($tpl), true) . "\n";
             } else {
                 $code .= $m->compile($tpl, null, array("type" => "function", "name" => filenameToFunctionName($file))) . "\n";
             }
         }
     }
 }
 if (_getopt($opts, "c")) {
     $className = $opts['c'];
     $method = filenameToFunctionName($files[0]);
     $code = $m->compileClass($className, $methods);
     if (_getopt($opts, "e")) {
         eval($code);
         $obj = new $className();
         print $obj->{$method}($context);
         die;
     }
 }
示例#2
0
<?php

/* compile some templates */
require_once dirname(__FILE__) . "/../Proust.php";
$p = new Proust\Proust(array("templatePath" => dirname(__FILE__) . "/templates/", "compilerOptions" => array("beautify" => true)));
$p->partials = array("partial" => "{{#section}}{{bla}}{{/section}}");
$tpl = <<<'EOT'
{{#foo}}{{bla}}{{/foo}}
{{>partial}}
EOT;
echo "\n\n\nCode:\n-----\n\n";
echo $p->compile($tpl);
echo "\n\n";
$p->compilerOptions = array("includePartialCode" => true);
echo "\n\n\nCode with included partials:\n----------------------------\n\n";
echo $p->compile($tpl);
echo "\n\n";
$p->compilerOptions = array("disableLambdas" => true);
echo "\n\n\nCode with disabled lambdas:\n---------------------------\n\n";
echo $p->compile($tpl);
echo "\n\n";
$p->compilerOptions = array("disableIndentation" => true);
echo "\n\n\nCode with disabled indentation:\n-------------------------------\n\n";
echo $p->compile($tpl);
echo "\n\n";