Skip to content

Commit

Permalink
bump scala and scala.js versions to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
simerplaha committed Oct 4, 2021
1 parent d53befa commit c7a8060
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 21 deletions.
9 changes: 4 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
enablePlugins(ScalaJSPlugin)
enablePlugins(WorkbenchPlugin)

name := "HtmlToScalaTagsConverter"

version := "1.0.0"

scalaVersion := "2.12.2"
scalaVersion := "2.13.6"

scalaJSUseMainModuleInitializer := true

libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "0.9.1",
"com.lihaoyi" %%% "scalatags" % "0.6.7"
)
"org.scala-js" %%% "scalajs-dom" % "1.2.0",
"com.lihaoyi" %%% "scalatags" % "0.9.4"
)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.0.1
sbt.version=1.5.5
4 changes: 1 addition & 3 deletions project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.21")

addSbtPlugin("com.lihaoyi" % "workbench" % "0.4.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.0")
2 changes: 1 addition & 1 deletion src/main/scala/simer/html/converter/HTMLTemplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object HTMLTemplate {
h4("HTML")
),
th(width := "50%")(
h4("Scalatags")
h4("Scala")
)
),
tr(width := "100%")(
Expand Down
21 changes: 10 additions & 11 deletions src/main/scala/simer/html/converter/HtmlToScalaTagsConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import org.scalajs.dom.html.TextArea
import org.scalajs.dom.raw.{DOMParser, NamedNodeMap, Node}

import scala.scalajs.js
import scala.scalajs.js.JSApp

object HtmlToScalaTagsConverter extends JSApp {
object HtmlToScalaTagsConverter {

def main(): Unit = {
def main(args: Array[String]): Unit = {
val template = HTMLTemplate.template(runConverter)
dom.document.getElementById("content").appendChild(template.render)
}
Expand All @@ -24,7 +23,7 @@ object HtmlToScalaTagsConverter extends JSApp {
val scalaCodes = rootChildNodes.map(toScalaTags(_, converterType))
val scalaCode =
if (scalaCodes.size > 1) {
val fixMe = s"""//FIXME - MULTIPLE HTML TREES PASSED TO THE CONVERTER. THIS MIGHT GENERATE UNEXPECTED SCALATAGS CODE. Check <!DOCTYPE html> is not in the input HTML."""
val fixMe = s"""//FIXME - MULTIPLE HTML TREES PASSED TO THE CONVERTER. THIS MIGHT GENERATE UNEXPECTED CODE. Check <!DOCTYPE html> is not in the input HTML."""
fixMe + "\n" + scalaCodes.mkString(", ")
} else
scalaCodes.mkString(", ")
Expand All @@ -33,7 +32,7 @@ object HtmlToScalaTagsConverter extends JSApp {
scalaCodeTextArea.value = scalaCodeWithoutParserAddedTags.trim
}

def removeGarbageChildNodes(node: Node): Seq[Node] =
def removeGarbageChildNodes(node: Node): collection.Seq[Node] =
node.childNodes.filterNot(isGarbageNode)

def isGarbageNode(node: Node): Boolean =
Expand All @@ -46,7 +45,7 @@ object HtmlToScalaTagsConverter extends JSApp {
*/
def toScalaTags(node: Node, converterType: ConverterType): String = {
//removes all comment and empty text nodes.
val childrenWithoutGarbageNodes: Seq[Node] = removeGarbageChildNodes(node)
val childrenWithoutGarbageNodes: collection.Seq[Node] = removeGarbageChildNodes(node)

val children = childrenWithoutGarbageNodes
.map(toScalaTags(_, converterType))
Expand All @@ -60,7 +59,7 @@ object HtmlToScalaTagsConverter extends JSApp {
*/
private def toScalaTag(node: Node,
converterType: ConverterType,
childrenWithoutGarbageNodes: Seq[Node],
childrenWithoutGarbageNodes: collection.Seq[Node],
children: String): String = {

val scalaAttrList = toScalaAttributes(attributes = node.attributes, converterType)
Expand All @@ -81,10 +80,10 @@ object HtmlToScalaTagsConverter extends JSApp {
else
scalaAttrList.mkString(", ")

s"${converterType.nodePrefix + node.nodeName.toLowerCase}($scalaAttrString${
if (children.isEmpty)
val childrenString =
if (children.isEmpty) {
""
else {
} else {
//text child nodes can be a part of the same List as the attribute List. They don't have to go to a new line.
val isChildNodeATextNode = childrenWithoutGarbageNodes.headOption.exists(_.nodeName == "#text")
val commaMayBe = if (scalaAttrString.isEmpty) "" else ","
Expand All @@ -93,8 +92,8 @@ object HtmlToScalaTagsConverter extends JSApp {
val endNewLineMayBe = if (isChildNodeATextNode && childrenWithoutGarbageNodes.size <= 1) "" else "\n"
s"$commaMayBe$startNewLineMayBe$children$endNewLineMayBe"
}
})"

s"${converterType.nodePrefix + node.nodeName.toLowerCase}($scalaAttrString$childrenString)"
}
}

Expand Down

0 comments on commit c7a8060

Please sign in to comment.