开发生成HTML的辅助函数:我应该使用嵌套的content_tag()还是局部函数? [英] Developing helper functions that generate HTML: should I rather use nested content_tag()s or partials?

查看:79
本文介绍了开发生成HTML的辅助函数:我应该使用嵌套的content_tag()还是局部函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正开始开发Rails引擎(和gem),该引擎应提供许多小的辅助功能,以生成用于视图的HTML.

I'm at the start of developing a Rails engine (and gem) that should provide many small helper functions that generate HTML for views.

现在,我想知道是否应该依靠使用许多嵌套的content_tag调用来生成HTML,还是仅依赖于部分代码是否更实用?

Now I wonder whether it's advisable to rely on the use of many nested content_tag calls to generate the HTML, or if it's more pragmatic to just rely on partials.

在我看来,第一种方法可能更干净(但性能较慢),但是第二种方法似乎更容易实现,所以我想我会偏爱第二种方法.你们怎么看?

In my opinion, the first approach may be a bit cleaner (but slower in performance), but the 2nd approach seems much easier to do, so I guess I will favor the 2nd one. What do you guys think?

推荐答案

许多嵌套的content_tag通话

听起来并不像您应该在助手中那样.我个人的限制是1或2个级别的标签,超出部分限制.

does not sound as if you should be doing this in a helper. 1 or 2 levels of tags is my personal limit, above that I go for the partial.

那只是我的感觉,这里不涉及任何理论:-)

Thats just my feeling, no theory involved here :-)

这篇关于开发生成HTML的辅助函数:我应该使用嵌套的content_tag()还是局部函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