]> git.llucax.com Git - software/bife/bife-all.git/commitdiff
- Added a new simple template system: Hooks + IT = HIT.
authorLeandro Lucarella <llucax@gmail.com>
Wed, 18 Jun 2003 04:18:09 +0000 (04:18 +0000)
committerLeandro Lucarella <llucax@gmail.com>
Wed, 18 Jun 2003 04:18:09 +0000 (04:18 +0000)
  It's a simple template system based on the experience with hooks and IT
  template system (and specially Sigma implementation of IT).
- Moved all to HIT =)

26 files changed:
doc/ROADMAP
doc/bife.xmi
examples/hit.php [new file with mode: 0644]
examples/hooks/body.html [new file with mode: 0644]
examples/hooks/cell.html [new file with mode: 0644]
examples/hooks/row.html [new file with mode: 0644]
examples/index.php
examples/templates/album/body.tpl.html [new file with mode: 0644]
examples/templates/album/cell.tpl.html [new file with mode: 0644]
examples/templates/album/empty.tpl.html [new file with mode: 0644]
examples/templates/album/item.tpl.html [new file with mode: 0644]
examples/templates/album/photo.tpl.html [moved from examples/templates/bife_albumphoto.html with 100% similarity]
examples/templates/album/row.tpl.html [new file with mode: 0644]
examples/templates/bife_album.html [deleted file]
examples/templates/bife_link.tpl.html [moved from examples/templates/bife_link.html with 100% similarity]
examples/templates/bife_page.tpl.html [moved from examples/templates/bife_page.html with 100% similarity]
examples/templates/bife_title.tpl.html [moved from examples/templates/bife_title.html with 100% similarity]
examples/templates/photo.html [deleted file]
src/BIFE/Album.php
src/BIFE/AlbumPhoto.php
src/BIFE/Container.php
src/BIFE/Generic.php
src/BIFE/Page.php
src/BIFE/Parser.php
src/BIFE/Root.php
src/HTML/Template/HIT.php [new file with mode: 0644]

index 5b7317d02822b21786348b99c8634065ea84f70e..5e75e617c65730f3097146753bedfcfd1fd91b2a 100644 (file)
@@ -3,6 +3,13 @@ $Id$
 Version 0.9
 ===========
 
 Version 0.9
 ===========
 
+        - Finish HTML_Template_HIT.
+        - Separate Album funtionality function from renderer (BIFE_Album).
+        - Use new hooks libs.
+
+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.
     Makefile:
         - Make a way to put all classes in a package together in a single file to
           avoid overhead in require_once calls.
index 7a89f991d16061bfd9e7f5c75153f9368c10e549..a6ebdee7cc5cccc02116f0c35439d1031537d3fb 100644 (file)
@@ -5,7 +5,7 @@
    <XMI.exporter>umbrello uml modeller http://uml.sf.net</XMI.exporter>
    <XMI.exporterVersion>1.1</XMI.exporterVersion>
   </XMI.documentation>
    <XMI.exporter>umbrello uml modeller http://uml.sf.net</XMI.exporter>
    <XMI.exporterVersion>1.1</XMI.exporterVersion>
   </XMI.documentation>
-  <XMI.model xmi.name="bife" href="/home/luca/website/www/test/bife_estable/doc/bife.xmi" />
+  <XMI.model xmi.name="bife" href="/home/luca/website/www/test/bife/doc/bife.xmi" />
   <XMI.metamodel xmi.name="UML" href="UML.xml" xmi.version="1.3" />
  </XMI.header>
  <XMI.content>
   <XMI.metamodel xmi.name="UML" href="UML.xml" xmi.version="1.3" />
  </XMI.header>
  <XMI.content>
     <UML:Attribute stereotype="" package="" xmi.id="125" value="array()" type="array" abstract="0" documentation="Attribute list." name="attrs" static="0" scope="202" />
    </UML:Class>
    <UML:Class stereotype="" package="BIFE" xmi.id="5" abstract="1" documentation="Base container widget class." name="Container" static="0" scope="200" >
     <UML:Attribute stereotype="" package="" xmi.id="125" value="array()" type="array" abstract="0" documentation="Attribute list." name="attrs" static="0" scope="202" />
    </UML:Class>
    <UML:Class stereotype="" package="BIFE" xmi.id="5" abstract="1" documentation="Base container widget class." name="Container" static="0" scope="200" >
