Skip to content

Commit

Permalink
Support for source file launches
Browse files Browse the repository at this point in the history
  • Loading branch information
marchof committed Oct 5, 2024
1 parent 0ab64ba commit c9d7639
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
11 changes: 6 additions & 5 deletions site/assets/app/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ Vue.component('sandbox', {
template: `
<tabs v-bind:infotext="versioninfo" v-bind:infotooltip="versioninfoext">
<slot></slot>
<tab v-bind:onTabClicked="compileandrun" name="▶︎ Run">
<tab v-bind:onTabClicked="run" name="▶︎ Run">
<div class="sandbox-console">{{ "{{" }} output }}</div>
</tab>
</tabs>
`,
props: {
version: { type: String, required: true },
mainclass: { type: String, required: true },
mainclass: { type: String, required: false },
mainsource: { type: String, required: false },
preview: { type: Boolean, required: false, default: false },
showInvisibles: { type: Boolean, required: false, default: false }
},
Expand All @@ -34,7 +35,7 @@ Vue.component('sandbox', {
serviceurl(action) {
return `{{ $.Site.Params.Api.Sandbox }}jdk/${this.version.replace("java", "")}/${action}`;
},
compileandrun() {
run() {
this.output = "Compile and run with " + this.versioninfo + " ...";
const sourcefiles = [];
this.$children[0].$children.forEach(tab => {
Expand All @@ -43,11 +44,11 @@ Vue.component('sandbox', {
}
});
request = {
mainclass: this.mainclass,
mainclass: this.mainclass || this.mainsource,
preview: this.preview,
sourcefiles: sourcefiles
};
fetch(this.serviceurl("compileandrun"), { method: "POST", body: JSON.stringify(request) })
fetch(this.serviceurl(this.mainclass ? "compileandrun" : "runfromsource"), { method: "POST", body: JSON.stringify(request) })
.then(r => r.json())
.then(response => this.output = response.output );
}
Expand Down
13 changes: 5 additions & 8 deletions site/content/jdk/24/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ description: Information about Java 24 including documentation links, new APIs,

Instantly compile and run Java 24 snippets without a local Java installation.

{{< sandbox version="java24" mainclass="Java24" preview="true" >}}
{{< sandbox version="java24" mainsource="Java24.java" preview="true" >}}
{{< sandboxsource "Java24.java" >}}
import java.lang.reflect.ClassFileFormatVersion;

public class Java24 {

public static void main(String[] args) {
var v = ClassFileFormatVersion.latest();
System.out.printf("Hello Java bytecode version %s!", v.major());
}

void main(String[] args) {
var v = ClassFileFormatVersion.latest();
System.out.printf("Hello Java bytecode version %s!", v.major());
}

{{< /sandboxsource >}}
{{< /sandbox >}}
2 changes: 1 addition & 1 deletion site/layouts/shortcodes/sandbox.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<sandbox version="{{ .Get "version"}}" mainclass="{{ .Get "mainclass"}}"{{ with .Get "preview"}} preview="{{.}}"{{ end }}{{ with .Get "show-invisibles"}} v-bind:show-invisibles="{{.}}"{{ end }} v-cloak>
<sandbox version="{{ .Get "version"}}" {{ with .Get "mainclass"}} mainclass="{{.}}"{{ end }}{{ with .Get "mainsource"}} mainsource="{{.}}"{{ end }}{{ with .Get "preview"}} preview="{{.}}"{{ end }}{{ with .Get "show-invisibles"}} v-bind:show-invisibles="{{.}}"{{ end }} v-cloak>
{{- .Inner -}}
</sandbox>
{{- .Page.Store.Set "hasSandbox" true -}}

0 comments on commit c9d7639

Please sign in to comment.