How do I generate RDOC for (all of) Rails?

2019-01-21 12:00发布

I can do

sudo gem rdoc activerecord --no-ri

and

sudo gem rdoc actionpack --no-ri

both of which give me good docs.

But

sudo gem rdoc rails --no-ri

gives me pretty much nothing, as the Rails gem itself is really just a holder for the others. How can I generate the equivalent of http://api.rubyonrails.org/?

9条回答
冷血范
2楼-- · 2019-01-21 12:07

If you installed rails with the rdoc (sudo gem install rails) You can access it via

gem server
查看更多
戒情不戒烟
3楼-- · 2019-01-21 12:11

From the Rails project Rakefile

desc "Generate documentation for the Rails framework"
Rake::RDocTask.new do |rdoc|
  rdoc.rdoc_dir = 'doc/rdoc'
  rdoc.title = "Ruby on Rails Documentation"

  rdoc.options << '--line-numbers' << '--inline-source'
  rdoc.options << '-A cattr_accessor=object'
  rdoc.options << '--charset' << 'utf-8'

  rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : './doc/template/horo'

  rdoc.rdoc_files.include('railties/CHANGELOG')
  rdoc.rdoc_files.include('railties/MIT-LICENSE')
  rdoc.rdoc_files.include('railties/README')
  rdoc.rdoc_files.include('railties/lib/{*.rb,commands/*.rb,rails/*.rb,rails_generator/*.rb}')

  rdoc.rdoc_files.include('activerecord/README')
  rdoc.rdoc_files.include('activerecord/CHANGELOG')
  rdoc.rdoc_files.include('activerecord/lib/active_record/**/*.rb')
  rdoc.rdoc_files.exclude('activerecord/lib/active_record/vendor/*')

  rdoc.rdoc_files.include('activeresource/README')
  rdoc.rdoc_files.include('activeresource/CHANGELOG')
  rdoc.rdoc_files.include('activeresource/lib/active_resource.rb')
  rdoc.rdoc_files.include('activeresource/lib/active_resource/*')

  rdoc.rdoc_files.include('actionpack/README')
  rdoc.rdoc_files.include('actionpack/CHANGELOG')
  rdoc.rdoc_files.include('actionpack/lib/action_controller/**/*.rb')
  rdoc.rdoc_files.include('actionpack/lib/action_view/**/*.rb')
  rdoc.rdoc_files.exclude('actionpack/lib/action_controller/vendor/*')

  rdoc.rdoc_files.include('actionmailer/README')
  rdoc.rdoc_files.include('actionmailer/CHANGELOG')
  rdoc.rdoc_files.include('actionmailer/lib/action_mailer/base.rb')
  rdoc.rdoc_files.exclude('actionmailer/lib/action_mailer/vendor/*')

  rdoc.rdoc_files.include('activesupport/README')
  rdoc.rdoc_files.include('activesupport/CHANGELOG')
  rdoc.rdoc_files.include('activesupport/lib/active_support/**/*.rb')
  rdoc.rdoc_files.exclude('activesupport/lib/active_support/vendor/*')
end

# Enhance rdoc task to copy referenced images also
task :rdoc do
  FileUtils.mkdir_p "doc/rdoc/files/examples/"
  FileUtils.copy "activerecord/examples/associations.png", "doc/rdoc/files/examples/associations.png"
end
查看更多
Ridiculous、
4楼-- · 2019-01-21 12:15
sudo gem rdoc --all --overwrite
查看更多
戒情不戒烟
5楼-- · 2019-01-21 12:15

The easiest I found was to just download them from railsapi.com and unpack the file into /Library/Ruby/Gems/1.8/doc/rails-2.3.3/rdoc/

查看更多
乱世女痞
6楼-- · 2019-01-21 12:26
$ rake rails:freeze:gems
$ rake doc:rails
$ rake rails:unfreeze
$ sudo mv doc/api/* /Library/Ruby/Gems/1.8/doc/rails-2.3.5/rdoc
$ gem server
查看更多
Explosion°爆炸
7楼-- · 2019-01-21 12:27

Run the command bundle exec rdoc on command line.

It will generate all documentation of your code.

查看更多
登录 后发表回答