cvs: pear /HTML_Template_Flexy/Flexy Tokenizer.lex Tokenizer.php /HTML_Template_Flexy/Flexy/Token Tag.php

From: Date: Sat, 01 Feb 2003 04:09:56 +0000
Subject: cvs: pear /HTML_Template_Flexy/Flexy Tokenizer.lex Tokenizer.php /HTML_Template_Flexy/Flexy/Token Tag.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8622@lists.php.net to get a copy of this message
alan_k Fri Jan 31 23:09:56 2003 EDT Modified files: /pear/HTML_Template_Flexy/Flexy Tokenizer.lex Tokenizer.php /pear/HTML_Template_Flexy/Flexy/Token Tag.php Log: change all tags to be stored uppercase, add support for static selects mapping to form values

Index: pear/HTML_Template_Flexy/Flexy/Tokenizer.lex diff -u pear/HTML_Template_Flexy/Flexy/Tokenizer.lex:1.4 pear/HTML_Template_Flexy/Flexy/Tokenizer.lex:1.5 --- pear/HTML_Template_Flexy/Flexy/Tokenizer.lex:1.4 Fri Jan 31 11:22:06 2003 +++ pear/HTML_Template_Flexy/Flexy/Tokenizer.lex Fri Jan 31 23:09:56 2003 @@ -16,7 +16,7 @@ // | Authors: nobody <nobody@localhost> | // +----------------------------------------------------------------------+ // -// $Id: Tokenizer.lex,v 1.4 2003/01/31 16:22:06 alan_k Exp $ +// $Id: Tokenizer.lex,v 1.5 2003/02/01 04:09:56 alan_k Exp $ // // The Source Lex file. (Tokenizer.lex) and the Generated one (Tokenizer.php) // You should always work with the .lex file and generate by @@ -214,7 +214,7 @@ <YYINITIAL>{ETAGO}{NAME}{WHITESPACE} { /* </title> -- end tag */ - $this->tagName = trim(substr($this->yytext(),1)); + $this->tagName = strtoupper(trim(substr($this->yytext(),1))); $this->tokenName = 'EndTag'; $this->yybegin(IN_ENDTAG); $this->value = ''; @@ -281,7 +281,7 @@ <YYINITIAL>{STAGO}{NAME}{WHITESPACE} { //<name -- start tag */ - $this->tagName = trim(substr($this->yytext(),1)); + $this->tagName = strtoupper(trim(substr($this->yytext(),1))); $this->tokenName = 'Tag'; $this->value = ''; $this->attributes = array(); @@ -320,7 +320,7 @@ <IN_ATTR>{NAME}{SPACE}*={WHITESPACE} { // <a ^href = "xxx"> -- attribute name - $this->attrKey = substr(trim($this->yytext()),0,-1); + $this->attrKey = strtoupper(substr(trim($this->yytext()),0,-1)); $this->yybegin(IN_ATTRVAL); $this->value = ''; return HTML_TEMPLATE_FLEXY_TOKEN_NONE; @@ -329,7 +329,7 @@ <IN_ATTR>{NAME}{WHITESPACE} { // <img src="xxx" ^ismap> -- name */ - $this->attributes[trim($this->yytext())] = null; + $this->attributes[strtoupper(trim($this->yytext()))] = null; $this->value = ''; return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } Index: pear/HTML_Template_Flexy/Flexy/Tokenizer.php diff -u pear/HTML_Template_Flexy/Flexy/Tokenizer.php:1.5 pear/HTML_Template_Flexy/Flexy/Tokenizer.php:1.6 --- pear/HTML_Template_Flexy/Flexy/Tokenizer.php:1.5 Fri Jan 31 12:28:39 2003 +++ pear/HTML_Template_Flexy/Flexy/Tokenizer.php Fri Jan 31 23:09:56 2003 @@ -16,7 +16,7 @@ // | Authors: nobody <nobody@localhost> | // +----------------------------------------------------------------------+ // -// $Id: Tokenizer.php,v 1.5 2003/01/31 17:28:39 alan_k Exp $ +// $Id: Tokenizer.php,v 1.6 2003/02/01 04:09:56 alan_k Exp $ // // The Source Lex file. (Tokenizer.lex) and the Generated one (Tokenizer.php) // You should always work with the .lex file and generate by @@ -1530,7 +1530,7 @@ case 5: { //<name -- start tag */ - $this->tagName = trim(substr($this->yytext(),1)); + $this->tagName = strtoupper(trim(substr($this->yytext(),1))); $this->tokenName = 'Tag'; $this->value = ''; $this->attributes = array(); @@ -1558,7 +1558,7 @@ case 9: { /* </title> -- end tag */ - $this->tagName = trim(substr($this->yytext(),1)); + $this->tagName = strtoupper(trim(substr($this->yytext(),1))); $this->tokenName = 'EndTag'; $this->yybegin(IN_ENDTAG); $this->value = ''; @@ -1728,7 +1728,7 @@ case 35: { // <img src="xxx" ^ismap> -- name */ - $this->attributes[trim($this->yytext())] = null; + $this->attributes[strtoupper(trim($this->yytext()))] = null; $this->value = ''; return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } @@ -1742,7 +1742,7 @@ case 37: { // <a ^href = "xxx"> -- attribute name - $this->attrKey = substr(trim($this->yytext()),0,-1); + $this->attrKey = strtoupper(substr(trim($this->yytext()),0,-1)); $this->yybegin(IN_ATTRVAL); $this->value = ''; return HTML_TEMPLATE_FLEXY_TOKEN_NONE; @@ -2049,7 +2049,7 @@ case 77: { //<name -- start tag */ - $this->tagName = trim(substr($this->yytext(),1)); + $this->tagName = strtoupper(trim(substr($this->yytext(),1))); $this->tokenName = 'Tag'; $this->value = ''; $this->attributes = array(); @@ -2071,7 +2071,7 @@ case 80: { /* </title> -- end tag */ - $this->tagName = trim(substr($this->yytext(),1)); + $this->tagName = strtoupper(trim(substr($this->yytext(),1))); $this->tokenName = 'EndTag'; $this->yybegin(IN_ENDTAG); $this->value = ''; @@ -2098,7 +2098,7 @@ case 84: { // <img src="xxx" ^ismap> -- name */ - $this->attributes[trim($this->yytext())] = null; + $this->attributes[strtoupper(trim($this->yytext()))] = null; $this->value = ''; return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } Index: pear/HTML_Template_Flexy/Flexy/Token/Tag.php diff -u pear/HTML_Template_Flexy/Flexy/Token/Tag.php:1.2 pear/HTML_Template_Flexy/Flexy/Token/Tag.php:1.3 --- pear/HTML_Template_Flexy/Flexy/Token/Tag.php:1.2 Fri Jan 31 12:28:40 2003 +++ pear/HTML_Template_Flexy/Flexy/Token/Tag.php Fri Jan 31 23:09:56 2003 @@ -16,7 +16,7 @@ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // -// $Id: Tag.php,v 1.2 2003/01/31 17:28:40 alan_k Exp $ +// $Id: Tag.php,v 1.3 2003/02/01 04:09:56 alan_k Exp $ /** * A standard HTML Tag = eg. Table/Body etc. @@ -89,7 +89,6 @@ function setValue($value) { global $_HTML_TEMPLATE_FLEXY_TOKEN; $this->tag = $value[0]; - $this->UCtag = strtoupper($value[0]); if (isset($value[1])) { $this->attributes = $value[1]; } @@ -113,7 +112,7 @@ } $ret = ''; - if ($foreach = $this->getAttribute('foreach')) { + if ($foreach = $this->getAttribute('FOREACH')) { $foreachObj = $this->factory('Foreach', explode(',',$foreach), $this->line); @@ -132,15 +131,22 @@ $ret .= " $k"; continue; } + + // if it's a string just dump it. if (is_string($v)) { $ret .= " {$k}={$v}"; continue; } + + // normally the value is an array of string, however + // if it is an object - then it's a conditional key. + // eg. if (something) echo ' SELECTED'; + if (is_object($v)) { $ret .= " " .$v->toString(); continue; } - + $ret .= " {$k}="; foreach($v as $item) { @@ -181,12 +187,12 @@ // form elements : format: //value - fill out as PHP CODE - $name = $this->getAttribute('name'); + $name = $this->getAttribute('NAME'); if ($_HTML_TEMPLATE_FLEXY_TOKEN['activeForm']) { $name = $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] .'.'.$name; } - $type = strtoupper($this->getAttribute('type')); + $type = strtoupper($this->getAttribute('TYPE')); $thisvar = str_replace(']','',$name); $thisvar = str_replace('[','.',$thisvar); @@ -253,7 +259,7 @@ // form elements : format: //value - fill out as PHP CODE - $name = $this->getAttribute('name'); + $name = $this->getAttribute('NAME'); if ($_HTML_TEMPLATE_FLEXY_TOKEN['activeForm']) { $name = $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] .'.'.$name; } @@ -288,12 +294,8 @@ * the options is the pullldown will have to be * $t->theform->getOptions('the_name_of_the_tag') * - * the tag is generated using HTML_Select - * - * However this requires that toString outputs something different. - eg. - * an overriden value.. * - * otherwise, It needs to generate a child like: + * I did look at HTML_Select - but since we output tags - this does most of the work anyway. * - for a key=>value array. * foreach($t->theform->getOptions('name') as $_k=>$_v) { * printf('<OPTION VALUE="%s"%s>%s</OPTION>', @@ -316,18 +318,21 @@ $call_object = '$t'; - if ($this->getAttribute('static')) { - return; - } - - - $basename = $this->getAttribute('name'); + $basename = $this->getAttribute('NAME'); $name = $basename; if ($_HTML_TEMPLATE_FLEXY_TOKEN['activeForm']) { $name = $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] .'.'.$name; $call_object = $this->toVar($_HTML_TEMPLATE_FLEXY_TOKEN['activeForm']); } + $_HTML_TEMPLATE_FLEXY_TOKEN['activeSelect'] = $name; + + if ($this->getAttribute('STATIC')) { + return; + } + + + @@ -344,8 +349,44 @@ ); } - - + /** + * Deal with Options (on a static select list) + * + * bascially add an attribute tag: + * if ($this->theform->thename_of_the_Tag == 'name/or contents') echo " SELECTED"; + * + * + * @return none + * @access public + */ + function parseTagOption() + { + + global $_HTML_TEMPLATE_FLEXY_TOKEN; + + + $name = $_HTML_TEMPLATE_FLEXY_TOKEN['activeSelect']; + + $php = '<? '; + + if ($this->getAttribute('SELECTED') === null) { + // then it's the default.. + // if no value is available for $this->the_form->the name of the tag... + // just leave it allown + $php .= "if (empty(".$this->toVar($name).")) echo ' SELECTED';"; + } + $value = $this->getAttribute('value'); + if (empty($value)) { + $value = $this->childrenToString(); + } + + + $php .= "if (".$this->toVar($name)." == \"". addslashes($value) . "\") echo ' SELECTED';"; + $php .= "?>"; + + $this->attributes['SELECTED'] = $this->factory("PHP", $php, $this->line); + + } @@ -368,7 +409,7 @@ { global $_HTML_TEMPLATE_FLEXY_TOKEN; - if ($name = $this->getAttribute('name')) { + if ($name = $this->getAttribute('NAME')) { $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] = $name; } @@ -384,7 +425,10 @@ * @access string */ function getAttribute($key) { - // really need to do a foreach/ strtoupper + // all attribute keys are stored Upper Case, + // however just to make sure we have not done a type :) + $key = strtoupper($key); + if (!isset($this->attributes[$key])) { return ''; }
« previous php.pear.cvs (#8622) next »