嵌入式python解释器(非常类似于ruby的erb)。
wemp的Python项目详细描述
wempy是一个命令行工具,用于解析嵌入式python(类似于ruby ERB)。wempy的语法是纯python,有3个非常重要的区别:
- There is no need for indentation
- The python keyword ‘pass’ must be used to indicate the end of some satements, blocks, and loops (like if/else, Try/Except, for or while ) depending on context
- ‘extend’ and ‘include’ are special keywords used to make templates (which can inherit)
示例
% wempy <<-EOF {{first_name = 'Tyler'}} {{last_name = 'Durden'}} Hello Mr. {{=last_name}} or shall I call you {{=first_name}} instead? EOF
这将生成以下输出:
Hello Mr. Durden or shall I call you Tyler instead?
您可以看到使用-x标志生成并执行的python脚本。
% wempy -x <<-EOF {{first_name = 'Tyler'}} {{last_name = 'Durden'}} Hello Mr. {{=last_name}} or shall I call you {{=first_name}} instead? EOF
打印出来的是:
import sys sys.stdout.write(' ') first_name = 'Tyler' sys.stdout.write('\n ') last_name = 'Durden' sys.stdout.write('\n Hello Mr. ') sys.stdout.write(last_name) sys.stdout.write(' or shall I call you ') sys.stdout.write(first_name) sys.stdout.write(' instead?\n')
py演示了如何使用wemplate库。但这里有一个简短的摘要:
>> import wemplate.wemplate >> text="Hello {{=planet}} !" >> parser = wemplate.wemplate.TemplateParser(text) >> >> print parser.render(planet="World") #print the rendered template 'Hello World !'
原点
Wempy直接取自Web2py的模板引擎。我们移走了一些 像Gluon集成包装函数、响应对象和 HTML/XML转义。
该名称代表(w)eb2py(em)bedded(py)thon
许可证
由于web2py是在lgpl v3下获得许可的,因此wempy也是如此
主页
有关详细信息,请访问http://www.wempy.org