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

9

13

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/?

Ostensible answered 29/7, 2009 at 18:12 Comment(0)
O
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/

Ostensible answered 4/8, 2009 at 17:52 Comment(1)
The question asked about generating - this answer is for retrieving.Layette
A
16
sudo gem rdoc --all --overwrite
Arytenoid answered 25/3, 2011 at 17:57 Comment(0)
O
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/

Ostensible answered 4/8, 2009 at 17:52 Comment(1)
The question asked about generating - this answer is for retrieving.Layette
B
9

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

gem server
Brandenbrandenburg answered 29/7, 2009 at 21:57 Comment(0)
D
5

Below is my attempt to clarify the steps a bit on how to get the rails 3.1 docs downloaded locally to your machine as the equivalent of http://api.rubyonrails.org/

  1. Go to the sdoc project at https://github.com/voloko/sdoc and get the project (or just do gem install sdoc)
  2. Visit the rails project at https://github.com/rails/rails and git clone it to your local machine
  3. Go into the rails clone and run sdoc -N rails
  4. This will take a while. When it is done you will have a new directory called doc
  5. You can move the doc directory anywhere you like and open the index.html file in a browser. Note that you do not need a web server for this to work.

As a side note it looks like sdoc has officially become the docs for the Ruby on Rails API (see http://weblog.rubyonrails.org/2011/8/29/the-rails-api-switches-to-sdoc)

Diapason answered 18/9, 2011 at 17:26 Comment(0)
B
3

You can freeze Rails in an app and run rake doc:rails to get the docs.

rails doc_project
cd doc_project
rake rails:freeze
rake doc:rails

The RDocs should be located in doc/api directory. You can use rake rails:freeze:edge to get documentation for Edge Rails.

Alternatively you can download the docs from a site like Rails Brain to get a searchable template with it as well.

If you are wanting the docs to show up in gem server then the easiest thing may be to re-install the rails gem with the rdoc option.

sudo gem install rails --rdoc
Baxley answered 4/8, 2009 at 14:45 Comment(1)
sudo gem install rails --rdoc did nothing for me. I still get "File not found: /Library/Ruby/Gems/1.8/doc/rails-2.3.3/rdoc/index.html." And the other solution puts the docs in the doc/api directory, not where the gem docs server can find it.Ostensible
P
2

Run the command bundle exec rdoc on command line.

It will generate all documentation of your code.

Pinkiepinkish answered 9/9, 2012 at 14:17 Comment(0)
C
0

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
Coruscation answered 29/7, 2009 at 18:27 Comment(5)
running that from /Library/Ruby/Gems/1.8/gems/rails-2.3.3/ gives me a "can't find template 'horo'" error. Specifying a template (specifically /Library/Ruby/Gems/1.8/gems/mislave-hanna-0.1.7/lib/hanna) gives me a "undefined method `add_generator' for RDoc::RDoc:Class" error.Ostensible
You must donwload the Rails Git repository if you want to use exactly that script.Coruscation
I still get "undefined method `add_generator' for RDoc::RDoc:Class" when running rake rdoc from a freshly-checked-out Rails project.Ostensible
Is there a particular version of RDoc that Rails uses? I've tried 2.3.0 and 2.4.3, both of which keep blowing up.Ostensible
I believe Rails is still defaulting to use RDoc 1. You can't just run: rake doc:rails ?Stewart
C
0

If you need to generate edge docs, you can perform something like this

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
Cordoba answered 4/8, 2009 at 11:54 Comment(0)
A
0
$ 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
Amendatory answered 6/2, 2010 at 18:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.