diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-10-09 09:49:53 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-10-09 09:49:53 +0000 |
commit | 8c0b661d074a7f9a9c42f143304c4807084f3cea (patch) | |
tree | 40ccdbadd4949eec7842f9e85e489b3a079136ba | |
parent | a1c80948c270881cbcf41f6012f67c0751c2245f (diff) | |
download | rockbox-8c0b661d074a7f9a9c42f143304c4807084f3cea.tar.gz rockbox-8c0b661d074a7f9a9c42f143304c4807084f3cea.zip |
Fix some issues with generation of plugin API documentation + make it more themeable
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18750 a1c6a512-1295-4272-9138-f99709370657
-rwxr-xr-x | utils/rockbox_api/gen_html.php | 153 | ||||
-rw-r--r-- | utils/rockbox_api/index.tpl | 23 | ||||
-rw-r--r-- | utils/rockbox_api/menu.tpl | 8 | ||||
-rw-r--r-- | utils/rockbox_api/section.tpl | 50 |
4 files changed, 185 insertions, 49 deletions
diff --git a/utils/rockbox_api/gen_html.php b/utils/rockbox_api/gen_html.php index 34e124f411..b3cec02036 100755 --- a/utils/rockbox_api/gen_html.php +++ b/utils/rockbox_api/gen_html.php | |||
@@ -9,102 +9,157 @@ function get_group($text) | |||
9 | 9 | ||
10 | $input = file_get_contents($argv[1]); | 10 | $input = file_get_contents($argv[1]); |
11 | 11 | ||
12 | $mypath = $_SERVER['SCRIPT_FILENAME']; | ||
13 | $mypath = substr($mypath, 0, strrpos($mypath, "/"))."/"; | ||
14 | |||
12 | $inh = parse_documentation($input); | 15 | $inh = parse_documentation($input); |
13 | 16 | ||
14 | @mkdir("output"); | 17 | @mkdir("output"); |
15 | 18 | ||
16 | $h = fopen("output/index.html", "w"); | 19 | $index_tpl = file_get_contents($mypath."index.tpl"); |
17 | 20 | ||
18 | fwrite($h, '<html><head><link href="layout.css" rel="stylesheet" type="text/css" /><title>Plugin API - INDEX</title></head><body>'); | 21 | $group_data = array(); |
22 | $group_tpl = array(); | ||
23 | ereg("%GROUP_START%.*%GROUP_END%", $index_tpl, $group_tpl); | ||
24 | $group_tpl = str_replace(array("%GROUP_START%", "%GROUP_END%"), "", $group_tpl[0]); | ||
19 | 25 | ||
20 | fwrite($h, "<h1>Plugin API reference</h1>"); | 26 | $func_tpl = array(); |
21 | fwrite($h, "<ul>"); | 27 | ereg("%FUNCTION_START%.*%FUNCTION_END%", $group_tpl, $func_tpl); |
28 | $func_tpl = str_replace(array("%FUNCTION_START%", "%FUNCTION_END%"), "", $func_tpl[0]); | ||
22 | 29 | ||
23 | foreach($inh as $group_name => $group) | 30 | foreach($inh as $group_name => $group) |
24 | { | 31 | { |
25 | if(strlen($group_name) > 0) | 32 | if(strlen($group_name) > 0) |
26 | { | 33 | { |
27 | fwrite($h, '<li>'.ucwords($group_name)."<ul>"); | 34 | $func_data = array(); |
28 | |||
29 | foreach($group as $el_name => $el) | 35 | foreach($group as $el_name => $el) |
30 | fwrite($h, "<li><a href=\"".get_group($group_name).".html#".get_func($el_name)."\">".$el_name."</a></li>"); | 36 | $func_data[] = str_replace(array("%GROUP%", "%FUNCTION%", "%FUNCTION_NAME%"), |
37 | array(get_group($group_name), get_func($el_name), $el_name), | ||
38 | $func_tpl); | ||
31 | 39 | ||
32 | fwrite($h, "</ul></li>"); | 40 | $tmp = str_replace("%GROUP_NAME%", ucwords($group_name), $group_tpl); |
41 | $group_data[] = ereg_replace("%FUNCTION_START%.*%FUNCTION_END%", implode("\n", $func_data), $tmp); | ||
33 | } | 42 | } |
34 | } | 43 | } |
35 | fwrite($h, "</ul></body></html>"); | ||
36 | 44 | ||
37 | fclose($h); | 45 | $index_tpl = ereg_replace("%GROUP_START%.*%GROUP_END%", implode("", $group_data), $index_tpl); |
46 | file_put_contents("output/index.html", $index_tpl); | ||
47 | |||
48 | $menu_tpl = file_get_contents($mypath."menu.tpl"); | ||
38 | 49 | ||
39 | $menu = '<ul><li><a href="index.html">INDEX</a></li><ul>'; | 50 | $group_tpl = array(); |
40 | $_menu = array(); | 51 | ereg("%GROUP_START%.*%GROUP_END%", $menu_tpl, $group_tpl); |
52 | $group_tpl = str_replace(array("%GROUP_START%", "%GROUP_END%"), "", $group_tpl[0]); | ||
53 | |||
54 | $menu = array(); | ||
41 | foreach($inh as $group_name => $group) | 55 | foreach($inh as $group_name => $group) |
42 | { | 56 | { |
43 | if(strlen($group_name) > 0) | 57 | if(strlen($group_name) > 0) |
44 | $_menu[strtolower($group_name)] = '<li><a href="'.get_group($group_name).'.html">'.ucwords($group_name).'</a></li>'; | 58 | $menu[strtolower($group_name)] = str_replace(array("%GROUP%", "%GROUP_NAME%"), |
59 | array(get_group($group_name), ucwords($group_name)), | ||
60 | $group_tpl); | ||
45 | } | 61 | } |
62 | ksort($menu); | ||
46 | 63 | ||
47 | ksort($_menu); | 64 | $menu = ereg_replace("%GROUP_START%.*%GROUP_END%", implode("", $menu), $menu_tpl); |
48 | $menu .= implode("\n", $_menu); | ||
49 | $menu .= "</ul></ul>"; | ||
50 | 65 | ||
51 | foreach($inh as $group_name => $group) | 66 | $section_tpl = file_get_contents($mypath."section.tpl"); |
52 | { | 67 | |
53 | $h = fopen("output/".get_group($group_name).".html", "w"); | 68 | $func_tpl = array(); |
69 | ereg("%FUNCTION_START%.*%FUNCTION_END%", $section_tpl, $func_tpl); | ||
70 | $func_tpl = str_replace(array("%FUNCTION_START%", "%FUNCTION_END%"), "", $func_tpl[0]); | ||
71 | |||
72 | $description_tpl = array(); | ||
73 | ereg("%DESCRIPTION_START%.*%DESCRIPTION_END%", $func_tpl, $description_tpl); | ||
74 | $description_tpl = str_replace(array("%DESCRIPTION_START%", "%DESCRIPTION_END%"), "", $description_tpl[0]); | ||
75 | |||
76 | $parameter_tpl = array(); | ||
77 | ereg("%PARAMETER_START%.*%PARAMETER_END%", $func_tpl, $parameter_tpl); | ||
78 | $parameter_tpl = str_replace(array("%PARAMETER_START%", "%PARAMETER_END%"), "", $parameter_tpl[0]); | ||
79 | |||
80 | $parameters_tpl = array(); | ||
81 | ereg("%PARAMETERS_START%.*%PARAMETERS_END%", $parameter_tpl, $parameters_tpl); | ||
82 | $parameters_tpl = str_replace(array("%PARAMETERS_START%", "%PARAMETERS_END%"), "", $parameters_tpl[0]); | ||
83 | |||
84 | $return_tpl = array(); | ||
85 | ereg("%RETURN_START%.*%RETURN_END%", $func_tpl, $return_tpl); | ||
86 | $return_tpl = str_replace(array("%RETURN_START%", "%RETURN_END%"), "", $return_tpl[0]); | ||
87 | |||
88 | $conditions_tpl = array(); | ||
89 | ereg("%CONDITIONS_START%.*%CONDITIONS_END%", $func_tpl, $conditions_tpl); | ||
90 | $conditions_tpl = str_replace(array("%CONDITIONS_START%", "%CONDITIONS_END%"), "", $conditions_tpl[0]); | ||
54 | 91 | ||
55 | fwrite($h, '<html><head><link href="layout.css" rel="stylesheet" type="text/css" /><title>Plugin API - '.ucwords($group_name).'</title></head><body>'); | 92 | $see_tpl = array(); |
56 | fwrite($h, '<div id="menu">'.ucwords($menu).'</div>'); | 93 | ereg("%SEE_START%.*%SEE_END%", $func_tpl, $see_tpl); |
57 | fwrite($h, '<div id="content">'); | 94 | $see_tpl = str_replace(array("%SEE_START%", "%SEE_END%"), "", $see_tpl[0]); |
58 | fwrite($h, '<a link="top"></a>'); | ||
59 | 95 | ||
60 | fwrite($h, "<h2>".ucwords($group_name)."</h2>"); | 96 | foreach($inh as $group_name => $group) |
61 | fwrite($h, '<span class="group">'); | 97 | { |
98 | $section_data = str_replace(array("%MENU%", "%GROUP_NAME%"), array($menu, ucwords($group_name)), $section_tpl); | ||
99 | |||
100 | $funcs_data = array(); | ||
62 | foreach($group as $func_name => $func) | 101 | foreach($group as $func_name => $func) |
63 | { | 102 | { |
64 | fwrite($h, '<a id="'.get_func($func_name).'"></a>'); | 103 | $func_data = str_replace(array("%FUNCTION_NAME%", "%FUNCTION%"), array(get_func($func_name), $func_name), $func_tpl); |
65 | |||
66 | fwrite($h, "<h3>$func_name</h3>"); | ||
67 | 104 | ||
68 | if(strlen($func["description"][0]) > 0) | 105 | if(strlen($func["description"][0]) > 0) |
69 | fwrite($h, do_markup($func["description"][0])."<br /><br />"); | 106 | $func_data = ereg_replace("%DESCRIPTION_START%.*%DESCRIPTION_END%", |
70 | 107 | str_replace("%FUNCTION_DESCRIPTION%", do_markup($func["description"][0]), $description_tpl), | |
108 | $func_data); | ||
109 | else | ||
110 | $func_data = ereg_replace("%DESCRIPTION_START%.*%DESCRIPTION_END%", "", $func_data); | ||
111 | |||
71 | if(isset($func["param"])) | 112 | if(isset($func["param"])) |
72 | { | 113 | { |
73 | $params = ""; | 114 | $params_data = array(); |
74 | foreach($func["param"] as $param) | 115 | foreach($func["param"] as $param) |
75 | { | 116 | { |
76 | $param = trim($param); | 117 | $param = trim($param); |
77 | $p1 = substr($param, 0, strpos($param, " ")); | 118 | $p1 = substr($param, 0, strpos($param, " ")); |
78 | $p2 = substr($param, strpos($param, " ")); | 119 | $p2 = do_markup(substr($param, strpos($param, " "))); |
120 | |||
79 | if(strlen($p1) > 0 && strlen($p2) > 0) | 121 | if(strlen($p1) > 0 && strlen($p2) > 0) |
80 | $params .= '<dt>'.$p1.'</dt><dd> '.do_markup($p2).'</dd>'; | 122 | $params_data[] = str_replace(array("%PARAM1%", "%PARAM2%"), array($p1, $p2), $parameters_tpl); |
81 | } | 123 | } |
82 | 124 | ||
83 | if(strlen($params) > 0) | 125 | |
84 | { | 126 | if(count($params_data) > 0) |
85 | fwrite($h, '<span class="extra">Parameters:</span><dl>'); | 127 | $func_data = ereg_replace("%PARAMETER_START%.*%PARAMETER_END%", |
86 | fwrite($h, $params); | 128 | ereg_replace("%PARAMETERS_START%.*%PARAMETERS_END%", implode("\n", $params_data), $parameter_tpl), |
87 | fwrite($h, "</dl>"); | 129 | $func_data); |
88 | } | 130 | else |
131 | $func_data = ereg_replace("%PARAMETER_START%.*%PARAMETER_END%", "", $func_data); | ||
89 | } | 132 | } |
133 | else | ||
134 | $func_data = ereg_replace("%PARAMETER_START%.*%PARAMETER_END%", "", $func_data); | ||
90 | 135 | ||
91 | if(isset($func["return"]) && strlen($func["return"][0]) > 0) | 136 | if(isset($func["return"]) && strlen($func["return"][0]) > 0) |
92 | fwrite($h, '<span class="extra">Returns:</span> '.do_markup($func["return"][0]).'<br /><br />'); | 137 | $func_data = ereg_replace("%RETURN_START%.*%RETURN_END%", |
138 | str_replace("%RETURN%", do_markup($func["return"][0]), $return_tpl), | ||
139 | $func_data); | ||
140 | else | ||
141 | $func_data = ereg_replace("%RETURN_START%.*%RETURN_END%", "", $func_data); | ||
93 | 142 | ||
94 | if(isset($func["conditions"])) | 143 | if(isset($func["conditions"])) |
95 | fwrite($h, '<span class="extra">Conditions:</span> '.$func["conditions"][0].'<br /><br />'); | 144 | $func_data = ereg_replace("%CONDITIONS_START%.*%CONDITIONS_END%", |
145 | str_replace("%CONDITIONS%", $func["conditions"][0], $conditions_tpl), | ||
146 | $func_data); | ||
147 | else | ||
148 | $func_data = ereg_replace("%CONDITIONS_START%.*%CONDITIONS_END%", "", $func_data); | ||
96 | 149 | ||
97 | if(isset($func["see"])) | 150 | if(isset($func["see"])) |
98 | fwrite($h, '<span class="see">Also see '.do_see_markup(explode(" ", trim($func["see"][0]))).'</span><br /><br />'); | 151 | $func_data = ereg_replace("%SEE_START%.*%SEE_END%", |
99 | 152 | str_replace("%SEE%", do_see_markup(explode(" ", trim($func["see"][0]))), $see_tpl), | |
100 | fwrite($h, '<a href="#top" class="top">To top</a><hr />'); | 153 | $func_data); |
154 | else | ||
155 | $func_data = ereg_replace("%SEE_START%.*%SEE_END%", "", $func_data); | ||
156 | |||
157 | $funcs_data[] = $func_data; | ||
101 | } | 158 | } |
102 | fwrite($h, "</span>"); | 159 | $section_data = ereg_replace("%FUNCTION_START%.*%FUNCTION_END%", implode("", $funcs_data), $section_data); |
103 | |||
104 | fwrite($h, "</div></body></html>"); | ||
105 | 160 | ||
106 | fclose($h); | 161 | file_put_contents("output/".get_group($group_name).".html", $section_data); |
107 | } | 162 | } |
108 | 163 | ||
109 | copy("layout.css", "output/layout.css"); | 164 | copy($mypath."layout.css", "output/layout.css"); |
110 | ?> \ No newline at end of file | 165 | ?> \ No newline at end of file |
diff --git a/utils/rockbox_api/index.tpl b/utils/rockbox_api/index.tpl new file mode 100644 index 0000000000..ccbd5965ad --- /dev/null +++ b/utils/rockbox_api/index.tpl | |||
@@ -0,0 +1,23 @@ | |||
1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ||
2 | <html> | ||
3 | <head> | ||
4 | <link href="layout.css" rel="stylesheet" type="text/css" /> | ||
5 | <title>Plugin API - INDEX</title> | ||
6 | </head> | ||
7 | |||
8 | <body> | ||
9 | <h1>Plugin API reference</h1> | ||
10 | <ul> | ||
11 | %GROUP_START% | ||
12 | <li>%GROUP_NAME% | ||
13 | <ul> | ||
14 | %FUNCTION_START% | ||
15 | <li><a href="%GROUP%.html#%FUNCTION%">%FUNCTION_NAME%</a></li> | ||
16 | %FUNCTION_END% | ||
17 | </ul> | ||
18 | </li> | ||
19 | %GROUP_END% | ||
20 | </ul> | ||
21 | |||
22 | </body> | ||
23 | </html> \ No newline at end of file | ||
diff --git a/utils/rockbox_api/menu.tpl b/utils/rockbox_api/menu.tpl new file mode 100644 index 0000000000..4eae437f5c --- /dev/null +++ b/utils/rockbox_api/menu.tpl | |||
@@ -0,0 +1,8 @@ | |||
1 | <ul> | ||
2 | <li><a href="index.html">INDEX</a></li> | ||
3 | <ul> | ||
4 | %GROUP_START% | ||
5 | <li><a href="%GROUP%.html">%GROUP_NAME%</a></li> | ||
6 | %GROUP_END% | ||
7 | </ul> | ||
8 | </ul> \ No newline at end of file | ||
diff --git a/utils/rockbox_api/section.tpl b/utils/rockbox_api/section.tpl new file mode 100644 index 0000000000..874703cb9c --- /dev/null +++ b/utils/rockbox_api/section.tpl | |||
@@ -0,0 +1,50 @@ | |||
1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | ||
2 | <html> | ||
3 | <head> | ||
4 | <link href="layout.css" rel="stylesheet" type="text/css" /> | ||
5 | <title>Plugin API - %GROUP_NAME%</title> | ||
6 | </head> | ||
7 | |||
8 | <body> | ||
9 | <div id="menu">%MENU%</div> | ||
10 | <div id="content"> | ||
11 | <a link="top"></a> | ||
12 | <h2>%GROUP_NAME%</h2> | ||
13 | <span class="group"> | ||
14 | %FUNCTION_START% | ||
15 | <a id="%FUNCTION_NAME%"></a> | ||
16 | <h3>%FUNCTION%</h3> | ||
17 | |||
18 | %DESCRIPTION_START% | ||
19 | %FUNCTION_DESCRIPTION% | ||
20 | <br /><br /> | ||
21 | %DESCRIPTION_END% | ||
22 | |||
23 | %PARAMETER_START% | ||
24 | <span class="extra">Parameters:</span> | ||
25 | <dl> | ||
26 | %PARAMETERS_START% | ||
27 | <dt>%PARAM1%</dt><dd>%PARAM2%</dd> | ||
28 | %PARAMETERS_END% | ||
29 | </dl> | ||
30 | %PARAMETER_END% | ||
31 | |||
32 | %RETURN_START% | ||
33 | <span class="extra">Returns:</span> %RETURN%<br /><br /> | ||
34 | %RETURN_END% | ||
35 | |||
36 | %CONDITIONS_START% | ||
37 | <span class="extra">Conditions:</span> %CONDITIONS%<br /><br /> | ||
38 | %CONDITIONS_END% | ||
39 | |||
40 | %SEE_START% | ||
41 | <span class="see">Also see %SEE%</span><br /><br /> | ||
42 | %SEE_END% | ||
43 | |||
44 | <a href="#top" class="top">To top</a><hr /> | ||
45 | |||
46 | %FUNCTION_END% | ||
47 | </span> | ||
48 | </div> | ||
49 | </body> | ||
50 | </html> \ No newline at end of file | ||