Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
timja committed Jul 28, 2022
1 parent e2100b3 commit 686df7b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<version>1.24.8</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jackson2-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/io/jenkins/plugins/thememanager/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -22,6 +23,11 @@
public class Theme {

private static final String JS_HTML = "<script type=\"text/javascript\" src=\"{0}\"></script>";
private static final String JSON_HTML =
"<script id=\"theme-manager-{0}\" type=\"application/json\">{1}</script>";

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private static final String CSS_HTML =
"<link type=\"text/css\" rel=\"stylesheet\" href=\"{0}\"/>";

Expand Down Expand Up @@ -55,6 +61,14 @@ Set<String> generateHeaderElements(boolean injectCss) {
headerElements.add(MessageFormat.format(JS_HTML, javascriptUrl));
}

try {
headerElements.add(
MessageFormat.format(
JSON_HTML, "properties", OBJECT_MAPPER.writeValueAsString(properties)));
} catch (Exception e) {
throw new RuntimeException(e);
}

return headerElements;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?jelly escape-by-default='false'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<script id="theme-manager-theme" type="application/json">{ "id": "${it.themeKey}" }</script>
<st:adjunct includes="io.jenkins.plugins.thememanager.header.main" />
${it.getHeaderHtml()}
<st:adjunct includes="io.jenkins.plugins.thememanager.header.main" />
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ const theme = JSON.parse(themeJson);

if (theme.id && theme.id !== '') {
document.documentElement.dataset.theme = theme.id
}
}


const propertiesJson = document.getElementById('theme-manager-properties').text
const parsedProperties = JSON.parse(propertiesJson);

Object.entries(parsedProperties)
.forEach((obj) => document.documentElement.dataset[obj[0]
.replace(/[-:]/g, '_')
] = obj[1]);

0 comments on commit 686df7b

Please sign in to comment.