Skip to content

Commit c7394ec

Browse files
committed
Feat: add development parser and fix representation
1 parent 4d0237b commit c7394ec

File tree

4 files changed

+104
-81
lines changed

4 files changed

+104
-81
lines changed

Dockerfile.parser

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3 AS parser
2+
RUN mkdir /app/data -p
3+
ADD data-new/ /app/data-new
4+
ADD scripts/merge-dimensions.py /app/scripts/merge-dimensions.py
5+
WORKDIR /app
6+
RUN pip install pyyaml
7+
CMD ["python3", "/app/scripts/merge-dimensions.py"]

data.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* @see graph.php
88
* @see index.php
99
* @see mappings.php
10-
* @see md.php
1110
* @see report-samm.php
1211
* @see report.php
1312
* @see scutter.php

detail.php

Lines changed: 94 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
if (array_key_exists("element", $_GET)) {
13-
$title = "Details for '" . htmlspecialchars($_GET['element']) . "'";
13+
$title = "Details for '" . htmlspecialchars($_GET['element']) . "'";
1414
}
1515
include_once "head.php";
1616
?>
@@ -30,97 +30,112 @@
3030
* @param unknown $subdimension
3131
* @param unknown $activityName
3232
* @param unknown $dimensions
33-
* @param unknown $report (optional)
33+
* @param unknown $report (optional)
3434
*/
35-
function printDetail($dimension, $subdimension, $activityName, $dimensions, $report = false) {
36-
$element = $dimensions[$dimension][$subdimension][$activityName] ?? null;
37-
38-
if ($element == null) { //Whitelist approach for security reasons (deny XSS)
39-
//echo "Sorry, we could not found the element";
40-
return;
41-
}
42-
if ($report) {
43-
$headerWeight = 3;
44-
} else {
45-
$headerWeight = 1;
46-
}
47-
48-
$pageH1 = "";
49-
if (!$report) {
50-
$pageH1 .= $dimension;
51-
52-
if ($dimension != $subdimension) {
53-
54-
$pageH1 .= " -> $subdimension";
35+
function printDetail($dimension, $subdimension, $activityName, $dimensions, $report = false)
36+
{
37+
$element = $dimensions[$dimension][$subdimension][$activityName] ?? null;
38+
39+
if ($element == null) { //Whitelist approach for security reasons (deny XSS)
40+
//echo "Sorry, we could not found the element";
41+
return;
42+
}
43+
if ($report) {
44+
$headerWeight = 3;
45+
} else {
46+
$headerWeight = 1;
5547
}
56-
$pageH1 .= ": $activityName";
57-
} else {
58-
$pageH1 .= "$activityName";
59-
}
60-
61-
echo "<h$headerWeight>$pageH1</h$headerWeight>";
62-
echo build_table_tooltip($element, $headerWeight + 1);
63-
echo "<hr/>";
64-
65-
if (array_key_exists("dependsOn", $element) || array_key_exists("implementation", $element) || array_key_exists("comment", $element) || array_key_exists("meta", $element)) {
66-
echo "<h" . ($headerWeight + 1) . ">Additional Information</h" . ($headerWeight + 1) . ">";
67-
if (array_key_exists("dependsOn", $element)) {
68-
$dependsOn = $element['dependsOn'];
69-
$dependencies = implode(", ", $dependsOn);
70-
echo "<div><b>Dependencies:</b> $dependencies</div>";
48+
49+
$pageH1 = "";
50+
if (!$report) {
51+
$pageH1 .= $dimension;
52+
53+
if ($dimension != $subdimension) {
54+
55+
$pageH1 .= " -> $subdimension";
56+
}
57+
$pageH1 .= ": $activityName";
58+
} else {
59+
$pageH1 .= "$activityName";
7160
}
72-
echo getElementContentAndCheckExistence($element, "meta");
73-
}
74-
75-
76-
if (array_key_exists("md-description", $element) && !empty($element['md-description'])) {
77-
echo "<div style=\"background: #F5F5F5\"";
78-
echo $element['md-description'];
79-
echo "</div>";
80-
}
81-
if (array_key_exists("implementation", $element) && !empty($element['implementation'])) {
82-
$implementation = $element['implementation'];
83-
echo "<div><b>Implementation hints:</b> ";
84-
if (is_array($implementation)) {
85-
echo "<ul>";
86-
foreach ($implementation as $implementationElement) {
87-
echo "<li>$implementationElement</li>";
88-
}
89-
echo "</ul>";
90-
}else {
91-
echo $implementation;
61+
62+
echo "<h$headerWeight>$pageH1</h$headerWeight>";
63+
echo build_table_tooltip($element, $headerWeight + 1);
64+
echo "<hr/>";
65+
66+
if (array_key_exists("dependsOn", $element) || array_key_exists("implementation", $element) || array_key_exists("comment", $element) || array_key_exists("meta", $element)) {
67+
echo "<h" . ($headerWeight + 1) . ">Additional Information</h" . ($headerWeight + 1) . ">";
68+
if (array_key_exists("dependsOn", $element)) {
69+
$dependsOn = $element['dependsOn'];
70+
$dependencies = implode(", ", $dependsOn);
71+
echo "<div><b>Dependencies:</b> $dependencies</div>";
72+
}
73+
echo getElementContentAndCheckExistence($element, "meta");
9274
}
93-
echo "</div>";
94-
}
9575

96-
if (array_key_exists("comment", $element) && !empty($element['comment'])) {
97-
$comment = $element['comment'];
98-
echo "<div><b>Comments:</b> $comment</div>";
99-
}
10076

101-
printReferences($element);
77+
if (array_key_exists("md-description", $element) && !empty($element['md-description'])) {
78+
echo "<div style=\"background: #F5F5F5\">";
79+
$Parsedown = new Parsedown();
80+
echo $Parsedown->text($element['md-description']);
81+
echo "</div>";
82+
}
83+
if (array_key_exists("implementation", $element) && !empty($element['implementation'])) {
84+
$implementation = $element['implementation'];
85+
echo "<div><b>Implementation hints:</b> ";
86+
if (is_array($implementation)) {
87+
echo "<ul>";
88+
foreach ($implementation as $implementationElement) {
89+
if (is_array($implementationElement)) {
90+
echo $implementationElement['name'] . ', ';
91+
if (!empty($implementationElement['url'])) {
92+
echo '<a href="' . $implementationElement['url'] . '\">Link</a>';
93+
}
94+
echo ", Tags: ";
95+
foreach ($implementationElement['tags'] as $tag) {
96+
echo $tag . " ";
97+
}
98+
} else {
99+
echo "<li>$implementationElement</li>";
100+
}
101+
102+
}
103+
echo "</ul>";
104+
} else {
105+
echo $implementation;
106+
}
107+
echo "</div>";
108+
}
109+
110+
if (array_key_exists("comment", $element) && !empty($element['comment'])) {
111+
$comment = $element['comment'];
112+
echo "<div><b>Comments:</b> $comment</div>";
113+
}
114+
115+
printReferences($element);
102116
}
103117

104118

105119
/**
106120
*
107121
* @param unknown $element
108122
*/
109-
function printReferences($element) {
110-
if (!array_key_exists("references", $element)) {
111-
return;
112-
}
113-
$actionLabels = readYaml("data/strings.yml#/actionLabels");
114-
115-
$references = $element['references'];
116-
foreach ($references as $r => $values) {
117-
// if it's not an array, array-ze it. Remove after fixing all yamls.
118-
$values = is_array($values) ? $values : array($values);
119-
120-
$label = getReferenceLabel($r);
121-
echo "<div><h3>$label</h3></div>";
122-
echo "<ul><li>". implode("</li><li>", $values) ."</li></ul>";
123-
}
123+
function printReferences($element)
124+
{
125+
if (!array_key_exists("references", $element)) {
126+
return;
127+
}
128+
$actionLabels = readYaml("data/strings.yml#/actionLabels");
129+
130+
$references = $element['references'];
131+
foreach ($references as $r => $values) {
132+
// if it's not an array, array-ze it. Remove after fixing all yamls.
133+
$values = is_array($values) ? $values : array($values);
134+
135+
$label = getReferenceLabel($r);
136+
echo "<div><h3>$label</h3></div>";
137+
echo "<ul><li>" . implode("</li><li>", $values) . "</li></ul>";
138+
}
124139

125140

126141
}

functions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ function readYaml($file) {
1919
);
2020
if ($fragment) {
2121
foreach (explode("/", $fragment) as $key) {
22-
$ret = $ret[$key];
22+
if(array_key_exists($key, $ret)) {
23+
$ret = $ret[$key];
24+
}
2325
}
2426

2527
}

0 commit comments

Comments
 (0)