def extract_template(fileobj, keywords, comment_tags, options): src = force_text(fileobj.read(), settings.FILE_CHARSET) if fileobj.name.endswith(".jade"): src = process(src, compiler=Compiler) src = templatize(src, "") if "gettext" in src: return extract_python(StringIO.StringIO(src.encode("utf8")), keywords, comment_tags, options) return ()
def preprocess(self, source, name, filename = None): if (name and name.endswith('.jade')) or (filename and filename.endswith('.jade')): return pyjade.process(source, compiler=pyjade.ext.jinja.Compiler) result = '' start_pos = 0 while start_pos < len(source) - 1: match = self.tags_rx[0].search(source, start_pos) if not match: return result + source[start_pos:] result += source[:match.start()] start_pos = match.end() close = self.tags_rx[1].search(source, start_pos) if not close: raise TemplateSyntaxError('Expecting "endjade" tag', result.count('\n')) raw = source[match.end():close.start()] result += pyjade.process(raw, compiler=pyjade.ext.jinja.Compiler) start_pos = close.end() return result
def extract_template(fileobj, keywords, comment_tags, options): src = force_text(fileobj.read(), settings.FILE_CHARSET) if fileobj.name.endswith(".jade"): src = process(src, compiler=Compiler) src = templatize(src, "") if "gettext" in src: src = re.sub(r"\n\s+", "\n", src) # Remove indentation return extract_python(io.StringIO(src.encode("utf8")), keywords, comment_tags, options) return ()
def parse_jade(presentation_src): """Parses a jade_file, producing a mako template""" validation_re = re.compile("""(^(?!(\.slide)|(div\.slide)))|(\n(?!((\.slide)|(div\.slide))))""") if validation_re.match(presentation_src): raise Exception("Does not describe a deck.js slide deck") return pyjade.process(presentation_src)
def jade_compile(filename): from pyjade import process return process(contents(filename), filename)