From: Leandro Lucarella Date: Mon, 30 Jun 2003 07:15:30 +0000 (+0000) Subject: - New structure is almost done. X-Git-Tag: svn_import~31 X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/commitdiff_plain/134ee44a53cbdc075f0d6663acfe597dd068e043?hp=c6ec7da2a3e4d8839ca7873c9dcb196da613609c - New structure is almost done. - PEAR Package are well done. - Code looks fine but examples are not tested. - HIT has it's own directory. - BIFE Core and Basic module are now in the same package since Basic it's now so small and simple. --- diff --git a/BIFE/Link.php b/BIFE/Link.php new file mode 100644 index 0000000..c8900d6 --- /dev/null +++ b/BIFE/Link.php @@ -0,0 +1,125 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + +// +X2C includes +require_once 'BIFE/Container.php'; +// ~X2C + +// +X2C Class 110 :Link +/** + * Link to another page. + * + * @access public + */ +class BIFE_Link extends BIFE_Container { + // ~X2C + + // +X2C Operation 111 + /** + * Constructor. + * + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function BIFE_Link($attrs) // ~X2C + { + $this->__construct($attrs); + } + // -X2C + + // +X2C Operation 112 + /** + * Constructor. + * + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function __construct($attrs) // ~X2C + { + $link_attrs['URL'] = $this->getURL($attrs); + $link_attrs['DESC'] = @$attrs['DESC']; + $link_attrs['TARGET'] = @$attrs['TARGET']; + parent::__construct($link_attrs); + } + // -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 Operation 157 + /** + * Renders the widget. + * + * @param HTML_Template_HIT &$template Template to use to render the widget. + * + * @return string + * @access public + */ + function render(&$template) // ~X2C + { + $this->attrs['CONTENTS'] = $this->renderContents($template); + return $template->parse('bife_link', $this->attrs, '', ''); + } + // -X2C + +} // -X2C Class :Link + +?> \ No newline at end of file diff --git a/examples/hit.php b/BIFE/Translate.php similarity index 53% rename from examples/hit.php rename to BIFE/Translate.php index f9ec397..98dc263 100644 --- a/examples/hit.php +++ b/BIFE/Translate.php @@ -1,4 +1,4 @@ - | // +--------------------------------------------------------------------+ // // $Id$ // -// This is a simple test and example of HTML_Template_HIT +// +X2C includes +require_once 'BIFE/Fallback.php'; +// ~X2C -$tmp = ini_get('include_path'); -ini_set('include_path', "../core:$tmp"); -unset($tmp); -umask('002'); +// +X2C Class 7 :Translate +/** + * This is a generic and simple (but very usefull) BIFE_Fallback implementation. Translate widgets using a template with it's name, prepended with 'bife_'. If not template is found, it copy the XML to the output. + * + * @access public + */ +class BIFE_Translate extends BIFE_Fallback { + // ~X2C -require_once 'HTML/Template/HIT.php'; - -$hit =& new HTML_Template_HIT('hooks'); - -for ($i = 0; $i < 20; $i++) { - for ($j = 0; $j < 20; $j++) { - $hit->parseBuffered('cell', 'CELL', "$i,$j"); + // +X2C Operation 12 + /** + * Renders the widget. + * + * @param HTML_Template_HIT &$template Template to use to render the widget. + * + * @return string + * @access public + */ + function render(&$template) // ~X2C + { + $this->attrs['CONTENTS'] = $this->renderContents($template); + $name = "bife_{$this->name}"; + if ($template->exists($name, '')) { + $out = $template->parse($name, $this->attrs, '', ''); + } else { + $name = $this->name; + $out = "<$name"; + foreach ($this->attrs as $attr => $val) { + $out .= sprintf(' %s="%s"', $attr, $val); + } + $contents = $this->renderContents($template); + if ($contents !== '') { + $out .= ">$contents"; + } else { + $out .= "/>"; + } + } + return $out; } - $hit->parseBuffered('row', 'ROW', $hit->popBuffer('cell')); -} -echo $hit->parse( - 'body', - array( - 'ROWS' => $hit->popBuffer('row'), - 'TITLE' => 'HOLA MUNDO!!!', - ) -); + // -X2C + +} // -X2C Class :Translate -?> +?> \ No newline at end of file diff --git a/Doxyfile b/Doxyfile index 19e035a..caed41f 100644 --- a/Doxyfile +++ b/Doxyfile @@ -30,8 +30,8 @@ # General configuration options #--------------------------------------------------------------------------- PROJECT_NAME = "BIFE - Build It FastEr" -PROJECT_NUMBER = 0.10 -OUTPUT_DIRECTORY = doc/api +PROJECT_NUMBER = 0.11 +OUTPUT_DIRECTORY = api OUTPUT_LANGUAGE = English EXTRACT_ALL = YES EXTRACT_PRIVATE = YES @@ -83,10 +83,10 @@ WARN_LOGFILE = doxygen.warn #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = src/ +INPUT = FILE_PATTERNS = *.php RECURSIVE = YES -EXCLUDE = src/BIFE.php +EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = EXAMPLE_PATH = diff --git a/core/Makefile b/Makefile similarity index 91% rename from core/Makefile rename to Makefile index ed9979c..4bfa3e5 100644 --- a/core/Makefile +++ b/Makefile @@ -25,13 +25,16 @@ # $Id$ # -VERSION=0.10 +VERSION=0.11 MODULE_FILE=BIFE.php MODULE_NAME=Core PHP_FILES=$(filter-out $(MODULE_FILE),$(subst ./,,$(shell find -name '*.php'))) -X2C_TEMPLATE=../xmi2code.tpl.php +EXAMPLE_FILES=$(subst ./,,$(shell find examples -regex '.*\.svn.*')) +DOC_FILES=README ROADMAP +X2C_TEMPLATE=xmi2code.tpl.php -all: $(MODULE_FILE) +package: package.xml $(PHP_FILES) $(EXAMPLE_FILES) $(DOC_FILES) + pear package code: bife.xmi xmi2code.config @xmi2code diff --git a/bife.xmi b/bife.xmi index bdd5163..13594f0 100644 --- a/bife.xmi +++ b/bife.xmi @@ -5,7 +5,7 @@ umbrello uml modeller http://uml.sf.net 1.1 - + @@ -83,84 +83,64 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - + + + + + + + + - + - - + + + + + + + + - - - - - - - @@ -177,6 +157,12 @@ Parse a template appending the results to an internal buffer. If $vars is an arr + + + + + + @@ -194,6 +180,9 @@ Parse a template appending the results to an internal buffer. If $vars is an arr + + + @@ -201,25 +190,6 @@ Parse a template appending the results to an internal buffer. If $vars is an arr - - - - - - - - - - - - - - - - - - - diff --git a/build.xml b/build.xml deleted file mode 100644 index 5a6d0a5..0000000 --- a/build.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/core/HTML/Template/HIT.php b/core/HTML/Template/HIT.php deleted file mode 100644 index 2b635c9..0000000 --- a/core/HTML/Template/HIT.php +++ /dev/null @@ -1,265 +0,0 @@ - | -// +--------------------------------------------------------------------+ -// -// $Id$ -// - -// +X2C Class 130 :HIT -/** - * Hooks vs. IT (HIT) is a simple template implementation, based on hooks and IT template systems. - * - * @access public - */ -class HTML_Template_HIT { - /** - * Root directory where template files are. - * - * @var string $root - * @access public - */ - var $root = '.'; - - /** - * If it's true, it looks for template files in PHP's include_path. - * - * @var bool $useIncludePath - * @access public - */ - var $useIncludePath = false; - - /** - * Group of templates to use (a subdirectory in root). - * - * @var string $group - * @access protected - */ - var $group = ''; - - /** - * Templates cache. - * - * @var array $cache - * @access protected - */ - var $cache = array(); - - /** - * @var array $buffer - * @access protected - */ - var $buffer = array(); - - // ~X2C - - // +X2C Operation 136 - /** - * Constructor. - * - * @param string $root Root directory where template files are. - * @param bool $useIncludePath If it's true, it looks for template files in PHP's include_path. - * @param string $group Group of templates to use (a subdirectory in root). - * - * @return void - * @access public - */ - function HTML_Template_HIT($root = '.', $useIncludePath = false, $group = '') // ~X2C - { - $this->__construct($root, $useIncludePath, $group); - } - // -X2C - - // +X2C Operation 137 - /** - * Constructor. - * - * @param int $root Root directory where template files are. - * @param false $useIncludePath If it's true, it looks for template files in PHP's include_path. - * @param string $group Group of templates to use (a subdirectory in root). - * - * @return void - * @access public - */ - function __construct($root = '.', $useIncludePath = false, $group = '') // ~X2C - { - $this->root = $root; - $this->useIncludePath = $useIncludePath; - $this->pushGroup($group); - } - // -X2C - - // +X2C Operation 138 - /** - * 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. - * @param mixed $group Group to use to parse this template. Null to use the current group. - * - * @return string - * @access public - */ - function parse($name, $vars = '', $val = '', $group = null) // ~X2C - { - $group = is_null($group) ? end($this->group) : $group; - if ($group) { - $file = "{$this->root}/$group/$name.tpl.html"; - } else { - $file = "{$this->root}/$name.tpl.html"; - } - if (!isset($this->cache[$file])) { - // FIXME - replace join(file()) with file_get_contents(). - $this->cache[$file] = join('', file($file, $this->useIncludePath)); - } - 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]; - } - } - // -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. - * - * @return string - * @access public - * @static - */ - function getBuffer($name) // ~X2C - { - return @$this->buffer["{$this->group}/$name"]; - } - // -X2C - - // +X2C Operation 146 - /** - * Gets a parsed buffer and removes it. - * - * @param string $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 pushGroup($group = '') // ~X2C - { - $this->group[] = $group; - } - // -X2C - - // +X2C Operation 140 - /** - * Removes the group from the groups stack and returns to the previous used group. - * - * @return string - * @access public - */ - function popGroup() // ~X2C - { - return array_pop($this->group); - } - // -X2C - - // +X2C Operation 159 - /** - * True if the template $name exists in $group (or the current group). - * - * @param string $name Name of the template. - * @param mixed $group Template's group. If it's null it uses the current group. - * - * @return bool - * @access public - */ - function exists($name, $group = null) // ~X2C - { - $group = is_null($group) ? end($this->group) : $group; - if ($group) { - $file = "{$this->root}/$group/$name.tpl.html"; - } else { - $file = "{$this->root}/$name.tpl.html"; - } - if (!$this->useIncludePath) { - return is_readable($file); - } else { - $include_path = array_unique(preg_split('/[:;]/', ini_get('include_path'))); - foreach ($include_path as $path) { - if (is_readable("$path/$file")) { - return true; - } - } - return false; - } - } - // -X2C - -} // -X2C Class :HIT - -?> \ No newline at end of file diff --git a/examples/data.xbf b/examples/data.xbf deleted file mode 100644 index 06782ae..0000000 --- a/examples/data.xbf +++ /dev/null @@ -1,19 +0,0 @@ - - Titulo -

