I think the point of a template is that it {{.}} is turned into code but
stuff outside is left unchanged. I'd rather leave this as it is. But thanks
for brining this up.
On Wednesday, 11 July 2012 13:33:44 UTC-5, Rob wrote:
>
> Thanks Massimo.
>
> That prints out:
> hihihi
>
>
> If you change it to:
> {{for d in data[:3]:
> = "hi\n"
> pass}}
>
> It prints out (spacing gets messed up):
> hi
> hi
> hi
>
> Anyway, you probably aren't interested in a patch (see attached), but this
> patch has been working pretty good for me when using my original syntax.
> Although, I don't know if there are any unforeseen consequences since I'm
> not using the templating engine to it's full potential right now.
>
> UPDATE: the attached patch matches template lines like {{for d in
> data[:3]:}}{{foo = 5}}{{=foo}} which it shouldn't (I think) and my regex
> foo is weak :/
>
> UPDATE2:
> r_whitespace_cleanup = re.compile(r' *?(\{\{([^=])(.*?)\}\})[^\S\n]*\n*',re
> .MULTILINE)
> This is better, but still not perfect.
>
> Thanks,
> Rob
>
> On Tuesday, July 10, 2012 8:07:16 PM UTC-7, Massimo Di Pierro wrote:
>>
>> You can do
>>
>> {{for d in data[:3]:
>> = "hi"
>> pass}}
>>
>> to achieve when you want.
>>
>> On Tuesday, 10 July 2012 16:08:40 UTC-5, Rob wrote:
>>>
>>> Hi,
>>>
>>> I'm using the standalone template.py to generate non html files and the
>>> excess whitespace is making this somewhat painful.
>>>
>>> For example, my view:
>>> #ifndef __BLAH__
>>> #define __BLAH__
>>> {{for d in data[:3]:}}
>>> {{= "hi"}}
>>> {{pass}}
>>> #endif
>>>
>>> outputs:
>>> #ifndef __BLAH__
>>> #define __BLAH__
>>>
>>> hi
>>>
>>> hi
>>>
>>> hi
>>>
>>> #endif
>>>
>>> I'm sure there are lots of reasons why this can't happen, but I propose
>>> that render() simply removes lines that contain nothing but whitespace and
>>> logic. For example, given the same view:
>>> 1 #ifndef __BLAH__
>>> 2 #define __BLAH__
>>> 3 {{for d in data[:3]:}}
>>> 4 {{= "hi"}}
>>> 5 {{pass}}
>>> 6 #endif
>>>
>>> Line number 3 and 6 contain nothing but template logic and whitespace
>>> (with excess carriage returns). Is there a reason why the rendering engine
>>> couldn't simply remove this whitespace from the output? IE: if the line
>>> contains pure logic ({{...}}) and whitespace, just remove it. If the line
>>> contains {{=..}} and other whitespace then it stays.
>>>
>>> Does this break all sorts of HTML output?
>>>
>>> Thanks,
>>> Rob
>>>
>>