Skip to content

Commit

Permalink
Make Microsite Interactive, with a bad UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDavenport committed Nov 21, 2021
1 parent 265372d commit 85fe386
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
16 changes: 11 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ThisBuild / githubWorkflowPublishPreamble ++= Seq(

ThisBuild / githubWorkflowPublish ++= Seq(
WorkflowStep.Sbt(
List("coreJS/npmPackageNpmrc", "coreJS/npmPackagePublish"),
List("npmPackageNpmrc", "npmPackagePublish"),
name = Some("Publish artifacts to npm"),
env = Map(
"NPM_TOKEN" -> "${{ secrets.NPM_TOKEN }}" // https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow#set-the-token-as-an-environment-variable-on-the-cicd-server
Expand All @@ -44,15 +44,12 @@ ThisBuild / githubWorkflowPublish ++= Seq(
)



val catsV = "2.6.1"
val catsEffectV = "3.2.9"
val catsParseV = "0.3.6"
val http4sV = "0.23.6"
val munitCatsEffectV = "1.0.6"



// Projects
lazy val `curly` = project.in(file("."))
.disablePlugins(MimaPlugin)
Expand Down Expand Up @@ -90,13 +87,22 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
npmPackageBinaryEnable := true,
)

lazy val jsdocs = project
.enablePlugins(ScalaJSPlugin)
.dependsOn(core.js)
.settings(
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % "2.0.0",
evictionErrorLevel := sbt.util.Level.Info,

)

lazy val site = project.in(file("site"))
.disablePlugins(MimaPlugin)
.enablePlugins(DavenverseMicrositePlugin)
.dependsOn(core.jvm)
.settings{
import microsites._
Seq(
mdocJS := Some(jsdocs),
micrositeDescription := "Oh! A WISE guy, eh?",
)
}
3 changes: 2 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.20")
addSbtPlugin("io.chrisdavenport" % "sbt-davenverse" % "0.1.3")
addSbtPlugin("io.chrisdavenport" % "sbt-davenverse" % "0.1.4")
addSbtPlugin("io.chrisdavenport" % "sbt-npm-package" % "0.0.5")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.24" )
38 changes: 31 additions & 7 deletions site/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,39 @@ layout: home

---

# curly - Oh! A WISE guy, eh? [![Build Status](https://travis-ci.com/ChristopherDavenport/curly.svg?branch=master)](https://travis-ci.com/ChristopherDavenport/curly) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/curly_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/curly_2.12)
# curly4s - Oh! A WISE guy, eh? [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/curly_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/curly_2.13)

## Quick Start

To use curly in an existing SBT project with Scala 2.11 or a later version, add the following dependencies to your
`build.sbt` depending on your needs:
```scala mdoc:js:invisible
<input type="text" id="curl" style="height:120px; width:200px;">
<button id="button">Run Curly4s</button>
<br>
<div id="output"></div>
---
import cats.syntax.all._
import cats.effect._
import cats.effect.unsafe.implicits._
import org.scalajs.dom._
import io.chrisdavenport.curly._

val inputElement = document.getElementById("curl").asInstanceOf[html.Input]
val outputElement = document.getElementById("output")
val button = document.getElementById("button").asInstanceOf[html.Button]

val process = for {
command <- IO(inputElement.value)
opts <- CurlyParser.parseOpts[IO](command)
data <- CurlyData.fromOpts[IO](opts)
(_, s) <- CurlyHttp4s.fromData[IO](data)
} yield s

def handleErrors(io: IO[String]): IO[String] =
io.handleErrorWith(e => e.toString.pure[IO])

def setOutput(s: String): IO[Unit] = IO(outputElement.innerHTML = s)

def run = handleErrors(process).flatMap(setOutput)

```scala
libraryDependencies ++= Seq(
"io.chrisdavenport" %% "curly" % "<version>"
)
button.onclick = _ => run.unsafeRunAndForget()
```

0 comments on commit 85fe386

Please sign in to comment.