File: MakeDocs.rb

package info (click to toggle)
chipmunk 7.0.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,968 kB
  • sloc: ansic: 29,265; objc: 4,313; ruby: 409; makefile: 10; sh: 1
file content (106 lines) | stat: -rw-r--r-- 2,981 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require 'rubygems'
require 'redcloth'
require 'erb'
require 'uri/common'


class Node
	attr_reader :anchor
	attr_reader :children
	
	def initialize(title, anchor, parent)
		@title = title
		@anchor = (parent.anchor ? "#{parent.anchor}-#{anchor}" : anchor)
		
		@children = []
		parent.children << self
	end
	
	def outline(level)
		children = ""
		if level == 1
			children = "<ul>#{@children.map{|child| child.outline(level + 1)}.join}</ul>"
		end
		
		["<li><a href=\"##{anchor}\">#{@title}</a>#{children}</li>"]
	end
	
	Root = Struct.new(:anchor, :children).new(nil, [])
	def Root.outline
		"<ul>#{self.children.map{|child| child.outline(1)}.join}</ul>"
	end
end

def pop_open_div(name)
	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">}
end

def pop_open_example(name)
	divid = "Pop Open #{name} Example"
	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>}
end

$node_path = [Node::Root]

def h(level, title, anchor)
	$node_path = $node_path[0, level]
	parent = $node_path.last
	
	node = Node.new(title, anchor, parent)
	$node_path << node
	
	"<h#{level}><a name=\"#{node.anchor}\"></a><a href=\"##{node.anchor}\">#{title}</a></h#{level}>"
end

# Run the ERB once to grab the outline information and insert headers.
textile = ERB.new(File.read('chipmunk-docs.textile')).result(binding)
textile2 = ERB.new(textile).result(binding)
redcloth_out = RedCloth.new(textile2).to_html

html = <<HTML
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
		<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>Chipmunk Game Dynamics Manual</title>
			<link rel="stylesheet" type="text/css" href="stylesheet.css" />
		</head>
		<body>
			<script language="javascript">
				function toggleDiv(divid){
					if(document.getElementById(divid).style.display == 'none'){
						document.getElementById(divid).style.display = 'block';
					}else{
						document.getElementById(divid).style.display = 'none';
					}
				}
				
				function toggleExample(divid, name){
					toggleDiv(divid);
					var div = document.getElementById(divid);
					var i = div.innerHTML;
					
					if(div.innerHTML == ""){
						div.innerHTML = "Loading ..."
						
						var xmlhttp = new XMLHttpRequest();
						xmlhttp.onreadystatechange = function(){
							if(xmlhttp.readyState == 4){
								div.innerHTML = xmlhttp.responseText;
							}
						}
						
						xmlhttp.open("GET", name, true);
						xmlhttp.send();
					}
				}
			</script>
			
			#{redcloth_out}
		</body>
	</html>
HTML

File.open('../doc/index.html', 'w') do|f|
	f.write html
end