Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
Formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
greut committed Apr 14, 2012
1 parent e0de27e commit ebdb887
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class Template {
private $inherits = array();
private $blocks = array();
private $blocknames = array();
//private $caches = array();
private $caches = array();
private $args = array();
public $globals = array();

function __construct($base, $globals=null, $ext=".tpl.php") {
function __construct($base, $globals = null, $ext = ".tpl.php") {
$this->paths[] = $base."/";
$this->ext = $ext;

Expand Down Expand Up @@ -73,18 +73,21 @@ function endblock() {
switch($this->blocks[$blockname]["mode"]) {
case "before":
case "prepend":
$this->blocks[$blockname] = array("content" => $this->blocks[$blockname]["content"].ob_get_contents(),
"mode" => $mode);
$this->blocks[$blockname] = array(
"content" => $this->blocks[$blockname]["content"] . ob_get_contents(),
"mode" => $mode
);
break;
case "after":
case "append":
$this->blocks[$blockname] = array("content" => ob_get_contents().$this->blocks[$blockname]["content"],
"mode" => $mode);

$this->blocks[$blockname] = array(
"content" => ob_get_contents() . $this->blocks[$blockname]["content"],
"mode" => $mode
);
break;
}
}

ob_end_clean();

if($mode === "replace") {
Expand All @@ -111,20 +114,20 @@ function cache($name, $ttl=3600) {

function endcache() {
$data = ob_get_contents();

ob_end_clean();

list($key, $ttl) = array_pop($this->caches);
apc_store($key, $data, $ttl);
echo $data;
}

function __call($name, $arguments) {
// take current context
$base = $this->paths[count($this->paths)-1];
$base = $this->paths[count($this->paths) - 1];
$path = dirname($name);
if($path !== ".") {
$base .= $path."/";
$base .= $path . "/";
$name = basename($name);
}
// push current context
Expand All @@ -138,7 +141,7 @@ function __call($name, $arguments) {
}

$args = array_merge((array)$this->globals, $arguments[0]);

$this->file = $file;
$this->inherits[$file] = array();
// used by the placeholder
Expand All @@ -152,18 +155,19 @@ function __call($name, $arguments) {
$args = array_shift($this->args);
$content = ob_get_contents();
ob_end_clean();

while($inherit = array_pop($this->inherits[$file])) {
$content = $this->{$inherit}($args);
}

// pop the context
array_pop($this->paths);

return $content;
} else {
throw new Exception("File not found (".$file.")");
throw new Exception("File not found ($file)");
}
}
}

?>

0 comments on commit ebdb887

Please sign in to comment.