Grails:调试脚手架模板

发布于 2024-08-30 07:34:17 字数 95 浏览 2 评论 0原文

有没有办法调试脚手架模板(在 /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轮廓§ 2024-09-06 07:34:17

通常,您不必“调试”模板,因为模板工作得相当好。

我认为您正在寻找跟踪数据流以对模板进行自己的修改,这将导致您使用打印语句。否则,您正在考虑使用页面渲染器。

因此,我推荐两个选项:

  1. 打印语句。这是一种简单的、经过验证的、真实的、强力的方法。一年前的 2011 年初,我在一个项目中使用过它,效果很好。缺点是它不可重用(除非您将代码注释掉,但这有点尴尬)。
    这使您可以逐步了解模板系统的“内部结构”,看看会发生什么。该框架无法真正向您“隐藏”任何内容,因此您可以第一排了解所发生的情况。

  2. 使用 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:

  1. 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.

  2. 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文