Skip to content

Commit b4b0bce

Browse files
Merge pull request #702 from scala/feature/scastie-front-page
Feature/scastie front page
2 parents 718844c + 9f56cd7 commit b4b0bce

File tree

3 files changed

+54
-29
lines changed

3 files changed

+54
-29
lines changed

_includes/scastie.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
<div class="wrap">
33
<div class="heading-line">
44
<h2><span>Run Scala in your browser</span></h2>
5-
<p class="lead">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer commodo neque eget placerat dapibus. Mauris ullamcorper dui eu pellentesque venenatis. Nam non elit vitae dolor posuere eleifend a facilisis diam</p>
5+
<p class="lead">
6+
Scastie is Scala + SBT in your browser!
7+
You can use any version of Scala, or even alternate backends
8+
such as Dotty, Scala.js, Scala Native, and Typelevel Scala. You can use
9+
any published library. You can save and share Scala programs/builds
10+
with anybody.
11+
</p>
612
</div>
713
</div>
814
<div class="call-to-action action-medium">
@@ -20,4 +26,4 @@ <h2><span>Run Scala in your browser</span></h2>
2026
</div>
2127
</div>
2228
</div>
23-
</section>
29+
</section>m

_layouts/frontpage.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ <h3>{{scalaItem.shortTitle}}</h3>
173173
</section>
174174

175175
<!-- Run Scala in your browser -->
176-
<!-- {% include scastie.html %} -->
176+
{% include scastie.html %}
177177

178178
<!-- Courses -->
179179
<section class="courses">

resources/js/functions.js

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -198,33 +198,52 @@ $(document).ready(function() {
198198

199199
// Scala in the browser
200200
$(document).ready(function() {
201-
if ($("#scastie-textarea").length) {
202-
var editor = CodeMirror.fromTextArea(document.getElementById("scastie-textarea"), {
203-
lineNumbers: true,
204-
matchBrackets: true,
205-
theme: "monokai",
206-
mode: "text/x-scala",
207-
autoRefresh: true,
208-
fixedGutter: false
209-
});
210-
editor.setSize("100%", ($("#scastie-code-container").height()));
211-
212-
var codeSnippet = "List(\"Hello\", \"World\").mkString(\"\", \", \", \"!\")";
213-
editor.getDoc().setValue(codeSnippet);
214-
editor.refresh();
215-
216-
$('.btn-run').click(function() {
217-
// TODO: Code to connect to the scastie server would be here, what follows is just a simulation for the UI elements:
218-
$('.btn-run').addClass("inactive");
219-
$('.btn-run i').removeClass("fa fa-play").addClass("fa fa-spinner fa-spin");
220-
setTimeout(function() {
221-
var currentCodeSnippet = editor.getDoc().getValue();
222-
console.log("Current code snippet: " + currentCodeSnippet);
223-
$('.btn-run').removeClass("inactive");
224-
$('.btn-run i').removeClass("fa-spinner fa-spin").addClass("fa fa-play");
225-
}, 2000);
226-
})
201+
if ($("#scastie-textarea").length) {
202+
var editor =
203+
CodeMirror.fromTextArea(
204+
document.getElementById("scastie-textarea"),
205+
{
206+
// lineNumbers: false,
207+
matchBrackets: true,
208+
theme: "monokai",
209+
mode: "text/x-scala",
210+
autoRefresh: true,
211+
fixedGutter: false,
212+
extraKeys: {
213+
'Ctrl-Enter': 'run',
214+
'Cmd-Enter': 'run'
215+
}
216+
}
217+
);
218+
219+
editor.setSize("100%", ($("#scastie-code-container").height()));
220+
221+
var codeSnippet = "List(\"Hello\", \"World\").mkString(\"\", \", \", \"!\")";
222+
editor.getDoc().setValue(codeSnippet);
223+
editor.refresh();
224+
225+
function run(){
226+
console.log("run");
227+
// var scastieBaseUrl = "https://scastie.scala-lang.org";
228+
var scastieBaseUrl = "http://localhost:9000";
229+
230+
$.ajax(
231+
{
232+
type: "POST",
233+
url: scastieBaseUrl + '/scala-lang',
234+
data: editor.getDoc().getValue(),
235+
success: function(url) {
236+
window.open(scastieBaseUrl + "/" + url);
237+
},
238+
// otherwise it's considered a popup
239+
async: false
240+
}
241+
)
227242
}
243+
244+
$('.btn-run').click(run);
245+
CodeMirror.commands.run = run;
246+
}
228247
});
229248

230249
// OS detection

0 commit comments

Comments
 (0)