Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.3.13

Request #10248 Additional Flexy Attributes
Submitted: 2007-03-02 21:39 UTC
From: rick at coalescentdesign dot com Assigned:
Status: Open Package: HTML_Template_Flexy (version 1.2.5)
PHP Version: Irrelevant OS: win2k
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 45 - 13 = ?

 
 [2007-03-02 21:39 UTC] rick at coalescentdesign dot com (Rick Jolly)
Description: ------------ Flexy is almost a full "template attribute language". It supports conditionals and loops using flexy:xxx attributes, but it is missing a few things (such as those included in phpTal). With the addition of a few new flexy attributes, placeholders could be virtually eliminated from source templates. The advantage is cleaner source templates that appear the same in a browser with or without the addition of flexy markup. Furthermore, default content added by a designer could remain in the source template for viewing as html, even though dynamic content would replace it when running php. Requested flexy attributes: "Flexy:content" template: <span flexy:content="myvar">will be replaced by myvar</span> output: <span>contents of myvar</span> "Flexy:replace" template: <span flexy:replace="myvar">element will be replaced by myvar</span> <span flexy:replace="">element will be deleted</span> output: contents of myvar "Flexy:omit-tag" (useful when the purpose of the tag is just to hold flexy attributes like conditionals and foreach loops) template: <span tal:omit-tag="">this text will appear but the tags will be removed</span> output: this text will appear but the tags will be removed

Comments

 [2007-03-03 04:35 UTC] alan_k (Alan Knowles)
Have a look at this file, it should be quite easy to add all that in there. http://cvs.php.net/viewvc.cgi/pear/HTML_Template_Flexy/Flexy/Compiler/Flexy/Flexy.php?view=markup
 [2007-03-04 03:10 UTC] rick at coalescentdesign dot com
Thank you for your response Alan. The class you suggested seems to allow for the addition of new flexy namespaced tags, which is excellent, but I was hoping to add new flexy namespaced attributes. The other class in the directory, Tag.php, is what I was looking for. I'll mess around with the ToString method and follow up with my results.
 [2007-03-08 03:10 UTC] rick at coalescentdesign dot com
I was able to add the new flexy namespaced attributes as outlined above. I would be happy to share if anyone is interested. Here's what I did... I created a new class that handles some new flexy namespaced attributes. All it does is modify the element token in different ways depending on what new attribute is found. It is a lot like the existing HTML_Template_Flexy_Compiler_Flexy_Flexy class which handles flexy namespaced tags. I had to make minor changes to the toString method of the HTML_Template_Flexy_Compiler_Flexy_Tag class to avoid printing opening and closing tags for flexy:replace and flexy:omittag. Changes to Tag.php (HTML_Template_Flexy_Compiler_Flexy_Tag) toString() method: - Before converting the element token opening tag, child tokens, or closing tag: include and call the new class to handle custom flexy namespaced attributes. Pass in the element token as a parameter. - Check that the element token tag is defined before converting the opening tag and attributes to string. - Check that the element tokens tag is defined before converting the closing tag to string. If not defined, then just convert the closing tag postfix token to string.
 [2007-03-08 03:18 UTC] alan_k (Alan Knowles)
Can you try the submit a patch button.? Thanks Alan
 [2007-03-08 03:49 UTC] rick at coalescentdesign dot com
I would love to, but this Pear bug tracking application could use some help. I was able to make this request by just creating a password, but to submit a patch I now need a username as well. I tried to create a new account two days ago but my email has not been verified.
 [2007-03-09 05:35 UTC] alan_k (Alan Knowles)
Try pastebin.com - I think the patch stuff is still a bit buggy..
 [2007-03-09 17:38 UTC] rick at coalescentdesign dot com
The following post has the new class and the modifications to the Tag.php toString() method. http://pastebin.ca/387806 Any changes/suggestions are welcome. Thanks, Rick
 [2007-03-10 05:28 UTC] alan_k (Alan Knowles)
Can you test the code in CVS- I've changed bit's to conform to CS.. but it should be pretty much the same. Regards Alan
 [2007-03-25 23:07 UTC] rick at coalescentdesign dot com
Hi Allan, I found some duplicate code in the CVS version of the toString() method of HTML_Template_Flexy_Compiler_Flexy_Tag. The following code can be deleted since it was moved to "toStringChildren($element,$ret)" and "toStringCloseTag($element,$ret)": /* // dump contents of script raw - to prevent gettext // print_r($element); if ($element->tag == 'SCRIPT') { foreach($element->children as $c) { //print_R($c); if (!$c) { continue; } if ($c->token == 'Text') { $ret .= $c->value; continue; } // techically we shouldnt have anything else inside of script tags. // as the tokeinzer is supposted to ignore it.. } } else { $add = $element->compileChildren($this->compiler); if (is_a($add,'PEAR_Error')) { return $add; } $ret .= $add; } */ // output the closing tag. /* if ($element->close) { $add = $element->close->compile($this->compiler); if (is_a($add,'PEAR_Error')) { return $add; } $ret .= $add; } */ Everything seems to work well once that code is commented out, with one exception. Maybe you have some insight into a bug of mine that I just noticed. When in a foreach loop in the source template, local variables will be referenced within a method (<span flexy:content="someMethod(loopKeyOrValue)">...), but not as a variable (<span flexy:content="loopKeyOrValue">...). Instead, a nonexistent template variable is referenced. The code responsible is in the "replaceChildren(&$element,&$val)" method of the new CustomFlexyAttributes class: ... $childToken = $element->factory('Method',array(substr($val,0,strpos($val,'(')), $args_clean), $element->line); // WILL reference local foreach variables } else { $childToken = $element->factory('Var', '{'.$val.'}', $element->line); // WON'T reference local foreach variables } I must be using the "Var" factory method incorrectly? Thank you, Rick Jolly
 [2008-01-31 11:20 UTC] alan_k (Alan Knowles)
I pulled the code from the release version, as i missed your comment - it's back in CVS, but I dont have time to look at the issue you mention below. - it should appear in the next release.... whenever that is....