如何重命名或移动 Rails 的 README_FOR_APP

发布于 2024-08-17 21:35:46 字数 431 浏览 4 评论 0原文

当我在 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 技术交流群。

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

发布评论

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

评论(3

追我者格杀勿论 2024-08-24 21:35:46

Rails rdoc 任务位于 /lib/tasks/documentation.rake 中,

可以执行您想要的操作,获取 :app 任务并更改它,将其放入您的 .rake 文件中应用程序的 /lib/tasks

#clear the doc:app task et al
Rake::Task["doc:app"].clear
Rake::Task["doc/app"].clear
Rake::Task["doc/app/index.html"].clear

namespace :doc do
  desc "Generate documentation for the application. Set custom template with TEMPLATE=/path/to/rdoc/template.rb or title with TITLE=\"Custom Title\""
  Rake::RDocTask.new("app") { |rdoc|
    rdoc.rdoc_dir = 'doc/app'
    rdoc.template = ENV['template'] if ENV['template']
    rdoc.title    = ENV['title'] || "Rails Application Documentation"
    rdoc.options << '--line-numbers' << '--inline-source'
    rdoc.options << '--charset' << 'utf-8'
    rdoc.rdoc_files.include('app/**/*.rb')
    rdoc.rdoc_files.include('lib/**/*.rb')
    rdoc.rdoc_files.include('README')
    rdoc.main = 'README'
  }
end

我不确定这是否正是它,但可以尝试一下并查看 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

#clear the doc:app task et al
Rake::Task["doc:app"].clear
Rake::Task["doc/app"].clear
Rake::Task["doc/app/index.html"].clear

namespace :doc do
  desc "Generate documentation for the application. Set custom template with TEMPLATE=/path/to/rdoc/template.rb or title with TITLE=\"Custom Title\""
  Rake::RDocTask.new("app") { |rdoc|
    rdoc.rdoc_dir = 'doc/app'
    rdoc.template = ENV['template'] if ENV['template']
    rdoc.title    = ENV['title'] || "Rails Application Documentation"
    rdoc.options << '--line-numbers' << '--inline-source'
    rdoc.options << '--charset' << 'utf-8'
    rdoc.rdoc_files.include('app/**/*.rb')
    rdoc.rdoc_files.include('lib/**/*.rb')
    rdoc.rdoc_files.include('README')
    rdoc.main = 'README'
  }
end

I'm not sure if that is exactly it, but play around with it and look at the rdoc task docs for more info.

话少情深 2024-08-24 21:35:46

执行您想要的操作:

README_FOR_APP 文件是在创建新的 Rails 应用程序时创建的。该代码位于rails-#.#.#\lib\rails_generator\generators\applications\app\app_generator.rb中。

要添加后缀并更改所有 Rails 应用程序的位置,您可以将方法修改为:

def create_documentation_file(m)
  # was m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
  m.file "doc/README_FOR_APP", "README_FOR_APP.rdoc" 
end

然后,您需要修改 Rake 文档任务以包含此文件而不是旧文件,在 rails-# .#.#\lib\tasks\documentation.rake:

Rake::RDocTask.new("app") { |rdoc|
  ...
  rdoc.rdoc_files.include('README_FOR_APP.rdoc') # was 'doc/README_FOR_APP'
}

关于单独的`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 in rails-#.#.#\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:

def create_documentation_file(m)
  # was m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
  m.file "doc/README_FOR_APP", "README_FOR_APP.rdoc" 
end

Then, you need to modify the Rake documentation task to include this file rather than the old one, in rails-#.#.#\lib\tasks\documentation.rake:

Rake::RDocTask.new("app") { |rdoc|
  ...
  rdoc.rdoc_files.include('README_FOR_APP.rdoc') # was 'doc/README_FOR_APP'
}

Regarding the logic of separate `README_FOR_APP` and `README` files:

  • README_FOR_APP, as the name implies is documentation for
    your specific Rails application, it concerns
    the classes and methods that you will
    have written.
  • README is general documention for all Rails applications describing the structure
    of 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).

长安忆 2024-08-24 21:35:46

如果您在本地应用程序文件夹(例如,lib/tasks/doc.rake)中创建相同的任务,并像这样定义相同的任务:

namespace :doc do
  task :app do
    # some code that adds rdoc extension
  end
end

那么该任务将在 Rails 的内置任务之后立即运行。因此,您不必搞乱 Rails 源,仍然可以实现您的目标。

If you create same task in your local app folder in, say, lib/tasks/doc.rake and define same task like this:

namespace :doc do
  task :app do
    # some code that adds rdoc extension
  end
end

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.

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