Search code examples
ruby-on-railsrdoc

Where in a Rails application is the RDoc title set?


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 ?


Solution

  • 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.