| 1 |
require 'rubygems' |
| 2 |
require 'redcloth' |
| 3 |
require 'erb' |
| 4 |
require 'uri/common' |
| 5 |
|
| 6 |
|
| 7 |
class Node |
| 8 |
attr_reader :anchor |
| 9 |
attr_reader :children |
| 10 |
|
| 11 |
def initialize(title, anchor, parent) |
| 12 |
@title = title |
| 13 |
@anchor = (parent.anchor ? "#{parent.anchor}-#{anchor}" : anchor) |
| 14 |
|
| 15 |
@children = [] |
| 16 |
parent.children << self |
| 17 |
end |
| 18 |
|
| 19 |
def outline(level) |
| 20 |
children = "" |
| 21 |
if level == 1 |
| 22 |
children = "<ul>#{@children.map{|child| child.outline(level + 1)}.join}</ul>" |
| 23 |
end |
| 24 |
|
| 25 |
["<li><a href=\"##{anchor}\">#{@title}</a>#{children}</li>"] |
| 26 |
end |
| 27 |
|
| 28 |
Root = Struct.new(:anchor, :children).new(nil, []) |
| 29 |
def Root.outline |
| 30 |
"<ul>#{self.children.map{|child| child.outline(1)}.join}</ul>" |
| 31 |
end |
| 32 |
end |
| 33 |
|
| 34 |
def pop_open_div(name) |
| 35 |
return %{<div><a class="HideShow" href="javascript:;" onmousedown="toggleDiv('Pop Open #{name}');">Hide/Show #{name}</a><div class="PopOpen" id="Pop Open #{name}" style="display:none">} |
| 36 |
end |
| 37 |
|
| 38 |
def pop_open_example(name) |
| 39 |
divid = "Pop Open #{name} Example" |
| 40 |
return %{<div><a class="HideShow" href="javascript:;" onmousedown="toggleExample('#{divid}', 'examples/#{URI.escape(name)}.html');">Hide/Show #{name} Example</a><div id="#{divid}" style="display:none"></div></div>} |
| 41 |
end |
| 42 |
|
| 43 |
$node_path = [Node::Root] |
| 44 |
|
| 45 |
def h(level, title, anchor) |
| 46 |
$node_path = $node_path[0, level] |
| 47 |
parent = $node_path.last |
| 48 |
|
| 49 |
node = Node.new(title, anchor, parent) |
| 50 |
$node_path << node |
| 51 |
|
| 52 |
"<h#{level}><a name=\"#{node.anchor}\"></a><a href=\"##{node.anchor}\">#{title}</a></h#{level}>" |
| 53 |
end |
| 54 |
|
| 55 |
|
| 56 |
textile = ERB.new(File.read('chipmunk-docs.textile')).result(binding) |
| 57 |
textile2 = ERB.new(textile).result(binding) |
| 58 |
redcloth_out = RedCloth.new(textile2).to_html |
| 59 |
|
| 60 |
html = <<HTML |
| 61 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 62 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 63 |
<head> |
| 64 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 65 |
<title>Chipmunk Game Dynamics Manual</title> |
| 66 |
<link rel="stylesheet" type="text/css" href="stylesheet.css" /> |
| 67 |
</head> |
| 68 |
<body> |
| 69 |
<script language="javascript"> |
| 70 |
function toggleDiv(divid){ |
| 71 |
if(document.getElementById(divid).style.display == 'none'){ |
| 72 |
document.getElementById(divid).style.display = 'block'; |
| 73 |
}else{ |
| 74 |
document.getElementById(divid).style.display = 'none'; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
function toggleExample(divid, name){ |
| 79 |
toggleDiv(divid); |
| 80 |
var div = document.getElementById(divid); |
| 81 |
var i = div.innerHTML; |
| 82 |
|
| 83 |
if(div.innerHTML == ""){ |
| 84 |
div.innerHTML = "Loading ..." |
| 85 |
|
| 86 |
var xmlhttp = new XMLHttpRequest(); |
| 87 |
xmlhttp.onreadystatechange = function(){ |
| 88 |
if(xmlhttp.readyState == 4){ |
| 89 |
div.innerHTML = xmlhttp.responseText; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
xmlhttp.open("GET", name, true); |
| 94 |
xmlhttp.send(); |
| 95 |
} |
| 96 |
} |
| 97 |
</script> |
| 98 |
|
| 99 |
#{redcloth_out} |
| 100 |
</body> |
| 101 |
</html> |
| 102 |
HTML |
| 103 |
|
| 104 |
File.open('../doc/index.html', 'w') do|f| |
| 105 |
f.write html |
| 106 |
end |