- Hola, gente, como estan todos? Esta es solo la primera prueba de - BIFE, un cuasi-framework inspirado en BIF. -

- Subtitulo - - Item loco. - Otro item loco. - - - Album de fotos - - - Este es mi perfil - -
diff --git a/examples/hooks/body.tpl.html b/examples/hooks/body.tpl.html deleted file mode 100644 index 2481bfa..0000000 --- a/examples/hooks/body.tpl.html +++ /dev/null @@ -1,10 +0,0 @@ - - - {TITLE} - - - - {ROWS} -
- - diff --git a/examples/hooks/cell.tpl.html b/examples/hooks/cell.tpl.html deleted file mode 100644 index d4889a9..0000000 --- a/examples/hooks/cell.tpl.html +++ /dev/null @@ -1 +0,0 @@ -{CELL} diff --git a/examples/hooks/row.tpl.html b/examples/hooks/row.tpl.html deleted file mode 100644 index 2889643..0000000 --- a/examples/hooks/row.tpl.html +++ /dev/null @@ -1 +0,0 @@ -{ROW} diff --git a/examples/index.php b/examples/index.php index fdb9580..3b9f86d 100644 --- a/examples/index.php +++ b/examples/index.php @@ -26,22 +26,14 @@ // $Id$ // -$incs = array( - '../core', - '../modules/album', - '../modules/basic', - '../modules/menu', -// '../modules/', -); $tmp = ini_get('include_path'); -ini_set('include_path', join(':', $incs) . ":$tmp"); +ini_set('include_path', "..:$tmp"); unset($tmp); umask('002'); require_once 'HTML/Template/HIT.php'; require_once 'BIFE/Parser.php'; require_once 'BIFE/Translate.php'; -require_once 'BIFE/Link.php'; $file = isset($_REQUEST['BIFE']) ? $_REQUEST['BIFE'] : 'index.xbf'; diff --git a/examples/index.xbf b/examples/index.xbf index 4ace0c3..df29c36 100644 --- a/examples/index.xbf +++ b/examples/index.xbf @@ -1,7 +1,9 @@ - - Datos! -

