我真的很喜欢在 Pylons 和其他几个 Python 框架中使用的 Mako 模板系统,我唯一的抱怨是即使是一个简单的继承方案也会有多少 WS 泄漏。
无论如何要在下面完成,而不会造成如此巨大的 WS 差距......或者像我开始使用 base.mako 那样打包我的代码?
否则,要掌握我要在下面完成的工作。
Base 有点像整个应用程序的所有视图的界面类,布局只是 3-4 个不同布局文件(表格、纯 CSS 等)的原型想法,控制器/动作是一个测试,以确保我的想法是理智的。
问题的简短摘要:如何删除在我的 Mako 方案中创建的 WS?
更新:这不是一个解决方案,因为它涉及使用 \'s http://www.makotemplates.org/docs/syntax.html#syntax_newline播种我所有的 mako 文件
/base.mako
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><%def name="headtags()"></%def>${self.headtags()}</head>
<body>
<%def name="header()"></%def>${self.header()}${next.body()}<%def name="footer()"></%def>${self.footer()}
</body>
</html>
/layout.mako
<%inherit file="/base.mako"/>
<%def name="headtags()">
${parent.headtags()}
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js"></script>
</%def>
<%def name="header()">
<h1>My Blogination</h1>
</%def>
<div id="content">${next.body()}</div>
/控制器/action.mako
<%inherit file="/layout.mako" />
<%def name="headtags()">
<title> Hello world, templating system is 1 percent done</title>
${parent.headtags()}
</%def>
Hello ${c.name}!
渲染输出:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title> Hello world, templating system is 1 percent done</title>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.3/prototype.js"></script>
</head>
<body>
<h1>My Blogination</h1>
<div id="content">
Hello Anonymous!
</div>
</body>
</html>