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 6 2009, 11:18 pm
From: makoto kuwata <kwa...@gmail.com>
Date: Sat, 6 Jun 2009 20:18:57 -0700 (PDT)
Local: Sat, Jun 6 2009 11:18 pm
Subject: Re: pyTenjin Feature Requests
On 2009-06-07 12:31, Steve <unetright.thebas...@xoxy.net> wrote:

>  Is there anyway
> your subclass technique might be modified to support the following:
(...snip...)
> Notice in this example that bool2 and bool3 conditionals appear and
> different indentations because of the structure of the html.  But in
> python, they must appear at equal indentation levels.  Is there any
> way to handle that?

Here you are:

main.py:

    import tenjin    # 0.7.0 or 0.8.0
    from tenjin.helpers import *

    class MyTemplate(tenjin.Template):

        def add_stmt(self, buf, code):
            if buf:
                s = buf[-1]
                if s and s.isspace() and s.find("\n") < 0 and len(s) >
len(self._spaces):
                    buf[-1:-1] = (self._spaces, "if True: ## dummy
\n", )
            if self.newline == "\r\n":
                code = code.replace("\r\n", "\n")
            buf.append(code)

    if __name__ == '__main__':
        tenjin.Engine.templateclass = MyTemplate
        engine = tenjin.Engine()
        template = engine.get_template("ex.pyhtml")
        print(template.script)

ex.pyhtml:

    <html>
      <body>
        <?py if bool1: ?>
          <div class="a">
            <div class="b">
              <p>
                text line A
                <?py if bool2: ?>
                  text line B
                <?py #endif bool2 ?>
                text line C
              </p>
            </div>
            <?py if bool3: ?>
              <p>
                text line D
              </p>
            <?py #endif bool3 ?>
          </div>
        <?py #endif bool1 ?>
      </body>
    </html>

result:

    $ python main.py
    _buf.extend(('''<html>
      <body>\n''', ));
    if True: ## dummy
        if bool1:
            _buf.extend(('''      <div class="a">
            <div class="b">
              <p>
                text line A\n''', ));
            if True: ## dummy
                if bool2:
                    _buf.extend(('''              text line B
\n''', ));
                #endif bool2
                _buf.extend(('''            text line C
              </p>
            </div>\n''', ));
            if bool3:
                _buf.extend(('''          <p>
                text line D
              </p>\n''', ));
            #endif bool3
            _buf.extend(('''      </div>\n''', ));
        #endif bool1
        _buf.extend(('''  </body>
    </html>\n''', ));

You can see that dummy if-statement is inserted before
'if bool1:' and 'if bool2:'.
Notice that this makes line numbers changed.
For exaple if you have an error on line 10, it may be
reported as line 11 or 12.

I hope this helps you.

--
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.