Exemplo n.º 1
0
 def templatize(src, origin=None, **kwargs):
     #if the template has no origin file then do not attempt to parse it with haml
     if origin:
         #if the template has a source file, then only parse it if it is haml
         if os.path.splitext(origin)[1].lower() in [
                 '.' + x.lower() for x in hamlpy.VALID_EXTENSIONS
         ]:
             hamlParser = hamlpy.Compiler()
             src = hamlParser.process(src)
     return func(src, origin=origin, **kwargs)
Exemplo n.º 2
0
 def preprocess(self, source, name, filename=None):
     if name and has_any_extension(name, HAML_FILE_NAME_EXTENSIONS):
         compiler = hamlpy.Compiler()
         try:
             return compiler.process(source)
         except Exception as e:
             raise jinja2.TemplateSyntaxError(e,
                                              1,
                                              name=name,
                                              filename=filename)
     else:
         return source
Exemplo n.º 3
0
def compile_file(fullpath, outfile_name):
    """Calls HamlPy compiler."""
    print '%s %s -> %s' % ( strftime("%H:%M:%S", gmtime()), fullpath, outfile_name )
    try:
        if DEBUG:
            print "Compiling %s -> %s" % (fullpath, outfile_name)
        haml_lines = codecs.open(fullpath, 'r', encoding='utf-8').read().splitlines()
        compiler = hamlpy.Compiler()
        output = compiler.process_lines(haml_lines)
        outfile = codecs.open(outfile_name, 'w', encoding='utf-8')
        outfile.write(output)
    except Exception, e:
        # import traceback
        print "Failed to compile %s -> %s\nReason:\n%s" % (fullpath, outfile_name, e)
Exemplo n.º 4
0
 def templatize(src, origin=None):
     hamlParser = hamlpy.Compiler()
     html = hamlParser.process(src.decode('utf-8'))
     return func(html.encode('utf-8'), origin)
Exemplo n.º 5
0
 def templatize(src, origin=None):
     hamlParser = hamlpy.Compiler()
     html = hamlParser.process(src)
     return func(html, origin)