From 6e0ec25e0133d5797f9f0e30cfc346a5cb5d6583 Mon Sep 17 00:00:00 2001 From: Itz Abhi <157791077+golden-skipper03@users.noreply.github.com> Date: Thu, 11 Apr 2024 18:32:21 +0530 Subject: [PATCH] Add-Scastie-Box --- .../scala/scaladex/core/model/Artifact.scala | 73 +++++++------------ 1 file changed, 25 insertions(+), 48 deletions(-) diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala b/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala index 0fd56e702..473f41ea2 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala @@ -221,59 +221,36 @@ case class Artifact( } // todo: Add tests for this - // def scastieURL: String = { - // val tryBaseUrl = "https://scastie.scala-lang.org/try" - - // val targetParam = binaryVersion.platform match { - // case ScalaJs(_) => Some("t" -> "JS") - // case _ => None - // } - - // val scalaVersionParam = binaryVersion.language match { - // case Scala(v) => Some("sv" -> v.toString) - // case _ => None - // } - - // val params: List[(String, String)] = List( - // "g" -> groupId.value, - // "a" -> artifactName.value, - // "v" -> version.toString - // ) ++ targetParam ++ scalaVersionParam - - // params - // .map { case (k, v) => s"$k=$v" } - // .mkString(tryBaseUrl + "?", "&", "") - // } - - // def isSbtPlugin: Boolean = platform match { - // case SbtPlugin(_) => true - // case _ => false - // } - - def scastieURL: Option[String] = binaryVersion.platform match { - case SbtPlugin(_) | ScalaNative(_) => None - case _ => - val tryBaseUrl = "https://scastie.scala-lang.org/try" - - val targetParam = binaryVersion.platform match { - case ScalaJs(_) => Some("t" -> "JS") - case _ => Some("t" -> "JVM") - } - - val scalaVersionParam = binaryVersion.language match { - case Scala(v) => Some("sv" -> v.toString) - case _ => None - } + def scastieURL: Option[String] = { + val tryBaseUrl = "https://scastie.scala-lang.org/try" + + val targetParam = binaryVersion.platform match { + case ScalaJs(_) => Some("t" -> "JS") + case Jvm => Some("t" -> "JVM") + case _ => None + } + + val scalaVersionParam = binaryVersion.language match { + case Scala(v) => Some("sv" -> v.toString) + case _ => None + } + + for { + target <- targetParam + scalaVersion <- scalaVersionParam + } yield { val params: List[(String, String)] = List( "g" -> groupId.value, "a" -> artifactName.value, "v" -> version.toString, - "o" -> projectRef.organization.toString, // removed getters - "r" -> projectRef.repository.toString - ) ++ targetParam ++ scalaVersionParam - - Some(params.map { case (k, v) => s"$k=$v" }.mkString(tryBaseUrl + "?", "&", "")) + "o" -> projectRef.organization.toString, + "r" -> projectRef.repository.toString, + target, + scalaVersion + ) + params.map { case (k, v) => s"$k=$v" }.mkString(tryBaseUrl + "?", "&", "") + } } }