-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for Scala JS for the main scripts #930
Changes from 5 commits
03171a7
7a868f8
94bec68
27a9cfb
28dffda
61f7165
12ed633
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ vendor/ | |
/.idea | ||
.ruby-version | ||
.sass-cache/ | ||
.ivy2/ | ||
.sbt/ | ||
target |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash -x | ||
command -v docker-compose >/dev/null 2>&1 || { echo >&2 "Please install Docker Compose: https://docs.docker.com/compose/install/"; exit 1; } | ||
docker-compose run js-build sbt fullOptJS |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/bin/bash | ||
command -v docker-compose >/dev/null 2>&1 || { echo >&2 "Please install Docker Compose: https://docs.docker.com/compose/install/"; exit 1; } | ||
docker-compose run --service-ports scala-lang jekyll serve --incremental | ||
docker-compose up | ||
docker-compose stop |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name := "scala-lang" | ||
|
||
organization in ThisBuild := "org.scalalang" | ||
version in ThisBuild := "0.1" | ||
scalaVersion in ThisBuild := "2.12.6" | ||
scalacOptions in ThisBuild ++= Seq( | ||
"-feature", | ||
"-deprecation" | ||
) | ||
|
||
lazy val functions = project in file("js-src/functions") | ||
|
||
lazy val root: Project = project.in(file(".")) | ||
.aggregate(functions) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import org.scalajs.core.tools.linker.backend.OutputMode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import is unused. |
||
|
||
enablePlugins(ScalaJSPlugin) | ||
|
||
name := "functions" | ||
|
||
libraryDependencies ++= Seq( | ||
"org.scala-js" %%% "scalajs-dom" % Versions.Dom, | ||
"org.querki" %%% "jquery-facade" % Versions.JQuery | ||
) | ||
|
||
// move our output folder to static | ||
artifactPath in(Compile, fastOptJS) := baseDirectory.value / ".." / ".." / "resources" / "js" / s"scala-${name.value}.js" | ||
artifactPath in(Compile, fullOptJS) := baseDirectory.value / ".." / ".." / "resources" / "js" / s"scala-${name.value}.js" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't configure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh good to know. What's the recommended way to setup a build like this? (Where I'd like my html file to be static and to just import the compiled output regardless of compilation target) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. I think it depends on the web server and/or templating mechanisms that one use. The folks at https://gitter.im/scala-js/scala-js or https://stackoverflow.com/questions/tagged/scala.js might have more experience with that than I do. |
||
scalaJSOptimizerOptions in (Compile, fullOptJS) ~= { _.withUseClosureCompiler(true) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This setting is redundant, as it is the default. |
||
|
||
scalaJSUseMainModuleInitializer := true | ||
emitSourceMaps := false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer the more future-proof scalaJSLinkerConfig ~= { _.withSourceMap(false) } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.scalalang | ||
|
||
import org.querki.jquery._ | ||
import org.scalajs.dom.{Element, document} | ||
import org.scalalang.utils.{JsUtils, Logger, OS} | ||
|
||
/** | ||
* This updates our download links based on the OS of the client | ||
*/ | ||
object DownloadLinks { | ||
|
||
def apply(): Unit = { | ||
setupBinariesElement() | ||
setupMainDownload() | ||
} | ||
|
||
private def setupBinariesElement(): Unit = JsUtils.findElement("#download-binaries").foreach((binariesElmnt: JQuery) => { | ||
val os: OS = OS() | ||
val osLabel: String = os.label | ||
|
||
var anchor: Element = document.getElementById("#link-main-unixsys") | ||
if (os == OS.Windows) { | ||
anchor = document.getElementById("#link-main-windows") | ||
} | ||
if (anchor == null) { | ||
anchor = document.getElementById("#link-main-one4all") | ||
} | ||
val link: String = anchor.getAttribute("href") | ||
|
||
binariesElmnt.attr("href", link).addClass(osLabel) | ||
$("#users-os").text(osLabel) | ||
}) | ||
|
||
private def setupMainDownload(): Unit = JsUtils.findElement(".main-download").foreach(_ => { | ||
val osLabel: String = OS().label | ||
|
||
val intelliJlink: String = $("#intellij-" + osLabel).text() | ||
val sbtLink: String = $("#sbt-" + osLabel).text() | ||
val stepOneContent: String = $("#stepOne-" + osLabel).html() | ||
|
||
$("#download-intellij-link").attr("href", intelliJlink) | ||
$("#download-sbt-link").attr("href", sbtLink) | ||
$("#download-step-one").html(stepOneContent) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.scalalang | ||
|
||
import org.querki.jquery._ | ||
import org.scalajs.dom.document | ||
import org.scalalang.utils.{Logger, RootLogger} | ||
|
||
/** | ||
* This is the main entry point for our application | ||
*/ | ||
object FunctionsApp { | ||
RootLogger.setTrace() | ||
|
||
private val logger: Logger = Logger[FunctionsApp.type] | ||
|
||
def main(args: Array[String]): Unit = { | ||
$(document).ready(() => { | ||
logger.trace("Dom Ready") | ||
|
||
Tooltip() | ||
DownloadLinks() | ||
PositionMarker() | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.scalalang | ||
|
||
import org.querki.jquery._ | ||
import org.scalajs.dom.window | ||
import org.scalalang.utils.JsUtils | ||
|
||
/** | ||
* This renders / updates the position marker on the front page | ||
*/ | ||
object PositionMarker { | ||
|
||
private val imageWidth: Int = 1680 | ||
|
||
// where our position should be on the image | ||
private val targetX: Int = 1028 | ||
private val targetY: Int = 290 | ||
|
||
def apply(): Unit = JsUtils.findElement("#position-marker") | ||
.foreach((pointer: JQuery) => { | ||
val updater: () => Unit = updatePointer(pointer) | ||
|
||
// register on window resize | ||
$(window).resize(updater) | ||
|
||
// initialize | ||
pointer.css("top", targetY) | ||
updater() | ||
}) | ||
|
||
private def updatePointer(pointer: JQuery): () => Unit = () => { | ||
val windowWidth: Double = $(window).width() | ||
|
||
val xScale: Double = windowWidth / imageWidth | ||
|
||
pointer.css("left", (targetX * xScale).toInt) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.scalalang | ||
|
||
import org.querki.jquery._ | ||
import org.scalajs.dom.Element | ||
|
||
import scala.scalajs.js | ||
|
||
/** | ||
* This renders tooltips for any .masterTooltip class element | ||
*/ | ||
object Tooltip { | ||
def apply(): Unit = { | ||
$(".masterTooltip") | ||
.hover( | ||
(tooltip: Element) => { | ||
// make sure we have a title | ||
$(tooltip).attr("title").toOption.foreach((title: String) => { | ||
// create our tooltip and place it on the body | ||
$("<p class=\"tooltip\"></p>") | ||
.text(title) | ||
.appendTo("body") | ||
.fadeIn("slow") | ||
}) | ||
}, | ||
() => { | ||
// remove our tooltip when we mouse off | ||
$(".tooltip").remove() | ||
} | ||
) | ||
.mousemove((e: JQueryEventObject) => { | ||
val mouseX: Int = e.pageX + 20 //Get X coordinates | ||
val mouseY: Int = e.pageY + 10 //Get Y coordinates | ||
|
||
$(".tooltip").css(js.Dictionary[js.Any]( | ||
"left" -> mouseX, | ||
"top" -> mouseY | ||
)) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.scalalang.utils | ||
|
||
import org.querki.jquery._ | ||
|
||
object JsUtils { | ||
/** | ||
* @param element the element we wish to find | ||
* @return the returned jquery element will have > 1 elements | ||
*/ | ||
@inline | ||
def findElement(element: ElementDesc): Option[JQuery] = { | ||
Option($(element)).filter(_.length > 0) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that docker-compose is only used for development, but if this isn't the case I could be breaking things here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct it's optional dev-only stuff