Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
woxxy committed Dec 20, 2012
2 parents b9cb869 + 094007b commit 1acc702
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 29 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
Foolz PHP Theme system
=======================

A theme system that abuses OOP to give those features you always dreamed about.
A theme system that abuses OOP to give you those features you've always dreamed of.

You will need PHP 5.4 for this to work. You can install it through [Composer](http://getcomposer.org/) and [Packagist](https://packagist.org/packages/foolz/plugin).

## What a mess!

Foolz\Theme works upon Foolz\Plugin. This means it has inbuilt support for plugin-like stuff, and use it if you wish, or just forget about it. We use it plenty to allow re-skinning and hooking links on the interface.
Foolz\Theme works on top of Foolz\Plugin. This means it has built-in support for plugin-like stuff, that you can use or ignore at will. We use it to allow re-skinning and hooking links on the interface.

What we disliked about other theme systems is that they were nothing more than View managers, monolithic and raw.
We created our own Theme system because other theme systems were nothing more than View managers, monolithic and raw.

This package aims to use a multi-level approach to themes, where you can go up and down in the system and build components at the very last moment - by interacting with the theme in the theme itself. The structure is the following:
This package aims to use a multi-level approach to themes, where you can go up and down in the system and build components at the very last moment - by interacting with the theme directly. The structure goes like this:

* Loader
* Theme
* Builder -> Global Parameter Manager
* View -> Local Parameter Manager

From the View you can bubble up to the Loader, grab the global parameters, enter other partials, build them within the View.
From the View you can bubble up to the Loader, grab the global parameters, enter other partials, and build them within the View.

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.
* Child themes: Instead of having to duplicate the entire theme directory, you can extend another theme and fallback on its files. You can also extend from an extended theme, with no limit.
* Asset Manager: compile LESS files on the fly.


Expand Down Expand Up @@ -81,7 +81,7 @@ The builder is used to create the HTML. It divides the job between layouts and p

#### 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.
Parameter managers are used to consistently store variables for use in the theme. The Builder has a global one, and every View has a local one.

* __$pm->reset()__

Expand Down Expand Up @@ -114,7 +114,7 @@ Parameter managers are used to consistently store variables for being used in th

#### View

The View returned by the Builder is most often a custom object extending \Foolz\Theme\View.
The View returned by the Builder is usually 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.__

Expand All @@ -124,7 +124,7 @@ __It's compulsory to override the `toString()` method (not the `__toString()` ma

* __$view->getType()__

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

* __$view->getView()__

Expand All @@ -142,4 +142,4 @@ __It's compulsory to override the `toString()` method (not the `__toString()` ma

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

_CHAINABLE_
_CHAINABLE_
2 changes: 1 addition & 1 deletion classes/Foolz/Theme/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getPartial($name)
return $this->partials[$name];
}

throw new \OutOfBoundsException('No such a partial exists.');
throw new \OutOfBoundsException('No such partial exists.');
}

/**
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 @@ -36,8 +36,8 @@ public function getParams()
* Returns the parameter with the key
*
* @param string $key
*
* @return mixed The value of the parameter
*
* @throws \OutOfBoundsException If the key is not set
*/
public function getParam($key)
Expand Down Expand Up @@ -77,7 +77,7 @@ public function setParams($array)
{
$this->params[$key] = $item;
}

return $this;
}
}
2 changes: 1 addition & 1 deletion classes/Foolz/Theme/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct($dir)
$this->enableAutoloader();
static::$autoloaded[] = __CLASS__;
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/Foolz/Theme/Void.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

class Void extends \Foolz\Plugin\Void
{

}
35 changes: 34 additions & 1 deletion tests/classes/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function bld()
return $this->theme()->createBuilder();
}


public function testConstruct()
{
$this->assertInstanceOf('Foolz\Theme\Builder', $this->bld());
Expand Down Expand Up @@ -67,6 +66,40 @@ public function testCreatePartial()
$this->assertInstanceOf('Foolz\Foolfake\Theme\Fake\Partial\ThisPartial', $this->bld()->createPartial('one_partial', 'this_partial'));
}

public function testGetLayout()
{
$bld = $this->bld();
$bld->createLayout('this_layout');
$this->assertInstanceOf('Foolz\Theme\View', $bld->getLayout('this_layout'));
$this->assertInstanceOf('Foolz\Foolfake\Theme\Fake\Layout\ThisLayout', $bld->getLayout('this_layout'));
}

public function testGetPartial()
{
$bld = $this->bld();
$bld->createPartial('one_partial', 'this_partial');
$this->assertInstanceOf('Foolz\Theme\View', $bld->getPartial('one_partial', 'this_partial'));
$this->assertInstanceOf('Foolz\Foolfake\Theme\Fake\Partial\ThisPartial', $bld->getPartial('one_partial', 'this_partial'));
}

/**
* @expectedException \BadMethodCallException
* @expectedExceptionMessage The layout wasn't set.
*/
public function testGetLayoutThrowsBadMethodCall()
{
$this->bld()->getLayout();
}

/**
* @expectedException \OutOfBoundsException
* @expectedExceptionMessage No such partial exists.
*/
public function testGetPartialThrowsOutOfBounds()
{
$this->bld()->getPartial('derp');
}

public function testBuild()
{
$bld = $this->bld();
Expand Down
14 changes: 14 additions & 0 deletions tests/classes/LoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use Foolz\Theme\Loader;

class LoaderTest extends PHPUnit_Framework_TestCase
{
public function testGetTheme()
{
$new = Loader::forge('default');
$new->addDir('test', __DIR__.'/../../tests/mock/');
$theme = $new->get('test', 'foolz/foolfake-theme-fake');
$this->assertInstanceOf('Foolz\Theme\Theme', $theme);
}
}
24 changes: 11 additions & 13 deletions tests/classes/ParamManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,30 @@ public function testGetParamsEmpty()

/**
* @expectedException \OutOfBoundsException
* @expectedExceptionMessage Undefined parameter.
*/
public function testSetGetParamThrowsOutOfBounds()
{
$new = new ParamManager();
$new->getParam('derp');
$new->getParam('herp');
}

public function testGetSetParam()
public function testSetGetParam()
{
$stack = array();
$this->assertEquals(0, count($stack));

array_push($stack, 'foo');
$this->assertEquals('foo', $stack[count($stack)-1]);
$this->assertEquals(1, count($stack));

$this->assertEquals('foo', array_pop($stack));
$this->assertEquals(0, count($stack));
$new = new ParamManager();

$new->setParam('param1', 'test');
$new->setParam('param2', 'testtest');
$this->assertSame('test', $new->getParam('param1'));
$this->assertSame('testtest', $new->getParam('param2'));
}

public function testGetSetParams()
public function testSetGetParams()
{
$arr = array('param1' => 'test', 'param2' => 'testtest');
$new = new ParamManager();
$new->setParams($arr);

$new->setParams($arr);
$this->assertSame($arr, $new->getParams());
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/classes/UtilTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

use Foolz\Theme\Util as Util;

class UtilTest extends PHPUnit_Framework_TestCase
{
/**
*
* @return herp_derp
*/
public function testLowercaseToClassName()
{
$new = new Util();
$new->lowercaseToClassName('HERP DERP');
}
}

0 comments on commit 1acc702

Please sign in to comment.