Ruby on Rails 插件开发流程
我正在考虑将网站的各个方面开发为 Rails 插件以供重用。我的问题是关于开发过程。由于每个插件都将提供功能“切片”,我是否应该将每个“切片”开发为自己的应用程序,然后将每个应用程序的代码提取到插件中?或者,我应该将它们作为插件编写在应用程序中吗?最终我将链接到每个站点的这些插件以保持干燥。
我想主要问题是创建多个“引擎”类型插件的开发过程是什么?
预先感谢您的任何帮助。
I'm considering developing aspects of a website as Rails plugins for reuse. My question is about the development process. Since each of these plugins will provide a "slice" of functionality, should I develop each "slice" as it's own application and then extract the code from each application into a plugin? Or, should I write them as plugins right in an application? Ultimately I will be linking to these plugins from each site to keep it DRY.
I guess the main question is what would be the development process for creating multiple "Engine" type plugins?
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
任何一种方法都是有效的。
在编写基本插件时,我通常发现将其与使用它的应用程序一起编写会更容易。因为我发现围绕已经存在的东西进行设计/测试更容易。
然而,当谈到引擎插件时,我更喜欢将它们开发为单独的应用程序,然后在将其移动到插件中时删除所有不必要的部分。它们本质上是迷你应用程序,当安装在新创建的 Rails 项目上时,它们应该具有完整的功能。
通过将它们设计为自己的应用程序,我可以确保适当的划分。这确保了我不会意外地引用不属于我正在开发的引擎的一部分的代码模型/控制器/视图/帮助器。
如果您以这种方式开发多个引擎类型插件,您可能需要使用实用程序脚本来压缩一些步骤。例如,简化将应用程序转变为引擎插件的过程。
它应该根据需要重组您的应用程序并填充插件应具有的文件,例如 init.rb。
Either approach is valid.
When writing a basic plugin I usually find it easier to write it in tandem with the application that will use it. Because I find it easier to design/test around something that already exists.
However, when it comes to Engine plugins, I prefer to develop them as a separate application and then rip out all the unnecessary bits when I move it into a plugin. They are in essence mini applications, and they should be completely functional when installed on a freshly created rails project.
By designing them as their own application I'm ensuring proper compartmentalization. This ensures that I'm not accidentally referring to code models/controllers/views/helpers that are not a part of the engine I'm developing.
If you're developing multiple engine type plugins this way, you might want to condense a few of the steps with a utility script. Such as one that streamlines the process of turning an application into an Engine plugin.
It should restructure your app as necessary and populate the files that plugins should have, such as init.rb.
您可能还想看看 Desert 框架。
You might want to give a look to Desert framework as well .