Skip to content

Commit

Permalink
Fixes from real use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
woxxy committed Dec 26, 2012
1 parent ebd3e02 commit 126e0b7
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 3 deletions.
18 changes: 18 additions & 0 deletions classes/Foolz/Theme/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class Builder
*/
protected $param_manager;

/**
* Instance of a props object
*
* @var \Foolz\Theme\Props
*/
protected $props = null;

/**
* We need at least a theme
*
Expand All @@ -41,6 +48,7 @@ public function __construct(\Foolz\Theme\Theme $theme)
{
$this->theme = $theme;
$this->param_manager = new ParamManager();
$this->props = new Props();
}

/**
Expand All @@ -63,6 +71,16 @@ public function getParamManager()
return $this->param_manager;
}

/**
* Returns the props object to manage title, meta etc.
*
* @return \Foolz\Theme\Props The props object
*/
public function getProps()
{
return $this->props;
}

/**
* Set a layout that is going to wrap all the partials
*
Expand Down
4 changes: 2 additions & 2 deletions classes/Foolz/Theme/ParamManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function getParams()
*/
public function getParam($key)
{
if ( ! isset($this->params[$key]))
if ( ! array_key_exists($key, $this->params))
{
throw new \OutOfBoundsException('Undefined parameter.');
}
Expand Down Expand Up @@ -77,7 +77,7 @@ public function setParams($array)
{
$this->params[$key] = $item;
}

return $this;
}
}
114 changes: 114 additions & 0 deletions classes/Foolz/Theme/Props.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace Foolz\Theme;

class Props
{
/**
* Array of stings containing the elements of which the title is composed
*
* @var array
*/
protected $title = [];

/**
* The separator between the elements of which the title is composed
*
* @var string
*/
protected $title_separator = ' » ';

/**
* Array of arrays of <meta>. The content of the internal array are tag => value
*
* @var array
*/
/*
protected $meta_tags = [
['charset' => 'utf8'],
];
public function getHeader()
{
$string = ""
."<!doctype html>\n"
." <html>\n"
." <head>\n";
foreach ($this->meta_tags as $meta)
{
$string .= " <meta";
foreach ($meta as $tag => $value)
{
$string .= ' '.$tag.'="'.htmlspecialchars($value).'"';
}
$string .= ">\n";
}
$string .= " <title>".htmlspecialchars($this->getTitle())."</title>";
foreach ()
return $string;
}
public function getFooter()
{
}
*/

/**
* Set the entire array of the title. Empties the title if no parameter is given
*
* @param array $title The array of elements of which the title is composed
*
* @return \Foolz\Theme\Props The current object
*/
public function setTitle(array $title = [])
{
$this->title = $title;

return $this;
}

/**
* Adds an element to the title
*
* @param string $title The element to add to the title
*
* @return \Foolz\Theme\Props The current object
*/
public function addTitle($title)
{
$this->title[] = $title;

return $this;
}

/**
* Sets a string to use as separator between the elements of the title. It must contain eventual spaces around it
*
* @param string $separator The separator string
*
* @return \Foolz\Theme\Props The current object
*/
public function setTitleSeparator($separator)
{
$this->title_separator = $separator;

return $this;
}

/**
* Returns the compiled title, NOT ESCAPED
*
* @return string The compiled title
*/
public function getTitle()
{
return implode($this->title_separator, $this->title);
}


}
12 changes: 11 additions & 1 deletion classes/Foolz/Theme/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class View
*/
protected $builder;

/**
* Instance of a props object
*
* @var \Foolz\Theme\Props
*/
protected $props = null;

/**
* The type of view, if partial or layout
*
Expand Down Expand Up @@ -43,6 +50,7 @@ public static function forge(\Foolz\Theme\Builder $builder, $type, $view)
{
// get the View object in case it can be found
$class = $builder->getTheme()->getNamespace().'\\'. ucfirst($type).'\\'.Util::lowercaseToClassName($view);

if (class_exists($class))
{
$new = new $class();
Expand Down Expand Up @@ -173,7 +181,9 @@ public function build()
*/
public function doBuild()
{
$this->built = $this->toString();
ob_start();
$this->toString();
$this->built = ob_get_clean();

return $this;
}
Expand Down

0 comments on commit 126e0b7

Please sign in to comment.