[jifty-devel] Form fields and output

Jesse Vincent jesse at bestpractical.com
Sat Nov 25 15:43:17 EST 2006


On Nov 25, 2006, at 7:16 AM, Gaal Yahas wrote:

> On Sat, Nov 25, 2006 at 02:00:11AM -0500, Jesse Vincent wrote:
>>> A form field object stringifies to "" but triggers writing its  
>>> HTML to
>>> the web output. Has it been considered to just return the HTML?
>>
>> Short answer: I'm very, very sorry and would like to improve matters.
>> Patches are most welcome.  It was an early and expedient hack that  
>> never
>> got cleaned up.
>
> Here's a patch; not committing since a discussion on IRC brought up  
> some
> issues.
>
> First of all, the historical reason for ->out()ing fields and not
> returning their text turns out to be that <% $ff %> escapes HTML by
> default. Applying this patch directly would break a lot of existing
> apps! And adding |n everywhere in the templates is a bit of a hassle.
>
> Alex proposed a patch <http://paste.husk.org/7240> that overrides < 
> % %>
> blocks to not apply escapes to Jifty::Web::Form::Elements. If the code
> below is to be taken in, it should be used in conjunction with Alex's.
> But even then it doesn't Just Work yet; e.g. it breaks Wifty's title,
> perhaps because of _("").


I have an idea that might hurt a little bit less heavyweight. Mason's  
<% %> tag evaluates in list context, whereas "my $x = ..." evaluates  
in scalar context.

What I'd recommend is having a single method that outputs if you're  
calling in list or void context but gives you back the value if  
you're asking politely. (in scalar context).

Thoughts?


This mason template:

<% foo() %>
<% my $x=  foo() %>


<%init>

sub foo {
     if (wantarray()) {
         warn "List context!";
     } elsif (defined wantarray()) {
         warn "Scalar context!";
     } else {
         warn "Void Context!";
     }

}
</%init>


Gives this output:


WARN - List context! at /Users/jesse/svk/hiveminder-trunk/html/wanty  
line 6, <DATA> line 16.
WARN - Scalar context! at /Users/jesse/svk/hiveminder-trunk/html/ 
wanty line 8, <DATA> line 16.




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.bestpractical.com/pipermail/jifty-devel/attachments/20061125/cb0c00b0/attachment-0001.htm


More information about the jifty-devel mailing list