5

我喜欢使用 Textile 或 Markdown 为我的项目编写自述文件,但是当我生成 RDoc 时,自述文件被解释为 RDoc 并且看起来非常糟糕。有没有办法让 RDoc 通过 RedCloth 或 BlueCloth 而不是自己的格式化程序运行文件?是否可以将其配置为自动检测文件后缀的格式?(例如 README.textile 通过 RedCloth 运行,但 README.mdown 通过 BlueCloth 运行)

4

3 回答 3

7

只要文件后缀合理,直接使用YARD而不是 RDoc 将允许您包含 Textile 或 Markdown 文件。我经常使用类似下面的 Rake 任务:

desc "Generate RDoc"
task :doc => ['doc:generate']

namespace :doc do
  project_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
  doc_destination = File.join(project_root, 'doc', 'rdoc')

  begin
    require 'yard'
    require 'yard/rake/yardoc_task'

    YARD::Rake::YardocTask.new(:generate) do |yt|
      yt.files   = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) + 
                   [ File.join(project_root, 'README.md') ]
      yt.options = ['--output-dir', doc_destination, '--readme', 'README.md']
    end
  rescue LoadError
    desc "Generate YARD Documentation"
    task :generate do
      abort "Please install the YARD gem to generate rdoc."
    end
  end

  desc "Remove generated documenation"
  task :clean do
    rm_r doc_dir if File.exists?(doc_destination)
  end

end
于 2010-01-27T13:01:10.337 回答
2

如果您在 github 上托管您的项目,您还可以使用http://rdoc.info使用 YARD 自动构建和发布您的 rdocs。

于 2010-10-05T17:06:28.217 回答
0

我意识到26819中的代码前面有“类似”,但我遇到了一些问题。我对答案的编辑被拒绝了,所以这是一个固定版本(编辑被评论):

desc "Generate RDoc"
task :doc => ['doc:generate']

namespace :doc do

  # edit: typically (for gems, at least), Rakefile is in the root, so ".", not ".."
  project_root = File.expand_path(File.join(File.dirname(__FILE__), '.'))
  doc_destination = File.join(project_root, 'doc', 'rdoc')

  begin
    require 'yard'
    require 'yard/rake/yardoc_task'

    YARD::Rake::YardocTask.new(:generate) do |yt|
      # edit: README.md is not a ruby source file - see
      # https://stackoverflow.com/questions/7907698/yard-0-7-3-fails-to-build-my-readme-in-both-markdown-and-textile
      # remove README.md from yt.files
      yt.files   = Dir.glob(File.join(project_root, 'lib', '**', '*.rb'))
      yt.options = ['--output-dir', doc_destination, '--readme', 'README.md']
    end
  rescue LoadError
    desc "Generate YARD Documentation"
    task :generate do
      abort "Please install the YARD gem to generate rdoc."
    end
  end

  desc "Remove generated documenation"
  task :clean do
    #edit: doc_dir was undefined; replaced by doc_destination
    rm_r doc_destination if File.exists?(doc_destination)
  end

end
于 2013-04-23T12:43:46.417 回答