0

Documentation generated for a Rails application by rake doc:app gets a default title of "Rails Application Documentation". The Rake sets this:

rdoc.title    = ENV['title'] || "Rails Application Documentation"

I can change this by doing

$ title='some other title' rake doc:app

However, I would like to set this in, say, application.rb or environment'rb but this doesn't appear to work.

Where should I set the title for RDoc in a Rails application ?

starfry
  • 9,273
  • 7
  • 66
  • 96

2 Answers2

0

You can create a Rakefile like this:

RDoc::Task.new :rdoc do |rdoc|
  rdoc.main = "README.rdoc"

  #change this to fit your needs
  rdoc.rdoc_files.include("README.rdoc", "doc/*.rdoc", "app/**/*.rb", "lib/*.rb", "config/**/*.rb")

  #set your title
  rdoc.title = "App Documentation"
  rdoc.options << "--all" 
end

And, then just:

rake rdoc

See the RDoc::Task documentation for details.

K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110
  • Isn't there a way to just set it without having to create a new rake task? That's hardly _DRY_ - if that's the only way then I am very surprised... – starfry Sep 04 '15 at 11:23
  • Not that I know! btw, when you say, `this doesn't appear to work.`, how did you set title in application and environment files? Try adding a @title instance variable in your application.rb file if you already did not do that. – K M Rakibul Islam Sep 04 '15 at 11:35
  • `ENV['title'] = 'my title'` in `environment.rb`. Also tried `@title = 'my title'` in `application.rb` but that didn't work either. I guess it'll have to be a custom rake task. – starfry Sep 04 '15 at 14:08
  • Yeah. Seems like you need a rake task as i showed in my answer – K M Rakibul Islam Sep 04 '15 at 14:35
0

Following the answer by K M Rakibul Islam, a custom Rake task is one way to set a different title. I provided one in a new lib/tasks/documentation.rake file:

require 'rails/tasks'
namespace :doc do
  RDocTaskWithoutDescriptions.new("mydoc") { |rdoc|
   rdoc.rdoc_dir = 'doc/app'                                                                                                   
    rdoc.template = ENV['template'] if ENV['template']
    rdoc.title    = "My Application Documentation"
    rdoc.options << '--line-numbers'
    rdoc.options << '--charset' << 'utf-8'
    rdoc.rdoc_files.include('README.rdoc')
    rdoc.rdoc_files.include('app/**/*.rb')
    rdoc.rdoc_files.include('lib/**/*.rb')
  }   
end

This task is identical to the built-in one except for the line that sets the title. I found that the other answer generated to a html directory instead of doc/app and ran a lot of other things too. This task is executed by

$ rake doc:mydoc

This is based on the original Rails code which I note was removed on Feb 6th 2015. That means an update to the latest Rails will break this.

starfry
  • 9,273
  • 7
  • 66
  • 96