Grails:调试脚手架模板
有没有办法调试脚手架模板(在 /src/template/scaffolding 中生成)。不是调试视图 gsp 文件,而是调试模板本身。我想我可以发表一些评论..除此之外..
is there a way to debug the scaffolding template (generated in /src/template/scaffolding). Not to debug the view gsp files, but the template itself. I guess I could put some comments.. other than that..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您不必“调试”模板,因为模板工作得相当好。
我认为您正在寻找跟踪数据流以对模板进行自己的修改,这将导致您使用打印语句。否则,您正在考虑使用页面渲染器。
因此,我推荐两个选项:
打印语句。这是一种简单的、经过验证的、真实的、强力的方法。一年前的 2011 年初,我在一个项目中使用过它,效果很好。缺点是它不可重用(除非您将代码注释掉,但这有点尴尬)。
这使您可以逐步了解模板系统的“内部结构”,看看会发生什么。该框架无法真正向您“隐藏”任何内容,因此您可以第一排了解所发生的情况。
使用 grails.gsp.PageRenderer
这允许您在运行时调试事物,您可以创建适当的测试、断言、可重用组件等作品。您与实际模板有一点距离(与在模板内使用 print 语句相反)。
以下是 GRAILS 文档的链接:页面渲染文档
此处是有关如何使用它们的示例的链接: Grails 优点:渲染 GSP 视图和...
Normally you should not have to "debug" the template as the templates work rather well.
I am thinking you are looking for tracing the data flow to make your own modifications to the templates which will lead you to using print statements. Otherwise, you are looking at using the Page Renderer.
So, there are two options I would recommend:
Print statements. This is your easy, tried and true, brute force approach. I have used it a year ago in early 2011 for a project and it works well. The downside is that it is non reusable (unless you leave your code commented out but that's a bit awkward).
This allows you to step through the "guts" of the template system and see what happens. The framework cannot "hide" anything from you really, so you get a front-row seat at what happens.
Use the grails.gsp.PageRenderer
This allows you to debug things at runtime, you can create proper tests, asserts, reusable components, the works. You are a little removed from the actual templates (as opposed to using print statements inside the templates).
Here is a link to the GRAILS Doc: Page Rendering Doc
Here is a link to an example on how to use them: Grails Goodness: Render GSP Views and...