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 7 2009, 10:19 am
From: makoto kuwata <kwa...@gmail.com>
Date: Sun, 7 Jun 2009 07:19:09 -0700 (PDT)
Local: Sun, Jun 7 2009 10:19 am
Subject: Re: pyTenjin Feature Requests
Steve,

On 2009-06-07 12:18, makoto kuwata <kwa...@gmail.com> wrote:

> Here you are:

I'm sorry that MyTemlate class in previous mail has a bug.
For example, the following template reveals a bug.

ex2.pyhtml:

    <div>
      <div>
        <?py if foo: ?>
        foo
        <?py #end ?>
      </div>
      <?py if bar: ?>
      bar
      <?py #end ?>
    </div>

resutl:

    $ python main.py ex2.pyhtml | cat -n
         1  _buf.extend(('''<div>
         2    <div>\n''', ));
         3  if True: ## dummy
         4      if foo:
         5        _buf.extend(('''    foo\n''', ));
         6      #end
         7      _buf.extend(('''  </div>\n''', ));
         8    if bar:
         9      _buf.extend(('''  bar\n''', ));
        10    #end
        11    _buf.extend(('''</div>\n''', ));
        12

    $ python main.py ex2.pyhtml | python
      File "<stdin>", line 8
        if bar:
              ^
    IndentationError: unindent does not match any outer indentation
level

I hacked MyTempalte class again to solve this bug.

main2.py:

    import tenjin
    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 s and s.isspace() and s.find("\n") < 0:
                    spc = self._spaces
                    indent = ' ' * self.indent
                    while len(s) > len(spc):
                        buf[-1:-1] = (spc, "if True: ## dummy\n", )
                        spc += indent
            if self.newline == "\r\n":
                code = code.replace("\r\n", "\n")
            buf.append(code)

    if __name__ == '__main__':
        import sys
        if len(sys.argv) < 2: raise "template name is required."
        template = MyTemplate(sys.argv[1], indent=2)     # change
indent width to 2
        #tenjin.Engine.templateclass = MyTemplate
        #engine = tenjin.Engine(cache=False, indent=2)    # change
indent width to 2
        #template = engine.get_template(sys.argv[1])
        print(template.script)

result:

    $ python main2.py ex2.pyhtml
    _buf.extend(('''<div>
      <div>\n''', ));
    if True: ## dummy
      if True: ## dummy
        if foo:
          _buf.extend(('''    foo\n''', ));
        #end
        _buf.extend(('''  </div>\n''', ));
      if bar:
        _buf.extend(('''  bar\n''', ));
      #end
      _buf.extend(('''</div>\n''', ));

This solves the bug, but notice that this hack inserts
a number of dummy if-statements.
So you may not prefer this hack.

I think that it is very hard to control indents accurately
in Tenjin approach. To controll them, it is necessary to
parse Python statements and detect block correctly, like
Mako or Django does. But it makes Tenjin more complex and
heavy, so I wouldn't do that.
I'm sorry but I recommend to compromise at some level.

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