diff --git a/Application/plugin/Builder/hook.php b/Application/plugin/Builder/hook.php new file mode 100644 index 0000000..084d896 --- /dev/null +++ b/Application/plugin/Builder/hook.php @@ -0,0 +1,21 @@ + + * @package default + */ + + +@list( , $controller, $action, $item_id ) = $request->pathParts; +?> + +router->prepend( '/admin/plugin/thumb/\w+(/\d+)?', 'ItemThumb_Plugin' ); +} +?> + + + diff --git a/Application/plugin/Builder/lib/Abc.php b/Application/plugin/Builder/lib/Abc.php new file mode 100644 index 0000000..31b452c --- /dev/null +++ b/Application/plugin/Builder/lib/Abc.php @@ -0,0 +1,85 @@ + + * @package Pico + */ + + +abstract class Builder_Abc { + private $_constructor_args; + + + + /** + * + * + * @param unknown $args + */ + public function __construct( $args ) { + $this->_constructor_args = $args; //func_get_args(); + } + + + + /** + * + * + * @return unknown + */ + public function __toString() { + return $this->as_string(); + } + + + /** + * + * + * @param unknown $name + * @return unknown + */ + public function __get( $name ) { + if ( ($property = "_$name") + && (isset($this->$property) || property_exists( $this, $property ))) { + if ( ! isset( $this->$property ) + && method_exists( $this, "_build_$property" ) ) { + $method = "_build_$property"; + $this->$property = $this->$method(); + } + return $this->$property; + } + } + + + + /** + * + * + * @param unknown $name + * @return unknown + */ + public function arg( $name ) { + if ( isset( $this->_constructor_args[$name] ) ) { + return $this->_constructor_args[$name]; + } + + return array(); + } + + + + /** + * + * + * @param unknown $args + * @return unknown + */ + public function element( $args ) { + $args = array_merge( array( 'type' => 'div', 'attributes' => array() ), $args ); + + return new Nano_Element( $args['type'], $args['attributes']); + } + + +} diff --git a/Application/plugin/Builder/lib/Block.php b/Application/plugin/Builder/lib/Block.php new file mode 100644 index 0000000..d7e4bbc --- /dev/null +++ b/Application/plugin/Builder/lib/Block.php @@ -0,0 +1,40 @@ + + * @package Pico + */ + + +class Builder_Block extends Builder_Abc { + + protected $_element; + + + + /** + * + * + * @return unknown + */ + public function as_string() { + return (string) $this->element; + } + + + + /** + * + * + * @return unknown + */ + protected function _build__element() { + $div = new Nano_Element( 'div' ); + $div->setVertile(); + + return $div; + } + + +} diff --git a/Application/plugin/Builder/lib/Page.php b/Application/plugin/Builder/lib/Page.php new file mode 100644 index 0000000..f1e2156 --- /dev/null +++ b/Application/plugin/Builder/lib/Page.php @@ -0,0 +1,99 @@ + + * @package Pico + */ + + +class Builder_Page extends Builder_Abc { + protected $_doctype = 'html'; + + protected $_html; + protected $_body; + protected $_head; + + + //$builder = new Builder_Page(array( + // 'head' => array( + // 'children' => array( + // 'type' => 'link', + // 'attibutes' => array( + // 'href' => 'style.css', + // 'rel' => 'stylesheet', + // ) + // ) + // ), + // 'children' => array( + // array( + // 'type' => 'block', + // ) + // ) + //)); + + + /** + * + * + * @return unknown + */ + public function as_string() { + $doctype = sprintf('', $this->doctype ); + + return join( "\n", array( $doctype, $this->html ) ); + } + + + + /** + * + * + * @return unknown + */ + protected function _build__html() { + $html = new Nano_Element( 'html' ); + $html->addChild( $this->head ); + $html->addChild( $this->body ); + + return $html; + } + + + + /** + * + * + * @return unknown + */ + protected function _build__head() { + $head = new Nano_Element( 'head' ); + $head->setVertile(); + + $args = $this->arg('head'); + + if ( isset( $args['children'] ) ) { + foreach ( $args['children'] as $child ) { + $head->addChild( $this->element( $child )) ; + } + } + + return $head; + } + + + + /** + * + * + * @return unknown + */ + protected function _build__body() { + $body = new Nano_Element( 'body' ); + $body->setVertile(); + + return $body; + } + + +} diff --git a/Application/plugin/Builder/t/Block.php b/Application/plugin/Builder/t/Block.php new file mode 100644 index 0000000..1f4c1ff --- /dev/null +++ b/Application/plugin/Builder/t/Block.php @@ -0,0 +1,38 @@ + + * @package Pico + */ + + +class Builder_PageTest extends PHPUnit_Framework_TestCase{ + private $config; + + /** + * + */ + protected function setUp() { + require_once dirname(dirname(__FILE__)) . '/../Nano/library/Nano/Autoloader.php'; + Nano_Autoloader::register(); + Nano_Autoloader::registerNamespace( 'Builder', dirname(__FILE__) . '/../lib' ); + } + + + + /** + * + */ + public function testStringify() { + $builder = new Builder_Block(); + $expect = '
+ +
+ '; + + $this->assertEquals($expect, (string) $builder ); + } + + +} diff --git a/Application/plugin/Builder/t/Page.php b/Application/plugin/Builder/t/Page.php new file mode 100644 index 0000000..798ddab --- /dev/null +++ b/Application/plugin/Builder/t/Page.php @@ -0,0 +1,50 @@ + + * @package Pico + */ + + +class Builder_PageTest extends PHPUnit_Framework_TestCase{ + private $config; + + /** + * + */ + protected function setUp() { + require_once dirname(dirname(__FILE__)) . '/../Nano/library/Nano/Autoloader.php'; + Nano_Autoloader::register(); + Nano_Autoloader::registerNamespace( 'Builder', dirname(__FILE__) . '/../lib' ); + } + + + + /** + * + */ + public function testSmoke() { + $builder = new Builder_Page(array( + 'head' => array( + 'children' => array( + array( + 'type' => 'link', + 'attributes' => array( + 'href' => 'style.css', + 'rel' => 'stylesheet', + )) + ) + ), + 'children' => array( + array( + 'type' => 'block', + ) + ) + )); + + echo $builder; + } + + +}