Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a rakefile to generate docs from source

Tags:

ruby

rake

yard

I downloaded the ruby Twitter gem source code and am trying to generate the documentation using yard, which I installed via gem install yard. In the rakefile, I found the following, which I assume is used to generate the docs for the Twitter gem:

require 'yard'
YARD::Rake::YardocTask.new

I tried to require yard in irb and then run YARD::Rake::YardocTask.new but nothing happened.

Can you help me get on the right track?

like image 943
BrainLikeADullPencil Avatar asked Oct 23 '12 02:10

BrainLikeADullPencil


People also ask

What is the use of Rakefile?

Through require 'rake/clean' Rake provides clean and clobber tasks: clean. Clean up the project by deleting scratch files and backup files. Add files to the CLEAN FileList to have the clean target handle them.

What is the purpose of the Rakefile available in the demo directory in Ruby?

What is the purpose of the rakefile available in the demo directory in Ruby? The purpose of this simple question is to make sure a developer is familiar with test-driven development.

How does Rake task work?

Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.

How do I create a Rake file?

Simply create a new file and name it as task. rake. Normally we put the rake task in directory lib/tasks. But you can put it anywhere you like.


1 Answers

From the YARD docs:

The second most obvious is to generate docs via a Rake task. You can do this by adding the following to your Rakefile:

YARD::Rake::YardocTask.new do |t|
  t.files   = ['lib/**/*.rb', OTHER_PATHS]   # optional
  t.options = ['--any', '--extra', '--opts'] # optional
end

both the files and options settings are optional. files will default to lib/**/*.rb and options will represents any options you might want to add. Again, a full list of options is available by typing yardoc --help in a shell. You can also override the options at the Rake command-line with the OPTS environment variable:

$ rake yard OPTS='--any --extra --opts'

To summarize: after adding YARD::Rake::YardocTask.new to your Rakefile, run rake yard.

like image 73
Andrew Marshall Avatar answered Sep 28 '22 08:09

Andrew Marshall