Photo album

- -
+ + BIFE is working! +

Translate Fallback is working too!

+

This is a very bad use for BIFE, because I'm writing HTML :-P

+ A little of 'real' use +

Here's a link to another BIFE file

+
diff --git a/examples/link.xbf b/examples/link.xbf new file mode 100644 index 0000000..1eaa4a9 --- /dev/null +++ b/examples/link.xbf @@ -0,0 +1,5 @@ + + + BIFE Links are working too! +

Go back.

+
diff --git a/examples/photo.xbf b/examples/photo.xbf deleted file mode 100644 index ba7f57c..0000000 --- a/examples/photo.xbf +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/examples/templates/album/body.tpl.html b/examples/templates/album/body.tpl.html deleted file mode 100644 index 2dd5085..0000000 --- a/examples/templates/album/body.tpl.html +++ /dev/null @@ -1,8 +0,0 @@ -

{DESC}

-
- - - {CONTENTS} - -
-
diff --git a/examples/templates/album/cell.tpl.html b/examples/templates/album/cell.tpl.html deleted file mode 100644 index dcbedbf..0000000 --- a/examples/templates/album/cell.tpl.html +++ /dev/null @@ -1,3 +0,0 @@ - - {CONTENTS} - diff --git a/examples/templates/album/empty.tpl.html b/examples/templates/album/empty.tpl.html deleted file mode 100644 index a735e36..0000000 --- a/examples/templates/album/empty.tpl.html +++ /dev/null @@ -1 +0,0 @@ -VACÍO diff --git a/examples/templates/album/item.tpl.html b/examples/templates/album/item.tpl.html deleted file mode 100644 index c41be64..0000000 --- a/examples/templates/album/item.tpl.html +++ /dev/null @@ -1 +0,0 @@ -{DESC} diff --git a/examples/templates/album/photo.tpl.html b/examples/templates/album/photo.tpl.html deleted file mode 100644 index 901274f..0000000 --- a/examples/templates/album/photo.tpl.html +++ /dev/null @@ -1,2 +0,0 @@ -

