From: Leandro Lucarella Date: Fri, 20 Jun 2003 04:18:50 +0000 (+0000) Subject: HTML_Template_HIT: X-Git-Tag: svn_import~43 X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/commitdiff_plain/715ddc41f45dcf4d64348fef69844618ad1abb3d HTML_Template_HIT: - Added "buffering". You can add parsed templates to a biffer and then get all the results. - Added "group stacking" to keep the previos group in nested callings. - Updated BIFE classes to use new features. - Updated example. BIFE_Link: - Added getURL() static method to construct an URL based on BIFE_Link attributes. BIFE_Album: - Updated to use BIFE_Link::getURL(). General: - Updated ROADMAP. - Updated UML diagram. --- diff --git a/doc/ROADMAP b/doc/ROADMAP index 5e75e61..1510d2b 100644 --- a/doc/ROADMAP +++ b/doc/ROADMAP @@ -3,19 +3,24 @@ $Id$ Version 0.9 =========== - - Finish HTML_Template_HIT. - - Separate Album funtionality function from renderer (BIFE_Album). - - Use new hooks libs. + - Finish HTML_Template_HIT (done?). + Version 0.10 ============ - Makefile: - - Make a way to put all classes in a package together in a single file to - avoid overhead in require_once calls. - - Make a Core Package with the core classes (Parser, Widget, Container, - Root, Fallback). - - Make a Basic (or Generic?) Package with simple implementations of all - classes in Core Package (Page, Title, Copy, etc). - - Make other more specific Packages (like Album) with other widgets. + - Make a way to put all classes in a package together in a single file to + avoid overhead in require_once calls. + - Make a Core Package with the core classes (Parser, Widget, Container, + Root, Fallback). + - Make a Basic (or Generic?) Package with simple implementations of all + classes in Core Package (Page, Title, Copy, etc). + - Make other more specific Packages (like Album) with other widgets. + + +Version 0.11 +============ + + - Separate Album funtionality function from renderer (BIFE_Album). + - Use new hooks libs. diff --git a/doc/bife.xmi b/doc/bife.xmi index 29ba9c0..bd9743d 100644 --- a/doc/bife.xmi +++ b/doc/bife.xmi @@ -9,7 +9,7 @@ - + @@ -19,7 +19,7 @@ - + @@ -34,7 +34,7 @@ - + @@ -49,7 +49,7 @@ - + @@ -63,7 +63,7 @@ - + @@ -82,7 +82,7 @@ - + - + @@ -181,7 +181,7 @@ Returns an array of associative arrays with this keys: - + @@ -191,6 +191,9 @@ Returns an array of associative arrays with this keys: + + + @@ -200,7 +203,7 @@ Returns an array of associative arrays with this keys: - + @@ -212,16 +215,35 @@ Returns an array of associative arrays with this keys: - + + + + + + + + + + + + + + + + - + + @@ -268,7 +290,7 @@ If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). - + @@ -455,7 +477,7 @@ If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). - + @@ -499,6 +521,7 @@ If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). + @@ -552,13 +575,19 @@ If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). - + + + + + + + diff --git a/examples/hit.php b/examples/hit.php index 9dae06d..0f7ce47 100644 --- a/examples/hit.php +++ b/examples/hit.php @@ -37,14 +37,18 @@ require_once 'HTML/Template/HIT.php'; $hit =& new HTML_Template_HIT('hooks'); -$rows = ''; for ($i = 0; $i < 20; $i++) { - $cells = ''; for ($j = 0; $j < 20; $j++) { - $cells .= $hit->parse('cell', array('CELL' => "$i,$j")); + $hit->parseBuffered('cell', 'CELL', "$i,$j"); } - $rows .= $hit->parse('row', array('ROW' => $cells, 'CACA' => 'fea')); + $hit->parseBuffered('row', 'ROW', $hit->popBuffer('cell')); } -echo $hit->parse('body', array('ROWS' => $rows, 'TITLE' => 'HOLA MUNDO!!!')); +echo $hit->parse( + 'body', + array( + 'ROWS' => $hit->popBuffer('row'), + 'TITLE' => 'HOLA MUNDO!!!', + ) +); ?> diff --git a/examples/hooks/body.html b/examples/hooks/body.tpl.html similarity index 100% rename from examples/hooks/body.html rename to examples/hooks/body.tpl.html diff --git a/examples/hooks/cell.html b/examples/hooks/cell.tpl.html similarity index 100% rename from examples/hooks/cell.html rename to examples/hooks/cell.tpl.html diff --git a/examples/hooks/row.html b/examples/hooks/row.tpl.html similarity index 100% rename from examples/hooks/row.html rename to examples/hooks/row.tpl.html diff --git a/src/BIFE/Album.php b/src/BIFE/Album.php index 9033389..9eb1e2d 100644 --- a/src/BIFE/Album.php +++ b/src/BIFE/Album.php @@ -91,46 +91,59 @@ class BIFE_Album extends BIFE_Widget { /** * Renders the widget. * - * @param HTML_Template_Sigma &$template Template to use to render the widget. + * @param HTML_Template_HIT &$template Template to use to render the widget. * * @return string * @access public */ function render(&$template) // ~X2C { - $template->group = 'album'; + $template->setGroup('album'); $list = $this->getList(); $tot = count($list); $rows = ceil($tot / $this->attrs['COLUMNS']); - $html_rows = ''; for ($row = 0; $row < $rows; $row++) { - $html_cells = ''; for ($col = 0; $col < $this->attrs['COLUMNS']; $col++) { $cur = $row * $this->attrs['COLUMNS'] + $col; if ($photo = @$list[$cur]) { if (is_null($photo['THUMB'])) { $photo['THUMB'] = $this->makeThumb($photo['FILE']); } - // FIXME - Si no se pudo crear el thumb, devuelve null - // (ver si se agrega otro template para indicar error - // o algo asi). - $photo['URL'] = $this->attrs['LINK-URL'] . - '?BIFE_ALBUM_FILE=' . urlencode($photo['FILE']); - if ($this->attrs['LINK-BIFE']) { - $photo['URL'] .= '&BIFE=' . - urlencode($this->attrs['LINK-BIFE']); - } - $html_cell = $template->parse('item', $photo); + /* XXX - Con objetos. * + $link =& new BIFE_Link( + array( + 'BIFE' => $this->attrs['LINK-BIFE'], + 'URL' => $this->attrs['LINK-URL'], + 'DESC' => $photo['DESC'], + 'DATA-BIFE_ALBUM_FILE' => $photo['FILE'], + ) + ); + $link->addContents($template->parse('item', $photo)); + $out_cell = $link->render($template); + /**/ + /* XXX - Intermedio, obteniendo el URL de Link. */ + $photo['URL'] = BIFE_Link::getURL( + array( + 'BIFE' => $this->attrs['LINK-BIFE'], + 'URL' => $this->attrs['LINK-URL'], + 'DATA-BIFE_ALBUM_FILE' => $photo['FILE'], + ) + ); + $cell = $template->parse('item', $photo); + /**/ } else { - $html_cell = $template->parse('empty'); + $cell = $template->parse('empty'); } - $html_cells .= $template->parse('cell', 'CONTENTS', $html_cell); + $template->parseBuffered('cell', 'CONTENTS', $cell); } - $html_rows .= $template->parse('row', 'CONTENTS', $html_cells); + $template->parseBuffered('row', 'CONTENTS', $template->popBuffer('cell')); } - return $template->parse( + $out = $template->parse( 'body', - array('DESC' => $this->getDescription(), 'CONTENTS' => $html_rows)); + array('DESC' => $this->getDescription(), 'CONTENTS' => $template->popBuffer('row')) + ); + $template->unsetGroup(); + return $out; } // -X2C diff --git a/src/BIFE/AlbumPhoto.php b/src/BIFE/AlbumPhoto.php index 1c63d78..c0ffa06 100644 --- a/src/BIFE/AlbumPhoto.php +++ b/src/BIFE/AlbumPhoto.php @@ -75,15 +75,17 @@ class BIFE_AlbumPhoto extends BIFE_Widget { /** * Renders the widget using a template returning a string with the results. * - * @param HTML_Template_Sigma &$template Template to use to render the widget. + * @param HTML_Template_HIT &$template Template to use to render the widget. * * @return string * @access public */ function render(&$template) // ~X2C { - $template->group = 'album'; - return $template->parse('photo', $this->attrs); + $template->setGroup('album'); + $out = $template->parse('photo', $this->attrs); + $template->unsetGroup(); + return $out; } // -X2C diff --git a/src/BIFE/Container.php b/src/BIFE/Container.php index 7c138ac..a1540b8 100644 --- a/src/BIFE/Container.php +++ b/src/BIFE/Container.php @@ -100,7 +100,7 @@ class BIFE_Container extends BIFE_Widget { /** * Renders the widget using a template returning a string with the results. * - * @param HTML_Template_Sigma &$template Template object to render the widget. + * @param HTML_Template_HIT &$template Template object to render the widget. * * @return string * @access public diff --git a/src/BIFE/Copy.php b/src/BIFE/Copy.php index c4bbe39..f58dec1 100644 --- a/src/BIFE/Copy.php +++ b/src/BIFE/Copy.php @@ -75,7 +75,7 @@ class BIFE_Copy extends BIFE_Fallback { /** * Renders the widget returning a string with the results. * - * @param HTML_Template_Sigma &$template Template to use to render the widget. + * @param HTML_Template_HIT &$template Template to use to render the widget. * * @return void * @access public diff --git a/src/BIFE/Generic.php b/src/BIFE/Generic.php index c1a1b60..bbda5bd 100644 --- a/src/BIFE/Generic.php +++ b/src/BIFE/Generic.php @@ -94,7 +94,7 @@ class BIFE_Generic extends BIFE_Container { /** * Renders the widget. * - * @param HTML_Template_Sigma &$template Template to use to render the widget. + * @param HTML_Template_HIT &$template Template to use to render the widget. * * @return string * @access public @@ -102,8 +102,10 @@ class BIFE_Generic extends BIFE_Container { function render(&$template) // ~X2C { $this->attrs['CONTENTS'] = parent::render($template); - $template->group = ''; - return $template->parse(get_class($this), $this->attrs); + $template->setGroup(); + $out = $template->parse(get_class($this), $this->attrs); + $template->unsetGroup(); + return $out; } // -X2C diff --git a/src/BIFE/Link.php b/src/BIFE/Link.php index 56e401c..02a3c80 100644 --- a/src/BIFE/Link.php +++ b/src/BIFE/Link.php @@ -89,6 +89,38 @@ class BIFE_Link extends BIFE_Generic { } // -X2C + // +X2C Operation 142 + /** + * Gets a URL string based on Link attributes. + * + * @param array $attrs Link attributes. + * + * @return string + * @access public + */ + function getURL($attrs) // ~X2C + { + $url = @$attrs['URL']; + unset($attrs['URL']); + if (isset($attrs['BIFE'])) { + $attrs['DATA-BIFE'] = $attrs['BIFE']; + unset($attrs['BIFE']); + } + $query = array(); + foreach($attrs as $name => $value) { + if (substr($name, 0, 5) === 'DATA-') { + if ($name = substr($name, 5)) { + $query[] = urlencode($name) . '=' . urlencode($value); + } + } + } + if ($query) { + $url .= '?' . join('&', $query); + } + return $url; + } + // -X2C + } // -X2C Class :Link ?> \ No newline at end of file diff --git a/src/BIFE/Menu.php b/src/BIFE/Menu.php index 49923d2..f7133b8 100644 --- a/src/BIFE/Menu.php +++ b/src/BIFE/Menu.php @@ -45,7 +45,7 @@ class BIFE_Menu extends BIFE_Widget { /** * Renders the widget using a template returning a string with the results. * - * @param HTML_Template_Sigma &$template Template to use to render the widget. + * @param HTML_Template_HIT &$template Template to use to render the widget. * * @return string * @access public diff --git a/src/BIFE/Page.php b/src/BIFE/Page.php index 10a63d0..0bff2f9 100644 --- a/src/BIFE/Page.php +++ b/src/BIFE/Page.php @@ -93,7 +93,7 @@ class BIFE_Page extends BIFE_Root { /** * Returns the rendered widget as a string. * - * @param HTML_Template_Sigma &$template Template to use to render the widget. + * @param HTML_Template_HIT &$template Template to use to render the widget. * * @return string * @access public @@ -101,8 +101,10 @@ class BIFE_Page extends BIFE_Root { function render(&$template) // ~X2C { $this->attrs['CONTENTS'] = parent::render($template); - $template->group = ''; - return $template->parse('bife_page', $this->attrs); + $template->setGroup(); + $out = $template->parse('bife_page', $this->attrs); + $template->unsetGroup(); + return $out; } // -X2C diff --git a/src/BIFE/Widget.php b/src/BIFE/Widget.php index 338cdf6..c000452 100644 --- a/src/BIFE/Widget.php +++ b/src/BIFE/Widget.php @@ -78,7 +78,7 @@ class BIFE_Widget { /** * Renders the widget using a template returning a string with the results. * - * @param HTML_Template_Sigma &$template Template object to render the widget. + * @param HTML_Template_HIT &$template Template object to render the widget. * * @return string * @access public diff --git a/src/HTML/Template/HIT.php b/src/HTML/Template/HIT.php index de67d2c..6da0b7b 100644 --- a/src/HTML/Template/HIT.php +++ b/src/HTML/Template/HIT.php @@ -45,7 +45,7 @@ class HTML_Template_HIT { * Group of templates to use (a subdirectory in root). * * @var string $group - * @access public + * @access protected */ var $group = ''; @@ -57,6 +57,12 @@ class HTML_Template_HIT { */ var $cache = array(); + /** + * @var array $buffer + * @access protected + */ + var $buffer = array(); + // ~X2C // +X2C Operation 136 @@ -87,27 +93,28 @@ class HTML_Template_HIT { */ function __construct($root = '.', $group = '') // ~X2C { - $this->root = $root; - $this->group = $group; + $this->root = $root; + $this->setGroup($group); } // -X2C // +X2C Operation 138 /** - * Parse a template. + * Parse a template returning the results. If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). If is a string, {$vars} is replaced with $val. * * @param string $name Name of template to parse. * @param mixed $vars Variables to replace in the template. * @param string $val If $vars is a string, the value to replace for $vars. * - * @return void + * @return string * @access public */ function parse($name, $vars = '', $val = '') // ~X2C { - if ($this->group) { - $file = "{$this->root}/{$this->group}/$name.tpl.html"; + $group = end($this->group); + if ($group) { + $file = "{$this->root}/$group/$name.tpl.html"; } else { $file = "{$this->root}/$name.tpl.html"; } @@ -132,6 +139,89 @@ If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). } // -X2C + // +X2C Operation 144 + /** + * Parse a template buffering the results. +Parse a template appending the results to an internal buffer. If $vars is an array, the {[keys]} are replaced with [values] ($val is ignored). If is a string, {$vars} is replaced with $val. + * + * @param string $name Name of template to parse. + * @param mixed $vars Variables to replace in the template. + * @param string $val If $vars is a string, the value to replace for $vars. + * + * @return void + * @access public + */ + function parseBuffered($name, $vars = '', $val = '') // ~X2C + { + @$this->buffer["{$this->group}/$name"] .= $this->parse($name, $vars, $val); + } + // -X2C + + // +X2C Operation 145 + /** + * Gets a parsed buffer. + * + * @param string $name Name of the parsed template to get. + * @param bool $flush Flush buffer. + * + * @return string + * @access public + */ + function getBuffer($name, $flush = true) // ~X2C + { + return @$this->buffer["{$this->group}/$name"]; + } + // -X2C + + // +X2C Operation 146 + /** + * Gets a parsed buffer and removes it. + * + * @param int $name Name of the buffer to flush. + * + * @return void + * @access public + */ + function popBuffer($name = '') // ~X2C + { + $return = @$this->buffer["{$this->group}/$name"]; + unset($this->buffer["{$this->group}/$name"]); + return $return; + } + // -X2C + + // +X2C Operation 139 + /** + * Sets the group to use and add it to the groups stack. + * + * @param string $group Group to use. + * + * @return void + * @access public + */ + function setGroup($group = '') // ~X2C + { + if ($group) { + $this->group[] = $group; + } else { + $this->group[] = ''; + } + } + // -X2C + + // +X2C Operation 140 + /** + * Removes the group from the groups stack and returns to the previous used group. + * + * @return void + * @access public + */ + function unsetGroup() // ~X2C + { + array_pop($this->group); + } + // -X2C + } // -X2C Class :HIT -?> +?> \ No newline at end of file