如何重命名或移动 Rails 的 README_FOR_APP
当我在 Rails 应用程序根目录中运行 rake doc:app
时,将使用 /doc/README_FOR_APP
作为主页生成 API 文档。我想向该文件添加 .rdoc
扩展名,以便在 GitHub 上正确呈现它。更好的是,我想将其移至应用程序根目录 (/README.rdoc
)。有没有办法通过修改包含的 rake/rdoctask
任务来在我的 Rakefile
中执行此操作?它是否在某个地方查找可以修改的主页文件的名称?或者我必须编写一个新的 Rake 任务吗?
附加问题:Rails 应用程序的两个单独文件 /README
和 /doc/README_FOR_APP
背后的逻辑是什么?为什么不只有一个呢?
When I run rake doc:app
in my Rails application root, the API docs are generated using /doc/README_FOR_APP
as the home page. I would like to add a .rdoc
extention to that file so it is properly rendered on GitHub. Even better, I would like to move it to the app root (/README.rdoc
). Is there a way to do this in my Rakefile
by modifying the included rake/rdoctask
task? Is there some place it looks for the name of the home page file that can be modified? Or do I have to write a new Rake task?
Bonus question: what is the logic behind the two separate files /README
and /doc/README_FOR_APP
for Rails applications? Why not just one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Rails rdoc 任务位于
/lib/tasks/documentation.rake
中,可以执行您想要的操作,获取 :app 任务并更改它,将其放入您的 .rake 文件中应用程序的 /lib/tasks
我不确定这是否正是它,但可以尝试一下并查看 rdoc 任务文档 了解更多信息。
Rails rdoc task is in
<rails gem folder>/lib/tasks/documentation.rake
to do what you want, take the :app task and alter it, putting it in a .rake file in your app's /lib/tasks
I'm not sure if that is exactly it, but play around with it and look at the rdoc task docs for more info.
执行您想要的操作:
README_FOR_APP
文件是在创建新的 Rails 应用程序时创建的。该代码位于rails-#.#.#\lib\rails_generator\generators\applications\app\app_generator.rb中。要添加后缀并更改所有 Rails 应用程序的位置,您可以将方法修改为:
然后,您需要修改 Rake 文档任务以包含此文件而不是旧文件,在
rails-# .#.#\lib\tasks\documentation.rake
:关于单独的`README_FOR_APP`和`README`文件的逻辑:
README_FOR_APP
,顾名思义是文档您的特定 Rails 应用程序,它涉及
您将要使用的类和方法
已经写了。
README
是所有 Rails 应用程序描述结构的通用文档Rails 应用程序和一些 Web 服务器设置。它的级别比
README_FOR_APP
更高。但是...
作为提示,我建议您保留这两个文件而不是重命名它们(不要忘记 Rail 的约定优于配置方面)。任何 Rails 开发人员都会期望这些文件存在,并且重命名它们可能会使事情变得更加复杂。
您的 IDE 也可能使用此约定。例如,我使用 Netbeans,Rails 项目视图已预先配置为显示某些文件。如果您将 README_FOR_APP 文件移至根目录,NetBeans 将不会在项目视图中显示它,您将不得不使用文件视图,或修改项目视图(不知道这是否可能) 。
To do what you want:
The
README_FOR_APP
file is created when creating a new Rails application. That code is inrails-#.#.#\lib\rails_generator\generators\applications\app\app_generator.rb
.To add a suffix and change the location for all of your Rails apps, you can modify the method to be:
Then, you need to modify the Rake documentation task to include this file rather than the old one, in
rails-#.#.#\lib\tasks\documentation.rake
:Regarding the logic of separate `README_FOR_APP` and `README` files:
README_FOR_APP
, as the name implies is documentation foryour specific Rails application, it concerns
the classes and methods that you will
have written.
README
is general documention for all Rails applications describing the structureof a Rails application and some web server settings. It's at a higher-level than
README_FOR_APP
.However...
As a tip, I would advise you to keep both files and not rename them (don't forget Rail's convention over configuration aspect). Any Rails developper will expect these files to be there, and renaming them might make things more complicated.
This convention might also be used by your IDE. For example, I use Netbeans, and the Rails project view is pre-configured to display certain files. If you move your
README_FOR_APP
file to the root directory, NetBeans will not display it in project view, you will have to use file view, or modify the project view (don't know if that's even possible).如果您在本地应用程序文件夹(例如,lib/tasks/doc.rake)中创建相同的任务,并像这样定义相同的任务:
那么该任务将在 Rails 的内置任务之后立即运行。因此,您不必搞乱 Rails 源,仍然可以实现您的目标。
If you create same task in your local app folder in, say,
lib/tasks/doc.rake
and define same task like this:then this task would be run right after rails' built-in task. Hence you wouldn't have to mess with rails sources and still accomplish your goal.