{DESC}

-{DESC} diff --git a/examples/templates/album/row.tpl.html b/examples/templates/album/row.tpl.html deleted file mode 100644 index 6f623b2..0000000 --- a/examples/templates/album/row.tpl.html +++ /dev/null @@ -1,3 +0,0 @@ - - {CONTENTS} - diff --git a/package.xml b/package.xml index fb889dd..ecaf738 100644 --- a/package.xml +++ b/package.xml @@ -1,5 +1,5 @@ - + BIFE Build It FastEr @@ -24,23 +24,25 @@ in mind. One of the main goals of BIFE is to be fast. alpha Check http://www.llucax.hn.org/desarrollo/bife/ for details. + BIFE/Parser.php BIFE/Widget.php BIFE/Container.php BIFE/Fallback.php - HTML/Template/HIT.php - bife.xmi + BIFE/Link.php + BIFE/Translate.php + + README + ROADMAP examples/index.php examples/index.xbf - examples/templates/bife_page.html - examples/templates/bife_title.html - examples/templates/bife_album.html - examples/templates/bife_album_item.html - examples/templates/bife_album_emptyitem.html + examples/templates/bife_page.tpl.html + examples/templates/bife_title.tpl.html + examples/templates/bife_link.tpl.html 4.2.3 - + HTML_Template_HIT diff --git a/xmi2code.config b/xmi2code.config index 4ab6be0..4e1a6cd 100644 --- a/xmi2code.config +++ b/xmi2code.config @@ -2,7 +2,7 @@