如何在其他 Rails 应用程序中重用组件和小部件?这是个好主意吗?
我构建了迷你小部件,其中包含一个模型、一个控制器、几个样式表和几行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一般来说,重用多个项目的代码是一个好主意。它减少了维护多组不同代码的需要,并且更容易快速实现功能。
我会专门为这些组件创建一个存储库,然后将其作为插件拉入您的代码库中。至于如何构造这个组件,它与 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.
插件 和
The plugin and gem paradigms for Ruby/Rails are well established. They are probably the best routes for re-use of components
Cells 使用统计信息(自 2010 年 9 月起):https://rubygems.org/gems/cells
Cells usage stats (since September 2010): https://rubygems.org/gems/cells