-    <UML:Operation stereotype="" package="" xmi.id="48" type="void" abstract="0" documentation="Constructor." name="BIFE_Container" static="0" scope="200" />
-    <UML:Operation stereotype="" package="" xmi.id="50" type="void" abstract="0" documentation="Constructor." name="__construct" static="0" scope="200" />
+    <UML:Operation stereotype="" package="" xmi.id="48" type="void" abstract="0" documentation="Constructor." name="BIFE_Container" static="0" scope="200" >
+     <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="array" abstract="0" documentation="Attributes." name="attrs" static="0" scope="200" />
+    </UML:Operation>
+    <UML:Operation stereotype="" package="" xmi.id="50" type="void" abstract="0" documentation="Constructor." name="__construct" static="0" scope="200" >
+     <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="array" abstract="0" documentation="Attributes." name="attrs" static="0" scope="200" />
+    </UML:Operation>
     <UML:Operation stereotype="" package="" xmi.id="6" type="void" abstract="0" documentation="Adds contents to the container." name="addContents" static="0" scope="200" >
      <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="&amp;mixed" abstract="0" documentation="Contents to add to the container." name="contents" static="0" scope="200" />
     </UML:Operation>
     <UML:Operation stereotype="" package="" xmi.id="6" type="void" abstract="0" documentation="Adds contents to the container." name="addContents" static="0" scope="200" >
      <UML:Parameter stereotype="" package="" xmi.id="1" value="" type="&amp;mixed" abstract="0" documentation="Contents to add to the container." name="contents" static="0" scope="200" />
     </UML:Operation>
diff --git a/examples/hit.php b/examples/hit.php
new file mode 100644 (file)
index 0000000..9dae06d
--- /dev/null
@@ -0,0 +1,50 @@
+<?
+// vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
+// +--------------------------------------------------------------------+
+// |                       BIFE - Buil It FastEr                        |
+// +--------------------------------------------------------------------+
+// | This file is part of BIFE.                                         |
+// |                                                                    |
+// | BIFE is free software; you can redistribute it and/or modify it    |
+// | under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation; either version 2 of the License, or  |
+// | (at your option) any later version.                                |
+// |                                                                    |
+// | BIFE is distributed in the hope that it will be useful, but        |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   |
+// | General Public License for more details.                           |
+// |                                                                    |
+// | You should have received a copy of the GNU General Public License  |
+// | along with Hooks; if not, write to the Free Software Foundation,   |
+// | Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA      |
+// +--------------------------------------------------------------------+
+// | Created: mié jun 18 01:05:57 ART 2003                              |
+// | Authors: Leandro Lucarella <luca@lugmen.org.ar>                    |
+// +--------------------------------------------------------------------+
+//
+// $Id$
+//
+
+// This is a simple test and example of HTML_Template_HIT
+
+$tmp = ini_get('include_path');
+ini_set('include_path', "../src:$tmp");
+unset($tmp);
+umask('002');
+
+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"));
+    }
+    $rows .= $hit->parse('row', array('ROW' => $cells, 'CACA' => 'fea'));
+}
+echo $hit->parse('body', array('ROWS' => $rows, 'TITLE' => 'HOLA MUNDO!!!'));
+
+?>
diff --git a/examples/hooks/body.html b/examples/hooks/body.html
new file mode 100644 (file)
index 0000000..2481bfa
--- /dev/null
@@ -0,0 +1,10 @@
+<HTML>
+    <HEAD>
+        <TITLE>{TITLE}</TITLE>
+    </HEAD>
+    <BODY>
+        <TABLE border="1" cellpadding="5">
+            {ROWS}
+        </TABLE>
+    </BODY>
+</HTML>
diff --git a/examples/hooks/cell.html b/examples/hooks/cell.html
new file mode 100644 (file)
index 0000000..d4889a9
--- /dev/null
@@ -0,0 +1 @@
+<TD>{CELL}</TD>
diff --git a/examples/hooks/row.html b/examples/hooks/row.html
new file mode 100644 (file)
index 0000000..2889643
--- /dev/null
@@ -0,0 +1 @@
+<TR>{ROW}</TR>
index 33b14e1bc9bd7c62b27fc1569d77a6d78b761aa5..b7487283fbd367aec47edf4d64fe8ccb58f46d08 100644 (file)
 $tmp = ini_get('include_path');
 ini_set('include_path', "../src:$tmp");
 unset($tmp);
 $tmp = ini_get('include_path');
 ini_set('include_path', "../src:$tmp");
 unset($tmp);
