-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathpublish-api-docs.php
130 lines (85 loc) · 2.51 KB
/
publish-api-docs.php
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
$root = dirname(dirname(__FILE__));
ini_set("include_path", "{$root}/www:{$root}/www/include");
include("include/init.php");
loadlib("cli");
loadlib("api_config");
loadlib("api_spec");
$spec = array(
"output" => array("flag" => "o", "required" => 0, "help" => "..., default is STDOUT"),
"all" => array("flag" => "a", "required" => 0, "boolean" => 1, "help" => "..."),
"exclude" => array("flag" => "e", "required" => 0, "help" => "..."),
# something about abs_root_url here...
);
$opts = cli_getopts($spec);
#
api_config_init();
ksort($GLOBALS['cfg']['api']['methods']);
# this is a dirty hack... (20130406/straup)
$tmpdir = realpath(dirname(__FILE__)) . "/api_c";
if (! is_dir($tmpdir)){
mkdir($tmpdir);
}
$GLOBALS['smarty']->compile_dir = $tmpdir;
#
$exclude = ($opts['exclude']) ? explode(",", $opts['exclude']) : array();
#
if ($opts['output']){
$fh = fopen($opts['output'], 'w');
}
else {
$fh = fopen("php://output", "w");
}
$methods = array();
foreach ($GLOBALS['cfg']['api']['methods'] as $method_name => $method_details){
$include = 1;
if (! $method_details['enabled']){
$include = 0;
}
if (! $method_details['documented']){
$include = 0;
}
if ($method_details['requires_blessing']){
$include = 0;
}
if ($opts['all']){
$include = 1;
}
foreach ($exclude as $what){
if (preg_match("/^{$what}/", $method_name)){
$include = 0;
break;
}
}
if (! $include){
continue;
}
$methods[$method_name] = $method_details;
}
# Header (maybe?)
# $GLOBALS['smarty']->assign("page_title", "{$GLOBALS['cfg']['site_name']} API documentation");
# fwrite($fh, $GLOBALS['smarty']->fetch("inc_head.txt"));
# Table of contents
$GLOBALS['smarty']->assign_by_ref("methods", $methods);
fwrite($fh, $GLOBALS['smarty']->fetch("inc_api_methods_toc.txt"));
# The actual API methods
foreach ($methods as $method_name => $method_details){
$rsp = api_spec_utils_example_for_method($method_name);
if ($rsp['ok']){
$details['example_response'] = $rsp['example'];
}
$GLOBALS['smarty']->assign_by_ref("method", $method_name);
$GLOBALS['smarty']->assign_by_ref("details", $method_details);
fwrite($fh, $GLOBALS['smarty']->fetch("inc_api_method.txt"));
}
# Footer (maybe?)
# fwrite($fh, $GLOBALS['smarty']->fetch("inc_foot.txt"));
fclose($fh);
# clean up dirty hack (above)
foreach (glob($tmpdir . '/*.php') as $file) {
unlink($file);
}
rmdir($tmpdir);
# wkpdf -s test.html -o test.pdf -y print -u css/api.css
exit();
?>