Permalink
Browse files

Fixed bugs

  • Loading branch information...
1 parent a5788e8 commit 6459a9e347e258c9934a75727d76e61e07e1da92 @syrusakbary committed Mar 27, 2012
View
@@ -2,7 +2,7 @@
app = Flask(__name__)
app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')
-
+app.debug = True
@app.route('/')
@app.route('/<name>')
def hello(name=None):
@@ -7,9 +7,9 @@ class Compiler(_Compiler):
autocloseCode = 'if,ifchanged,ifequal,ifnotequal,for,block,filter,autoescape,with,blocktrans,spaceless,comment,cache,localize,compress'.split(',')
def visitCodeBlock(self,block):
self.buffer('{%% block %s %%}'%block.name)
- if block.mode=='prepend': self.buffer('{{block.super}}')
- self.visitBlock(block)
if block.mode=='append': self.buffer('{{block.super}}')
+ self.visitBlock(block)
+ if block.mode=='prepend': self.buffer('{{block.super}}')
self.buffer('{% endblock %}')
def visitAssignment(self,assignment):
self.buffer('{%% __pyjade_set %s = %s %%}'%(assignment.name,assignment.val))
View
@@ -2,13 +2,14 @@
import os
from pyjade import Parser, Compiler as _Compiler
from pyjade.runtime import attrs
+from jinja2.debug import fake_exc_info
ATTRS_FUNC = '__pyjade_attrs'
class Compiler(_Compiler):
def visitCodeBlock(self,block):
self.buffer('{%% block %s %%}'%block.name)
- if block.mode=='prepend': self.buffer('{{super()}}')
- self.visitBlock(block)
if block.mode=='append': self.buffer('{{super()}}')
+ self.visitBlock(block)
+ if block.mode=='prepend': self.buffer('{{super()}}')
self.buffer('{% endblock %}')
def visitMixin(self,mixin):
if mixin.block:
@@ -54,13 +55,26 @@ def attributes(self,attrs):
class PyJadeExtension(Extension):
+ # def exception_handler(self,pt):
+ # # print '******************************'
+ # # print pt.exc_type
+ # # print pt.exc_value
+ # # print pt.frames[0].tb
+ # # line = pt.frames[0].tb.tb_lineno
+ # # pt.frames[0].tb.tb_lineno = line+10
+
+ # # print '******************************'
+ # _,_,tb = fake_exc_info((pt.exc_type,pt.exc_value, pt.frames[0].tb),'asfdasfdasdf',7)
+ # # pt.frames = [tb]
+ # raise pt.exc_type, pt.exc_value, tb
def __init__(self, environment):
super(PyJadeExtension, self).__init__(environment)
environment.extend(
jade_file_extensions=('.jade',),
# jade_env=JinjaEnvironment(),
)
+ # environment.exception_handler = self.exception_handler
environment.globals[ATTRS_FUNC] = attrs
def preprocess(self, source, name, filename=None):
View
Binary file not shown.
View
@@ -11,9 +11,9 @@ def interpolate(self,text):
def visitCodeBlock(self,block):
self.buffer('<%%block name="%s">'%block.name)
- if block.mode=='prepend': self.buffer('${parent.%s()}'%block.name)
- self.visitBlock(block)
if block.mode=='append': self.buffer('${parent.%s()}'%block.name)
+ self.visitBlock(block)
+ if block.mode=='prepend': self.buffer('${parent.%s()}'%block.name)
self.buffer('</%block>')
def visitMixin(self,mixin):
if mixin.block:
View
@@ -5,7 +5,7 @@
textOnly = ('script','style')
class Parser(object):
- def __init__(self,str,filename,**options):
+ def __init__(self,str,filename=None,**options):
self.input = str
self.lexer = Lexer(str,**options)
self.filename = filename
View
@@ -0,0 +1,28 @@
+import pyjade
+a = pyjade.Parser('''doctype 5
+html
+ head: title Hello from flask
+ body(attr="2" ba=2)
+ if name
+ h1(class="red") Hello
+ = name
+ span.description #{name|capitalize} is a great name!
+ else
+ h1 Hello World!''')
+block = a.parse()
+import pyjade.ext.jinja
+compiler = pyjade.ext.jinja.Compiler(block)
+print compiler.compile()
+# OUT: <!DOCTYPE html>
+# OUT: <html{{__pyjade_attrs(terse=True)}}>
+# OUT: <head{{__pyjade_attrs(terse=True)}}>
+# OUT: <title{{__pyjade_attrs(terse=True)}}>Hello from flask
+# OUT: </title>
+# OUT: </head>
+# OUT: <body{{__pyjade_attrs(terse=True, attrs=[('attr',("2" ba=2))])}}>{% if name %}
+# OUT: <h1{{__pyjade_attrs(terse=True, attrs=[('class', (("red")))])}}>Hello {{name|escape}}
+# OUT: </h1><span{{__pyjade_attrs(terse=True, attrs=[('class', (('description')))])}}>{{name|capitalize}} is a great name!</span>{% else %}
+# OUT: <h1{{__pyjade_attrs(terse=True)}}>Hello World!
+# OUT: </h1>{% endif %}
+# OUT: </body>
+# OUT: </html>

0 comments on commit 6459a9e

Please sign in to comment.