rails解析rubyamf配置文件修改生成rdoc

rails有内置rdoc文档,但是当用到你自己配置的文件来解析生成到文档里就可不好弄了!也许对于高手来说很容易,但这是针对新手的文章。
要生成文档首先要修改生成文档的样式,更改路径在
Ruby\lib\ruby\1.8\rdoc\generators\template\html里的html文件,在此文件最下面有生成文档的格式。
此时你要在工程的lib\tasks下写个rake任务,或者ruby文件都行

desc "创建共享文档"
task :create_doc do
  val = []
  key = []
  hsh = {}
  html = {}

  content = File.read("config/rubyamf_config.rb")
  content.gsub(/#.*$/,"").scan(/ClassMappings\.register\(\s+(.*?)\)/m) do |item|
    val << item
  end

  val.each do |k|
    k.to_s.scan(/actionscript.*'[A-Z][a-z]*'/) do |ke|
      ke.to_s.scan(/'[A-Z][a-z]*'/) do |keey|
        #puts keey
        hsh["#{keey.to_s[1..-2]}"] = k.to_s.scan(/.*[\,|\]]/)
      end
    end
  end

  content.gsub(/#.*$/,"").scan(/'[A-Z][a-z]*'/m) do |ke|
    key << ke
  end

  key.uniq!.sort!.map! { |i| "<a href='classes/#{i[1..-2]}.html' target='docwin'>"+ i[1..-2] + "</a><br/>" }


  HTML_LEFT = %{
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="rdoc-style.css" type="text/css" />
<title>ClassMappings.register</title>
</head>
<body>
<div id="index">
  <h1 class="section-bar">Classes</h1>
  <div id="index-entries">
#{key.each{ |i| i}}
  </div>
</div>
</body>
</html>
  }

  hsh.each do |ke,va|
    html["#{ke}"] = %{
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>#{ke}</title>
</head>
<body>
参数:
#{va.map!{|p| "<p>"+ p.delete(",") +"</p>"}}
</body>
</html>
    }
  end

  writefile = File.new("doc/app/left.html" , "w")
  writefile.write(HTML_LEFT)
  html.each do |ke,va|
    writefile = File.new("doc/app/classes/#{ke}.html" , "w")
    writefile.write(va)
  end
end

 当然,你有更好的html页面设计

此rake会覆盖你生成文档的classes文件里面的类的html。之后的效果就是

现在就可以rake doc:app

之后再 rake create_doc

效果见下面。点击类名就会到对应的配置项!配置文件的解析就要你自己来了!
rails解析rubyamf配置文件修改生成rdoc_第1张图片
 
rails解析rubyamf配置文件修改生成rdoc_第2张图片

 

你可能感兴趣的:(html,css,XHTML,Ruby,Rails)