Skip to content

Commit

Permalink
Replace teavm custom code module
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Oct 22, 2023
1 parent 4c22849 commit 9626d7e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private boolean parserBlock(Node node, BlockComment blockComment) {
return false;
}

public boolean parseCodeBlock(Node node, String headerCommands, String content) {
protected boolean parseCodeBlock(Node node, String headerCommands, String content) {
if(headerCommands.contains(CMD_ADD_RAW)) {
setAddReplaceCMD(node, content, false, true);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package emu.com.github.xpenatan.jparser.loader;

import java.util.HashSet;
import org.teavm.jso.browser.Window;
import org.teavm.jso.dom.events.Event;
import org.teavm.jso.dom.events.EventListener;
Expand All @@ -8,6 +9,8 @@

public class JParserLibraryLoader {

private static HashSet<String> loadedLibraries = new HashSet<>();

public JParserLibraryLoader() {
}

Expand All @@ -26,19 +29,24 @@ public void load(String libraryName, Runnable runnable) {
}

public void load(String libraryName01, String libraryName02, Runnable runnable) {
String libPath = "assets/" + libraryName01 + ".js";;
if(loadedLibraries.contains(libPath)) {
return;
}

if(libraryName02 != null) {

}
if(libraryName01 != null) {
libraryName01 = "assets/" + libraryName01 + ".js";
System.out.println("Loading JS script: " + libraryName01);
System.out.println("Loading JS script: " + libPath);
Window current = Window.current();
HTMLDocument document = current.getDocument();
HTMLScriptElement scriptElement = (HTMLScriptElement)document.createElement("script");
scriptElement.setSrc(libraryName01);
scriptElement.setSrc(libPath);
scriptElement.addEventListener("load", new EventListener<Event>() {
@Override
public void handleEvent(Event evt) {
loadedLibraries.add(libPath);
if(runnable != null) {
runnable.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,4 +583,11 @@ public void onParserComplete(JParser jParser, ArrayList<JParserItem> parserItems
convertCallerLongToInt(all);
}
}

@Override
protected boolean parseCodeBlock(Node node, String headerCommands, String content) {
// Replace custom code that contains module tag
String newContent = content.replace(TEMPLATE_TAG_MODULE, module);
return super.parseCodeBlock(node, headerCommands, newContent);
}
}

0 comments on commit 9626d7e

Please sign in to comment.