我可以
sudo gem rdoc activerecord --no-ri
和
sudo gem rdoc actionpack --no-ri
两者都给了我很好的文档。
但
sudo gem rdoc rails --no-ri
几乎什么也没给我,因为 Rails gem 本身实际上只是其他人的持有人。如何生成等效的http://api.rubyonrails.org/?
我可以
sudo gem rdoc activerecord --no-ri
和
sudo gem rdoc actionpack --no-ri
两者都给了我很好的文档。
但
sudo gem rdoc rails --no-ri
几乎什么也没给我,因为 Rails gem 本身实际上只是其他人的持有人。如何生成等效的http://api.rubyonrails.org/?
sudo gem rdoc --all --overwrite
我发现最简单的方法是从railsapi.com下载它们并将文件解压缩到/Library/Ruby/Gems/1.8/doc/rails-2.3.3/rdoc/
如果您使用 rdoc (sudo gem install rails) 安装了 rails,您可以通过以下方式访问它
gem server
下面是我尝试澄清有关如何将 Rails 3.1 文档本地下载到您的机器的步骤,相当于http://api.rubyonrails.org/
附带说明一下,sdoc 似乎已正式成为 Ruby on Rails API 的文档(请参阅http://weblog.rubyonrails.org/2011/8/29/the-rails-api-switches-to-sdoc)
您可以在应用程序中冻结 Rails 并运行rake doc:rails
以获取文档。
rails doc_project
cd doc_project
rake rails:freeze
rake doc:rails
RDocs 应该位于 doc/api 目录中。您可以使用rake rails:freeze:edge
获取 Edge Rails 的文档。
或者,您也可以从Rails Brain之类的网站下载文档以获取可搜索的模板。
如果您希望显示文档,gem server
那么最简单的方法可能是使用 rdoc 选项重新安装 rails gem。
sudo gem install rails --rdoc
在命令行上运行bundle exec rdoc
命令。
它将生成您的代码的所有文档。
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
如果您需要生成边缘文档,您可以执行类似这样的操作
git clone git://github.com/rails/rails.git ~/rails
# or if you have repo, just checkout interested branch
cd ~
ruby ~/rails/railties/bin/rails docapp
cd docapp
ln -s ~/rails vendor/rails
rake doc:rerails
rake doc:guides
$ 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