+umask('002');
 
 
-require_once 'HTML/Template/Sigma.php';
+require_once 'HTML/Template/HIT.php';
+#require_once 'HTML/Template/Sigma.php';
 require_once 'BIFE/Parser.php';
 require_once 'BIFE/Copy.php';
 require_once 'BIFE/Page.php';
 require_once 'BIFE/Parser.php';
 require_once 'BIFE/Copy.php';
 require_once 'BIFE/Page.php';
@@ -41,8 +43,9 @@ require_once 'BIFE/Link.php';
 
 $file = isset($_REQUEST['BIFE']) ? $_REQUEST['BIFE'] : 'index.xbf';
 
 
 $file = isset($_REQUEST['BIFE']) ? $_REQUEST['BIFE'] : 'index.xbf';
 
-$template =& new HTML_Template_Sigma('templates', 'compiled_templates');
-$template->setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_ERROR);
+$template =& new HTML_Template_HIT('templates');
+#$template =& new HTML_Template_Sigma('templates', 'compiled_templates');
+#$template->setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_ERROR);
 
 $parser =& new BIFE_Parser('BIFE_Copy');
 $page =& $parser->parseFile($file);
 
 $parser =& new BIFE_Parser('BIFE_Copy');
 $page =& $parser->parseFile($file);
diff --git a/examples/templates/album/body.tpl.html b/examples/templates/album/body.tpl.html
new file mode 100644 (file)
index 0000000..2dd5085
--- /dev/null
@@ -0,0 +1,8 @@
+<H3 class="album">{DESC}</H3>
+<DIV class="center">
+    <TABLE class="album">
+        <TBODY>
+            {CONTENTS}
+        </TBODY>
+    </TABLE>
+</DIV>
diff --git a/examples/templates/album/cell.tpl.html b/examples/templates/album/cell.tpl.html
new file mode 100644 (file)
index 0000000..dcbedbf
--- /dev/null
@@ -0,0 +1,3 @@
+<TD align="center" valign="middle">
+    {CONTENTS}
+</TD>
diff --git a/examples/templates/album/empty.tpl.html b/examples/templates/album/empty.tpl.html
new file mode 100644 (file)
index 0000000..a735e36
--- /dev/null
@@ -0,0 +1 @@
+VACÍO
diff --git a/examples/templates/album/item.tpl.html b/examples/templates/album/item.tpl.html
new file mode 100644 (file)
index 0000000..c41be64
--- /dev/null
@@ -0,0 +1 @@
+<A href="{URL}"><IMG alt="{DESC}" src="{THUMB}"></A>
diff --git a/examples/templates/album/row.tpl.html b/examples/templates/album/row.tpl.html
new file mode 100644 (file)
index 0000000..6f623b2
--- /dev/null
@@ -0,0 +1,3 @@
+<TR>
+    {CONTENTS}
+</TR>
diff --git a/examples/templates/bife_album.html b/examples/templates/bife_album.html
deleted file mode 100644 (file)
index 749e1d0..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<H3 class="album">{DESC}</H3>
-<DIV class="center">
-    <TABLE class="album">
-        <TBODY>
-            <!-- BEGIN ROW -->
-            <TR>
-                <!-- BEGIN ITEM -->
-                <TD align="center" valign="middle">
-                    <A href="{URL}"><IMG alt="{DESC}" src="{THUMB}"></A>
-                </TD>
-                <!-- END ITEM -->
-                <!-- BEGIN EMPTY -->
-                <TD align="center" valign="middle">
-                    VACÍO
-                </TD>
-                <!-- END EMPTY -->
-            </TR>
-            <!-- END ROW -->
-        </TBODY>
-    </TABLE>
-</DIV>
diff --git a/examples/templates/photo.html b/examples/templates/photo.html
deleted file mode 100644 (file)
index 4ff6528..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-<IMG class="albumphoto" alt="{DESC}" src="{PHOTO}"/>
-<DIV class="albumphoto">{DESC}</DIV>
index b3fd40915dddfc889b836c4ddc0d7a337c4b6d0d..ff08c401a0ad49a876035f67c0746b8adb767dd5 100644 (file)
@@ -98,12 +98,14 @@ class BIFE_Album extends BIFE_Widget {
      */
     function render(&$template) // ~X2C
     {
      */
     function render(&$template) // ~X2C
     {
-        $template->loadTemplateFile('bife_album.html');
+        $template->group = 'album';
         $root = $this->attrs['DIR'];
         $list = $this->getList();
         $tot  = count($list);
         $rows = ceil($tot / $this->attrs['COLUMNS']);
         $root = $this->attrs['DIR'];
         $list = $this->getList();
         $tot  = count($list);
         $rows = ceil($tot / $this->attrs['COLUMNS']);
+        $html_rows = '';
         for ($row = 0; $row < $rows; $row++) {
         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]) {
             for ($col = 0; $col < $this->attrs['COLUMNS']; $col++) {
                 $cur = $row * $this->attrs['COLUMNS'] + $col;
                 if ($photo = @$list[$cur]) {
@@ -113,22 +115,23 @@ class BIFE_Album extends BIFE_Widget {
                     // FIXME - Si no se pudo crear el thumb, devuelve null
                     // (ver si se agrega otro template para indicar error
                     // o algo asi).
                     // 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']);
+                    $photo['URL'] = $this->attrs['LINK-URL'] .
+                        '?BIFE_ALBUM_FILE=' . urlencode($photo['FILE']);
                     if ($this->attrs['LINK-BIFE']) {
                     if ($this->attrs['LINK-BIFE']) {
-                        $photo['URL'] .= '&BIFE=' . urlencode($this->attrs['LINK-BIFE']);
+                        $photo['URL'] .= '&BIFE=' .
+                            urlencode($this->attrs['LINK-BIFE']);
                     }
                     }
-                    $template->setVariable($photo);
-                    $template->parse('ITEM');
+                    $html_cell = $template->parse('item', $photo);
                 } else {
                 } else {
-                    $template->touchBlock('EMPTY');
-                    $template->parse('EMPTY');
+                    $html_cell = $template->parse('empty');
                 }
                 }
+                $html_cells .= $template->parse('cell', 'CONTENTS', $html_cell);
             }
             }
-            $template->parse('ROW');
+            $html_rows .= $template->parse('row', 'CONTENTS', $html_cells);
         }
         }
