Skip to content

Commit

Permalink
feat: auto generate about page help based on README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
grigoriev committed Jun 25, 2024
1 parent 5a67d72 commit 4988dd9
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ replay_pid*
target/
*.iml
dependency-reduced-pom.xml

src/main/resources/webapp/*-admin/html/about.html
README.html
26 changes: 26 additions & 0 deletions .scripts/convert-readme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

INPUT_FILE="${1:-README.md}"
OUTPUT_FILE="${2:-README.html}"

# Convert the markdown file to a JSON payload
jq -R -s '{"mode": "gfm", "text": .}' < "$INPUT_FILE" > payload.json

# Send the JSON payload to the GitHub API
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/markdown \
-d @payload.json > "$OUTPUT_FILE"

# Remove the temporary JSON payload
rm payload.json

# Remove the Build and Installation sections from readme
awk '
/<h2>Build<\/h2>/ {skip=1; next}
/<h2>Polarion configuration<\/h2>/ {skip=0}
!skip' "$OUTPUT_FILE" > "$OUTPUT_FILE.tmp" && mv "$OUTPUT_FILE.tmp" "$OUTPUT_FILE"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Changes only take effect after restart of Polarion.
2. On the top of the project's navigation pane click ⚙ (Actions) ➙ 🔧 Administration. Project's administration page will be opened.
3. On the administration's navigation pane select Portal ➙ Topics and click on Edit button of desired View.
4. In opened Topics Configuration editor insert following new topic:
```
```xml
<topic id="excel-importer"/>
Expand Down
Empty file.
104 changes: 103 additions & 1 deletion src/main/resources/webapp/excel-importer-admin/pages/about.jsp
Original file line number Diff line number Diff line change
@@ -1 +1,103 @@
<jsp:include page="/common/jsp/about.jsp" />
<%@ page import="ch.sbb.polarion.extension.generic.properties.CurrentExtensionConfiguration" %>
<%@ page import="ch.sbb.polarion.extension.generic.rest.model.Version" %>
<%@ page import="ch.sbb.polarion.extension.generic.util.ExtensionInfo" %>
<%@ page import="ch.sbb.polarion.extension.generic.util.VersionUtils" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.util.Properties" %>
<%@ page import="java.io.InputStream" %>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<!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">

<%!
private static final String ABOUT_TABLE_ROW = "<tr><td>%s</td><td>%s</td></tr>";
private static final String CONFIGURATION_PROPERTIES_TABLE_ROW = "<tr><td>%s</td><td>%s</td></tr>";
Version version = ExtensionInfo.getInstance().getVersion();
Properties properties = CurrentExtensionConfiguration.getInstance().getExtensionConfiguration().getProperties();
%>

<head>
<title></title>
<link rel="stylesheet" href="../ui/generic/css/common.css?bundle=<%= version.getBundleBuildTimestampDigitsOnly() %>">
<link rel="stylesheet" href="../ui/generic/css/about.css?bundle=<%= version.getBundleBuildTimestampDigitsOnly() %>">
<link rel="stylesheet" href="../ui/generic/css/github-markdown-light.css?bundle=<%= version.getBundleBuildTimestampDigitsOnly() %>">
</head>

<body>
<div class="standard-admin-page about-page">
<h1>About</h1>

<div class="about-page-text">
<img class="app-icon" src="../ui/images/app-icon.svg?bundle=<%= version.getBundleBuildTimestampDigitsOnly() %>" alt="" onerror="this.style.display='none'"/>

<h3>Extension info</h3>

<table>
<thead>
<tr>
<th>Manifest entry</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<%
out.println(ABOUT_TABLE_ROW.formatted(VersionUtils.BUNDLE_NAME, version.getBundleName()));
out.println(ABOUT_TABLE_ROW.formatted(VersionUtils.BUNDLE_VENDOR, version.getBundleVendor()));
if (version.getSupportEmail() != null) {
String mailToLink = "<a target=\"_blank\" href=\"mailto:%s\">%s</a>".formatted(version.getSupportEmail(), version.getSupportEmail());
out.println(ABOUT_TABLE_ROW.formatted(VersionUtils.SUPPORT_EMAIL, mailToLink));
}
out.println(ABOUT_TABLE_ROW.formatted(VersionUtils.AUTOMATIC_MODULE_NAME, version.getAutomaticModuleName()));
out.println(ABOUT_TABLE_ROW.formatted(VersionUtils.BUNDLE_VERSION, version.getBundleVersion()));
out.println(ABOUT_TABLE_ROW.formatted(VersionUtils.BUNDLE_BUILD_TIMESTAMP, version.getBundleBuildTimestamp()));
%>
</tbody>
</table>

<h3>Extension configuration properties</h3>

<table>
<thead>
<tr>
<th>Configuration property</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<%
Set<Object> keySet = properties.keySet();
List<String> propertyNames = new ArrayList<>();
for (Object key : keySet) {
propertyNames.add((String) key);
}
Collections.sort(propertyNames);
for (String key : propertyNames) {
String value = properties.getProperty(key);
String row = CONFIGURATION_PROPERTIES_TABLE_ROW.formatted(key, value);
out.println(row);
}
%>
</tbody>
</table>

<input id="scope" type="hidden" value="<%= request.getParameter("scope")%>"/>

<article class="markdown-body">
<%
try (InputStream inputStream = ExtensionInfo.class.getResourceAsStream("/webapp/excel-importer-admin/html/about.html")) {
assert inputStream != null;
String configurationHelp = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
out.println(configurationHelp);
}
%>
</article>
</div>
</div>
</body>
</html>

0 comments on commit 4988dd9

Please sign in to comment.