Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Message from discussion pyTenjin Feature Requests
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
makoto kuwata  
View profile  
 More options Jun 5 2009, 11:33 pm
From: makoto kuwata <kwa...@gmail.com>
Date: Fri, 5 Jun 2009 20:33:01 -0700 (PDT)
Local: Fri, Jun 5 2009 11:33 pm
Subject: Re: pyTenjin Feature Requests
Hi Steve, thank you for trying pyTenjin.

On 2009-06-06 3:37, Steve <unetright.thebas...@xoxy.net> wrote:

> The indentation levels of the <?py ?> statements are mandatory to be
> separate from my indentation of the html content.  Instead, I would
> like to be able to use whatever indentation is appropriate for the
> html as long as it is constant between <?py ?> statements.  For
> example:

> <body>
>     <div>
>         <p>
>             <?py if boolean: ?>
>                 some conditional text
>             <?py #endif ?>
>         </p>
>     </div>
> </body>

What I can do is to extend Template class to add dummy 'if' statement.

main.py:

    import tenjin
    from tenjin.helpers import *

    class MyTemplate(tenjin.Template):

        def convert(self, input, filename=None):
            self._is_first_stmt = True
            return tenjin.Template.convert(self, input, filename)

        def add_stmt(self, buf, code):
            if self._is_first_stmt:
                if buf and buf[-1] != "\n" and buf[-1].isspace():
                    indent = buf.pop()
                    tenjin.Template.add_stmt(self, buf, "if True: ##
dummy\n")
                    buf.append(indent)
                self._is_first_stmt = False
            tenjin.Template.add_stmt(self, buf, code)

    print(MyTemplate('ex.pyhtml').script)
    #tenjin.Engine.templateclass = MyTemplate
    #engine = tenjin.Engine()
    #print engine.get_template('ex.pyhtml').script

ex.pyhtml:

    <html>
      <body>
        <ul>
          <?py if items: ?>
          <?py   for item in items: ?>
          <li>#{item}</li>
          <?py   #endfor ?>
          <?py #endif ?>
        </ul>
      </body>
    </html>

result:

    $ python main.py
    _buf.extend(('''<html>
      <body>
        <ul>\n''', ));
    if True: ## dummy
          if items:
            for item in items:
                _buf.extend(('''      <li>''', to_str(item), '''</li>
\n''', ));
            #endfor
          #endif
          _buf.extend(('''    </ul>
      </body>
    </html>\n''', ));

This hack will work well, but notice that it changes line number
of converted script, so you will get '+1' line number when you
have error reported.

> Another problem I have is that my django templates get pre-processed
> with an html compressor which strips out redundant whitespace.  Since
> I indent my html liberally and use 4 spaces per indentation, there is
> a 30% reduction with this processing.  Yes I do know this is minimized
> with html gzip transfer encoding.  Howerver some browsers ( *cough* IE
> *cough* ) have caching and etag bugs with respect to gzip'd content.

'30% reduction' is very impressive.
Hmm, it is difficult for Tenjin to strip spaces automatically and
correctly.
I don't have a good solution for this issue, but I'll try to think it.

--
regards,
makoto kuwata


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.