-        $template->setVariable('DESC', $this->getDescription());
-        return $template->get();
+        return $template->parse(
+            'body',
+            array('DESC' => $this->getDescription(), 'CONTENTS' => $html_rows));
     }
     // -X2C
 
     }
     // -X2C
 
@@ -158,7 +161,7 @@ Returns an array of associative arrays with this keys:
                 if (is_readable("$root/$file") and in_array($ext, $exts)) {
                     $thumb = $this->getThumbFilename("$root/$file");
                     $return[] = array(
                 if (is_readable("$root/$file") and in_array($ext, $exts)) {
                     $thumb = $this->getThumbFilename("$root/$file");
                     $return[] = array(
-                        'FILE'  => "$root/$name",
+                        'FILE'  => "$root/$file",
                         'DESC'  => $name,
                         'THUMB' => is_readable($thumb) ? $thumb : null,
                     );
                         'DESC'  => $name,
                         'THUMB' => is_readable($thumb) ? $thumb : null,
                     );
index ab4cc53e9cef1afdb7f4801a1c9ce03c42f4cb8e..084088df3d44f549ed654204dfb763c9c117cd4e 100644 (file)
@@ -82,9 +82,8 @@ class BIFE_AlbumPhoto extends BIFE_Widget {
      */
     function render(&$template) // ~X2C
     {
      */
     function render(&$template) // ~X2C
     {
-        $template->loadTemplateFile('bife_albumphoto.html');
-        $template->setVariable($this->attrs);
-        return $template->get();
+        $template->group = 'album';
+        return $template->parse('photo', $this->attrs);
     }
     // -X2C
 
     }
     // -X2C
 
index 14c71054344ea3867fd321812ac1ece49924a4a8..7c138ac5830b7989c9ec5b5dbdcbe883f2e8af04 100644 (file)
@@ -50,12 +50,14 @@ class BIFE_Container extends BIFE_Widget {
     /**
      * Constructor.
      *
     /**
      * Constructor.
      *
+     * @param  array $attrs Attributes.
+     *
      * @return void
      * @access public
      */
      * @return void
      * @access public
      */
-    function BIFE_Container() // ~X2C
+    function BIFE_Container($attrs) // ~X2C
     {
     {
-        $this->__construct();
+        $this->__construct($attrs);
     }
     // -X2C
 
     }
     // -X2C
 
@@ -63,11 +65,14 @@ class BIFE_Container extends BIFE_Widget {
     /**
      * Constructor.
      *
     /**
      * Constructor.
      *
+     * @param  array $attrs Attributes.
+     *
      * @return void
      * @access public
      */
      * @return void
      * @access public
      */
-    function __construct() // ~X2C
+    function __construct($attrs) // ~X2C
     {
     {
+        parent::__construct($attrs);
         $this->contents = array();
     }
     // -X2C
         $this->contents = array();
     }
     // -X2C
index e31d813bc1bf13e891d03e1cf630f4dd54a6a59e..1e9e06d9782f2b1a123f19038780f33c1f8a6193 100644 (file)
@@ -101,11 +101,9 @@ class BIFE_Generic extends BIFE_Container {
      */
     function render(&$template) // ~X2C
     {
      */
     function render(&$template) // ~X2C
     {
-        $contents = parent::render($template);
-        $template->loadTemplateFile(get_class($this).'.html');
-        $template->setVariable($this->attrs);
-        $template->setVariable('CONTENTS', $contents);
-        return $template->get();
+        $this->attrs['CONTENTS'] = parent::render($template);
+        $template->group = '';
+        return $template->parse(get_class($this), $this->attrs);
     }
     // -X2C
 
     }
     // -X2C
 
index d1ce3485e8d6bc208ecc1b40f9fa788a692c1088..1d68fa0a10acaf4cfbd79b42c16a16a92c8822b5 100644 (file)
@@ -100,11 +100,9 @@ class BIFE_Page extends BIFE_Root {
      */
     function render(&$template) // ~X2C
     {
      */
     function render(&$template) // ~X2C
     {
-        $contents = parent::render($template);
-        $template->loadTemplateFile('bife_page.html');
-        $template->setVariable($this->attrs);
-        $template->setVariable('CONTENTS', $contents);
-        return $template->get();
+        $this->attrs['CONTENTS'] = parent::render($template);
+        $template->group = '';
+        return $template->parse('bife_page', $this->attrs);
     }
     // -X2C
 
     }
     // -X2C
 
index 4598ea1cba7fc2003d80c5de2c2b9644970c3902..bf9632626a5f523de86227521254ea0b57ecf406 100644 (file)
@@ -262,4 +262,4 @@ class BIFE_Parser {
 
 } // -X2C Class :Parser
 
 
 } // -X2C Class :Parser
 
-?>
\ No newline at end of file
+?>
index 66f9cbc001da4d52d294bccb222e05cb75102595..30e40efbaa1563118d6d0b1748b6f2398f955358 100644 (file)
@@ -77,4 +77,4 @@ class BIFE_Root extends BIFE_Container {
 
 } // -X2C Class :Root
 
 
 } // -X2C Class :Root
 
-?>
\ No newline at end of file
+?>
diff --git a/src/HTML/Template/HIT.php b/src/HTML/Template/HIT.php
new file mode 100644 (file)
index 0000000..951cca1
--- /dev/null
@@ -0,0 +1,43 @@
+<?
+
+// TODO
+//      * Add to UML diagram and make xmi2code generate the code.
+//      * Add option to use include_path on file search.
+
+class HTML_Template_HIT {
+    var $root;
+    var $group;
+    var $cache;
+    function HTML_Template_HIT($root = '.', $group = '') {
+        $this->root  = $root;
+        $this->group = $group;
+        $this->cache = array();
+    }
+    function parse($name, $vars = null, $val = null) {
+        if ($this->group) {
+            $file = "{$this->root}/{$this->group}/$name.tpl.html";
+        } else {
+            $file = "{$this->root}/$name.tpl.html";
+        }
+        if (!isset($this->cache[$file])) {
+            $this->cache[$file] = join('', file($file));
+        }
+        //if (!is_readable($file)) {
+        //    trigger_error("Can't read '$file'.");
+        //}
+        if ($vars) {
+            if (is_string($vars)) {
+                $vars = array($vars => $val);
+            }
+            foreach ($vars as $key => $val) {
+                $keys[] = '{' . $key . '}';
+                $vals[] = $val;
+            }
+            return str_replace($keys, $vals, $this->cache[$file]);
+        } else {
+            return $this->cache[$file];
+        }
+    }
+}
+
+?>