Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/FoolCode/Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagrant committed Dec 17, 2012
2 parents 91125a8 + c50cc36 commit c2f084a
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 7 deletions.
121 changes: 120 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,123 @@ From the View you can bubble up to the Loader, grab the global parameters, enter
Other features:

* Child themes: Instead of having to duplicate the entire theme directory, you can extend another and fallback on its files. You can also extend a theme that by itself extends another, without depth limit.
* Asset Manager: compile LESS files on the fly.
* Asset Manager: compile LESS files on the fly.


## Classes

#### Theme

The Theme object abstracts the content of the theme. These will be returned by the Loader, and you will be able to choose which to use.

* __$theme->createBuilder()__

Returns a new builder. It's used to create the HTML.

* __$theme->createAssetManager()__

Returns a new asset manager. It's used to load and edit the content of the package that the user will download, like stylesheets and images.

#### Builder

The builder is used to create the HTML. It divides the job between layouts and partials, and provides a global parameter manager.

* __$builder->getTheme()__

Returns the Theme that generated this builder object.

* __$builder->getParamManager()__

Returns the parameter manager used to hold parameters for the views.

* __$builder->createLayout($view)__

* string _$view_ - The name of the layout with underscores

Sets the layout and returns the View object.

* __$builder->createPartial($name, $view)__

* string _$name_ - A given name for the partial
* string _$view_ - The name of the layout with underscores

Sets a partial with the given $name, and returns the View object.

* __$builder->getLayout()__

Returns the currently set Layout.

* __$builder->getPartial($name)__

* string _$name_ - The given name of the partial

Returns the partial with the given name.

* __$builder->build()__

Builds the entire HTML with the given parameters.

#### Parameter Manager

Parameter managers are used to consistently store variables for being used in the theme. The Builder owns a global one, and every View has a local one.

* __$pm->reset()__

Resets the object to its original state.

* __$pm->getParams()__

Returns an array of parameters.

* __$pm->getParam($key)__

* string _$key_ - The key for the value

Returns the value stored with $key.

__Throws:__ _\OutOfBoundsException_ - If the value was not set

* __$pm->setParam($key, $value)__

* string _$key_ - The key for the value
* mixed _$value_ - The value

Sets a parameter

* __$pm->setParams($array)__

* array _$array_ - An array of parameters to set

Takes an array and inserts every single parameter. Doesn't delete previous parameters.

#### View

The View returned by the Builder is most often a custom object extending \Foolz\Theme\View.

__It's compulsory to override the `toString()` method (not the `__toString()` magic method!) in order to output the HTML. This function should output HTML or return a string.__

* __$view->toString()__

Called when the HTML must be generated. It should contain the classic HTML building logic. `$this` can be used. No manual output buffering is necessary.

* __$view->getType()__

Returns the type of View. `layout` or `partial`.

* __$view->getView()__

Returns the name of the View.

* __$view->getParamManager()__

Returns the local parameter manager.

* __$view->build()__

Builds _and cached_ the HTML. Returns the HTML.

* __$view->doBuild()__

Builds the HTML and stores it in a variable. Rebuilds the HTML every time it's called.

__CHAINABLE__
4 changes: 2 additions & 2 deletions classes/Foolz/Theme/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public function getPartial($name)
* @return string The content generated
* @throws \OutOfBoundsException If the layout wasn't selected
*/
public function get()
public function build()
{
return $this->getLayout()->get();
return $this->getLayout()->build();
}
}
2 changes: 1 addition & 1 deletion classes/Foolz/Theme/ParamManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ParamManager
*/
public function reset()
{
$this->params = [];;
$this->params = [];
return $this;
}

Expand Down
6 changes: 3 additions & 3 deletions classes/Foolz/Theme/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ public function getParamManager()
*
* @return string The compiled view
*/
public function get()
public function build()
{
if ($this->built === null)
{
$this->build();
$this->doBuild();
}

return $this->built;
Expand All @@ -171,7 +171,7 @@ public function get()
*
* @return \Foolz\Theme\View The current object
*/
public function build()
public function doBuild()
{
$this->built = $this->toString();

Expand Down

0 comments on commit c2f084a

Please sign in to comment.