/
index.php
82 lines (70 loc) · 2.23 KB
/
index.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
<?php
/**
* Display a list of examples and extract the documentation
* block from the top of each one.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2011 Nicholas J Humfrey
* @license http://unlicense.org/
*/
$dir = dirname(__FILE__);
$dh = opendir($dir);
if (!$dh) {
die("Failed to open directory: $dir\n");
}
?>
<!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">
<head>
<title>EasyRdf Examples</title>
</head>
<body>
<h1>EasyRdf Examples</h1>
<?php
$examples = array();
while (($filename = readdir($dh)) !== false) {
if (substr($filename, 0, 1) == '.' or $filename == 'index.php') {
continue;
}
print "<h2><a href='$filename'>$filename</a></h2>\n";
$lines = file(
$dir . DIRECTORY_SEPARATOR . $filename,
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
);
$startDoc = false;
$tags = array();
$text = array();
$para = '';
foreach ($lines as $line) {
if (preg_match("/^\s*\/\*\*/", $line, $m)) {
$startDoc = true;
$tags = array();
} else if ($startDoc && preg_match("/^\s+\*\//", $line, $m)) {
$text[] = $para;
break;
} else if ($startDoc && preg_match("/^\s+\*\s+@(\w+)\s+(.*)/", $line, $m)) {
$tags[$m[1]] = $m[2];
} else if ($startDoc && preg_match("/^\s+\*\s*$/", $line, $m)) {
$text[] = $para;
$para = '';
} else if ($startDoc && preg_match("/^\s+\*\s*(.*)/", $line, $m)) {
if ($para) $para .= ' ';
$para .= $m[1];
}
}
foreach($text as $paragraph) {
print "<p>$paragraph</p>\n";
}
$examples[$filename] = $text[0];
}
closedir($dh);
// Create some Markdown that can be pasted into README.md
print "<!--\n";
foreach($examples as $filename => $desc) {
print "* [$filename](https://github.com/njh/easyrdf/blob/master/examples/$filename#slider) - $desc\n";
}
print "-->\n";
?>
</body>
</html>