Skip to content

Commit

Permalink
refactor: theme header
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Nov 24, 2024
1 parent 50ded0a commit bb5f966
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/net/sourceforge/plantuml/theme/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
package net.sourceforge.plantuml.theme;

import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;

import net.sourceforge.plantuml.json.JsonObject;
import net.sourceforge.plantuml.preproc.ReadLine;
import net.sourceforge.plantuml.preproc.ReadLineWithYamlHeader;
import net.sourceforge.plantuml.text.StringLocated;
Expand All @@ -58,8 +59,12 @@ public void close() throws IOException {
source.close();
}

public Map<String, String> getMetadata() {
return source.getMetadata();
public JsonObject getMetadata() {
final JsonObject result = new JsonObject();
for (Entry<String, String> ent : source.getMetadata().entrySet())
result.add(ent.getKey(), ent.getValue());

return result;
}

}
9 changes: 5 additions & 4 deletions src/net/sourceforge/plantuml/tim/TContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import net.sourceforge.plantuml.FileSystem;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.json.Json;
import net.sourceforge.plantuml.json.JsonObject;
import net.sourceforge.plantuml.json.JsonValue;
import net.sourceforge.plantuml.log.Logme;
import net.sourceforge.plantuml.preproc.Defines;
Expand Down Expand Up @@ -636,10 +637,10 @@ private void executeIncludeDef(TMemory memory, StringLocated s) throws EaterExce
}
}

private Map<String, String> headerMetadata = Collections.emptyMap();
private JsonObject themeMetadata = new JsonObject();

public Map<String, String> getHeaderMetadata() {
return headerMetadata;
public JsonObject getThemeMetadata() {
return themeMetadata;
}

private void executeTheme(TMemory memory, StringLocated s) throws EaterException {
Expand All @@ -663,7 +664,7 @@ private void executeTheme(TMemory memory, StringLocated s) throws EaterException
Logme.error(e);
throw new EaterException("Error reading theme " + e, s);
} finally {
this.headerMetadata = theme.getMetadata();
this.themeMetadata = theme.getMetadata();
try {
theme.close();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import net.sourceforge.plantuml.json.JsonObject;
Expand All @@ -61,9 +60,7 @@ public boolean canCover(int nbArg, Set<String> namedArgument) {
@Override
public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List<TValue> values,
Map<String, TValue> named) throws EaterException {
final JsonObject result = new JsonObject();
for (Entry<String, String> ent : context.getHeaderMetadata().entrySet())
result.add(ent.getKey(), ent.getValue());
final JsonObject result = context.getThemeMetadata();

return TValue.fromJson(result);
}
Expand Down

0 comments on commit bb5f966

Please sign in to comment.