2

I have just added some documentation to my Rails 3.2.13 app. I can generate the documentation just fine (running RDoc 3.12.2) by using a rake task:

# lib/tasks/documentation.rake
Rake::Task["doc:app"].clear
Rake::Task["doc/app"].clear
Rake::Task["doc/app/index.html"].clear

namespace :doc do
    RDoc::Task.new('app') do |rdoc|
        rdoc.rdoc_dir  = 'doc/app'
        rdoc.generator = 'hanna'
        rdoc.title     = 'Stoffi Web App Documentation'
        rdoc.main      = 'doc/Overview'
        rdoc.options << '--charset' << 'utf-8'
        rdoc.rdoc_files.include('app/**/*.rb')
        rdoc.rdoc_files.include('doc/*')
    end
end

...and then running rake doc:app. But I really don't like the default look of the Hanna template. Is there a way to edit the CSS, perhaps by providing my own CSS file which will override the default one used in Hanna?

Thanks!

Christoffer Reijer
  • 1,925
  • 2
  • 21
  • 40
  • Did you add the `hanna` gem to your `Gemfile`? and run `bundle`? Also, do check this: https://github.com/rdoc/hanna-nouveau#rake-task `rdoc.generator = 'hanna'` part. – Kashyap Apr 02 '13 at 09:38
  • All of a sudden it worked by using rdoc.generator. Maybe I hadn't properly installed the gem or something. I'll change the question to only regard the modification. – Christoffer Reijer Apr 02 '13 at 09:39

1 Answers1

3

First of all find where your templates are located:

⮀ RDPATH=$(dirname $(gem which rdoc))
# ⇒ /home/am/.rvm/rubies/ruby-head/lib/ruby/2.1.0

Now copy the default template from there to the desired location (change /tmp to your project directory or like):

⮀ cp -r $RDPATH/rdoc/generator/template/darkfish /tmp/myniftytemplate

And, finally, let’s teach the rdoc:

class RDoc::Options
  def template_dir_for template
    "/tmp/#{template}"
  end
end

RDoc::Task.new('app') do |rdoc|
  rdoc.template = 'myniftytemplate'
  …
end

That’s it. Hope it helps.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • Thanks. It was very helpful if I wanted to modify Darkfish. But I'm trying to modify the Hanna template and I can't figure out how to do it. I copied the files in template_files inside the hanna-nouveau gem into my own folder mytemplate, modify the background, tell RDoc about the path and then set rdoc.template = "mytemplate". But it doesn't work. Still get the default template in Hanna. No errors from RDoc though. – Christoffer Reijer Apr 03 '13 at 07:08
  • 1
    Oooups, sorry I misunderstood that the template engine is `hanna`. According to the [sources](https://github.com/mislav/hanna/blob/master/lib/hanna/hanna.rb) (lines 15, 35,) `hanna`’s template files are at the moment hard-coded. I know it sounds ugly, but I see no way to override the template except of patching either templates in-place or `hanna.rb` to load `sass` from custom location. – Aleksei Matiushkin Apr 03 '13 at 08:06