【问题标题】:Rake aborted! Don't know how to build task 'doc:app'瑞克失败了!不知道如何构建任务 'doc:app'
【发布时间】:2016-04-22 22:49:47
【问题描述】:

official documentation indicates 我应该能够使用rake doc:app 为我的应用程序构建文档,但是当我在 Rails 5 中运行该命令时,我得到以下输出:

bwerth@bwerth-VirtualBox:~/rails/gep$ rake doc:app
rake aborted!
Don't know how to build task 'doc:app' (see --tasks)

(See full trace by running task with --trace)

【问题讨论】:

    标签: ruby-on-rails ruby rake rdoc ruby-on-rails-5


    【解决方案1】:

    此功能在版本 5 中为 removed from Rails,理由如下:

    ...根据我们的经验,应用程序不会使用 doc:app 生成 API...如果团队绝对需要生成应用程序文档 出于内部目的,他们仍然可以轻松编写自己的任务...

    可以通过在 /lib/tasks/documentation.rake 创建一个文件来轻松恢复该功能,该文件包含以下内容,取自last version of the official task

    # /lib/tasks/documentation.rake
    require 'rdoc/task'
    
    namespace :doc do
      RDoc::Task.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'
        rdoc.options << '--charset' << 'utf-8'
        rdoc.rdoc_files.include('README.md')
        rdoc.rdoc_files.include('app/**/*.rb')
        rdoc.rdoc_files.include('lib/**/*.rb')
      }
      Rake::Task['doc:app'].comment = "Generate docs for the app -- also available doc:rails, doc:guides (options: TEMPLATE=/rdoc-template.rb, TITLE=\"Custom Title\")"
    end
    

    虽然,在这一点上,从命令行运行这样的东西似乎更容易:

    rdoc --main README.md --title 'My Fancy Title' README.md app/**/*.rb lib/**/*.rb 
    

    【讨论】:

    • 如果您有旧版应用程序,您可能希望将 README.md 更改为 README.rdoc:rdoc.rdoc_files.include('README.md')
    • 如果其他人和我有同样的问题,即如何实际查看生成的文档,答案是您可以打开doc/app/index.html
    猜你喜欢
    • 1970-01-01
    • 2012-06-03
    • 1970-01-01
    • 1970-01-01
    • 2015-10-29
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 2016-01-20
    相关资源
    最近更新 更多