Change a RDoc template for generating Rails app documentation

南笙酒味 提交于 2019-12-13 18:21:34

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/15760530/change-a-rdoc-template-for-generating-rails-app-documentation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!