如何在其他 Rails 应用程序中重用组件和小部件?这是个好主意吗?

发布于 2024-10-01 03:34:14 字数 267 浏览 2 评论 0原文

我构建了迷你小部件,其中包含一个模型、一个控制器、几个样式表和几行 JavaScript。每当我发现我正在构建的下一个应用程序中需要类似的东西时,我就必须从我构建它们的应用程序中进行一些复制。不用说,这并不好玩。

所以我听说过像 Cells、Apotomo 和 Parts 这样的组件框架,它们有望减轻这种苦差事,但我找不到任何围绕它们的讨论或任何其他重要的社区活动、使用统计数据等来表明它们的采用。除了几篇博文之外,社区对组件框架保持着奇怪的沉默。这让我想知道:它们是个好主意吗?如果不是,为什么不呢?

I have built mini widgets that consist of a model, a controller a couple of stylesheets and a couple of lines of javascript. Whenever it turns out that I need something like that in the next app I am building, i have to do some copypasta from the app where I had built them. Needless to say, that is not fun.

So I've heard about component frameworks like Cells, Apotomo and Parts, which promise to alleviate this chore, but I couldn't find any discussion around them or any other significant community activity, usage stats, and so on, to indicate their adoption. Except for a few blogposts, the community is oddly silent about component frameworks. That makes me wonder: are they a good idea and if they are not, why not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

杀手六號 2024-10-08 03:34:14

一般来说,重用多个项目的代码是一个好主意。它减少了维护多组不同代码的需要,并且更容易快速实现功能。

我会专门为这些组件创建一个存储库,然后将其作为插件拉入您的代码库中。至于如何构造这个组件,它与 github 上可用的任何其他 gem 相同,为您提供正确的命名空间项,您可以轻松地在应用程序之间移植它,而不会出现问题。

Reusing code from multiple projects is in general a good idea. It reduces the need to maintain multiple different sets of code and makes it easier to implement functionality quickly.

I would create a repo specifically for those components and simply pull it into your codebase as a plugin. As for how to structure this component its identical to any other gem available on github , providing you namespace items correctly you can port it easily between applications without issue.

不知所踪 2024-10-08 03:34:14

插件

The plugin and gem paradigms for Ruby/Rails are well established. They are probably the best routes for re-use of components

猫九 2024-10-08 03:34:14

Cells 使用统计信息(自 2010 年 9 月起):https://rubygems.org/gems/cells

Cells usage stats (since September 2010): https://rubygems.org/gems/cells

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