示例#1
0
<?php

/* simple hello world */
require_once dirname(__FILE__) . "/../Proust.php";
$p = new Proust\Proust();
echo $p->render("Hello {{planet}}\n", array("planet" => "World"));
示例#2
0
文件: Proust.php 项目: sebcode/proust
 }
 if (_getopt($opts, "p")) {
     $options["templatePath"] = _getopt($opts, "p");
 }
 $options["compilerOptions"] = $compilerOptions;
 $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);
示例#3
0
<?php

/* canonical mustache template */
require_once dirname(__FILE__) . "/../Proust.php";
$p = new Proust\Proust();
$tpl = <<<'EOD'
Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{taxed_value}}, after taxes.
{{/in_ca}}

EOD;
class Chris
{
    public $name = "Chris";
    public $value = 10000;
    public $in_ca = true;
    public function taxed_value()
    {
        return $this->value - $this->value * 0.4;
    }
}
echo $p->render($tpl, new Chris());