From af47fe1c6008dbd9b37f224b234387e030e7291d Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sun, 24 Oct 2021 04:50:52 +0000 Subject: [PATCH 01/20] Setup docs project --- build.sbt | 13 +++++++++++++ docs/index.md | 15 +++++++++++++++ project/plugins.sbt | 1 + 3 files changed, 29 insertions(+) create mode 100644 docs/index.md diff --git a/build.sbt b/build.sbt index 750501f7..c860e0bc 100644 --- a/build.sbt +++ b/build.sbt @@ -146,3 +146,16 @@ lazy val tests = project ) .dependsOn(dom) .enablePlugins(ScalaJSPlugin, BuildInfoPlugin, NoPublishPlugin) + +lazy val jsdocs = project.dependsOn(dom) +lazy val docs = + project + .in(file("mdocs")) + .settings( + mdocJS := Some(jsdocs), + mdocVariables := Map( + "VERSION" -> (if (isSnapshot.value) + git.baseVersion.value + else + version.value))) + .enablePlugins(MdocPlugin) diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..e279816b --- /dev/null +++ b/docs/index.md @@ -0,0 +1,15 @@ +# http4s-dom + +Installation: +```sbt +// supports http4s 0.23.x and scala-js-dom 2.x +libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.2.0" + +// supports http4s 0.23.x and scala-js-dom 1.x +libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.1.0" +``` + +```scala mdoc +val x = 1 +List(x, x) +``` diff --git a/project/plugins.sbt b/project/plugins.sbt index 4ffd04d4..060ff733 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -5,3 +5,4 @@ addSbtPlugin("com.codecommit" % "sbt-spiewak-sonatype" % "0.22.1") addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") +addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.24") From 80ab03428452b9f665a9145863a851407404dfeb Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sat, 23 Oct 2021 22:47:33 -0700 Subject: [PATCH 02/20] Try mdocjs --- docs/index.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index e279816b..010c6a13 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,7 +1,7 @@ # http4s-dom Installation: -```sbt +```scala // supports http4s 0.23.x and scala-js-dom 2.x libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.2.0" @@ -9,7 +9,8 @@ libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.2.0" libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.1.0" ``` -```scala mdoc +```scala mdoc:js val x = 1 + List(x, x) ``` From 812e3588860efa5d96b84c75eecfb4363fa3ea1e Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sun, 24 Oct 2021 02:08:39 -0700 Subject: [PATCH 03/20] Working docs. Half-decent --- build.sbt | 15 +++++++++++++-- docs/index.md | 53 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/build.sbt b/build.sbt index c860e0bc..c3135b4e 100644 --- a/build.sbt +++ b/build.sbt @@ -39,7 +39,8 @@ ThisBuild / scmInfo := Some( url("https://github.com/http4s/http4s-dom"), "https://github.com/http4s/http4s-dom.git")) -ThisBuild / crossScalaVersions := Seq("2.12.15", "3.1.0", "2.13.6") +val scala3 = "3.1.0" +ThisBuild / crossScalaVersions := Seq("2.12.15", scala3, "2.13.6") replaceCommandAlias("ci", CI.AllCIs.map(_.toString).mkString) addCommandAlias("ciFirefox", CI.Firefox.toString) @@ -147,7 +148,17 @@ lazy val tests = project .dependsOn(dom) .enablePlugins(ScalaJSPlugin, BuildInfoPlugin, NoPublishPlugin) -lazy val jsdocs = project.dependsOn(dom) +lazy val jsdocs = + project + .dependsOn(dom) + .settings( + libraryDependencies ++= Seq( + "org.http4s" %%% "http4s-circe" % http4sVersion, + "io.circe" %%% "circe-generic" % "0.15.0-M1" + ) + ) + .enablePlugins(ScalaJSPlugin) + lazy val docs = project .in(file("mdocs")) diff --git a/docs/index.md b/docs/index.md index 010c6a13..b6796804 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,16 +1,57 @@ # http4s-dom -Installation: +### Installation + ```scala -// supports http4s 0.23.x and scala-js-dom 2.x +// Supports http4s 0.23.x and scala-js-dom 2.x libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.2.0" -// supports http4s 0.23.x and scala-js-dom 1.x -libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.1.0" +// Or, for compatibility with scala-js-dom 1.x +// libraryDependencies += "org.http4s" %%% "http4s-dom" % "0.1.0" + +// recommended, brings in the latest client module +libraryDependencies += "org.http4s" %%% "http4s-client" % "0.23.6" + +// optional, for JSON support +libraryDependencies += "org.http4s" %%% "http4s-circe" % "0.23.6" +libraryDependencies += "io.circe" %%% "circe-generic" % "0.15.0-M1" ``` +### Example + ```scala mdoc:js -val x = 1 +
+

+ Can I haz dad joke? +

+ +

+
+--- +import cats.effect._ +import cats.effect.unsafe.implicits._ +import io.circe.generic.auto._ +import org.http4s.circe.CirceEntityCodec._ +import org.http4s.dom._ +import org.scalajs.dom._ + +val client = FetchClientBuilder[IO].create + +val jokeElement = document.getElementById("joke") -List(x, x) +final case class Joke(joke: String) + +val fetchJoke: IO[Unit] = for { + joke <- client.expect[Joke]("https://icanhazdadjoke.com/") + _ <- IO(jokeElement.innerHTML = joke.joke) +} yield () + +val button = + document.getElementById("button").asInstanceOf[html.Button] + +button.onclick = _ => fetchJoke.unsafeRunAndForget() ``` + +### Learn more + +Check out the http4s [client documentation](https://http4s.org/v0.23/client/). From 6ce7f1d84cefd938dfc6b0710a6fb062b7d5aa10 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sun, 24 Oct 2021 12:52:12 -0700 Subject: [PATCH 04/20] Laika to the rescue! --- build.sbt | 70 ++++++++++++++++++++++++--- docs/{index.md => README.md} | 14 +++--- docs/default.template.html | 93 ++++++++++++++++++++++++++++++++++++ docs/styles/site.css | 9 ++++ project/plugins.sbt | 1 + 5 files changed, 174 insertions(+), 13 deletions(-) rename docs/{index.md => README.md} (75%) create mode 100644 docs/default.template.html create mode 100644 docs/styles/site.css diff --git a/build.sbt b/build.sbt index c3135b4e..d9c987f2 100644 --- a/build.sbt +++ b/build.sbt @@ -159,14 +159,72 @@ lazy val jsdocs = ) .enablePlugins(ScalaJSPlugin) +import laika.ast.Path.Root +import laika.ast._ +import laika.ast.LengthUnit._ +import laika.helium.Helium +import laika.helium.config.{HeliumIcon, IconLink, ImageLink, ReleaseInfo, Teaser, TextLink} +import laika.theme.config.Color + lazy val docs = project .in(file("mdocs")) .settings( mdocJS := Some(jsdocs), - mdocVariables := Map( - "VERSION" -> (if (isSnapshot.value) - git.baseVersion.value - else - version.value))) - .enablePlugins(MdocPlugin) + Laika / sourceDirectories := Seq(mdocOut.value), + laikaConfig ~= { _.withRawContent }, + laikaExtensions ++= Seq( + laika.markdown.github.GitHubFlavor, + laika.parse.code.SyntaxHighlighting + ), + laikaTheme := Helium + .defaults + .all + .metadata( + language = Some("en"), + title = Some("http4s-dom") + ) + .site + .layout( + contentWidth = px(860), + navigationWidth = px(275), + topBarHeight = px(35), + defaultBlockSpacing = px(10), + defaultLineHeight = 1.5, + anchorPlacement = laika.helium.config.AnchorPlacement.Right + ) + .site + .themeColors( + primary = Color.hex("5B7980"), + secondary = Color.hex("cc6600"), + primaryMedium = Color.hex("a7d4de"), + primaryLight = Color.hex("e9f1f2"), + text = Color.hex("5f5f5f"), + background = Color.hex("ffffff"), + bgGradient = + (Color.hex("334044"), Color.hex("5B7980")) // only used for landing page background + ) + .site + .darkMode + .disabled + .site + .topNavigationBar( + homeLink = ImageLink.external( + "https://http4s.org", + Image.external("https://http4s.org/v1.0/images/http4s-logo-text-dark-2.svg")), + navLinks = Seq( + IconLink.external( + "https://www.javadoc.io/doc/org.http4s/http4s-dom_sjs1_2.13/latest/org/http4s/dom/index.html", + HeliumIcon.api, + options = Styles("svg-link")), + IconLink.external( + "https://github.com/http4s/http4s-dom", + HeliumIcon.github, + options = Styles("svg-link")), + IconLink.external("https://discord.gg/XF3CXcMzqD", HeliumIcon.chat), + IconLink.external("https://twitter.com/http4s", HeliumIcon.twitter) + ) + ) + .build + ) + .enablePlugins(MdocPlugin, LaikaPlugin) diff --git a/docs/index.md b/docs/README.md similarity index 75% rename from docs/index.md rename to docs/README.md index b6796804..f6001fe7 100644 --- a/docs/index.md +++ b/docs/README.md @@ -1,6 +1,6 @@ # http4s-dom -### Installation +## Installation ```scala // Supports http4s 0.23.x and scala-js-dom 2.x @@ -17,13 +17,13 @@ libraryDependencies += "org.http4s" %%% "http4s-circe" % "0.23.6" libraryDependencies += "io.circe" %%% "circe-generic" % "0.15.0-M1" ``` -### Example +## Example ```scala mdoc:js
-

- Can I haz dad joke? -

+

+ I can haz dad joke? +

@@ -52,6 +52,6 @@ val button = button.onclick = _ => fetchJoke.unsafeRunAndForget() ``` -### Learn more +## Learn more -Check out the http4s [client documentation](https://http4s.org/v0.23/client/). +The [`FetchClientBuilder`](https://www.javadoc.io/doc/org.http4s/http4s-dom_sjs1_2.13/latest/org/http4s/dom/FetchClientBuilder.html) creates a standard http4s [`Client`](https://http4s.org/v0.23/api/org/http4s/client/client) that is described in the [http4s documentation](https://http4s.org/v0.23/client/). diff --git a/docs/default.template.html b/docs/default.template.html new file mode 100644 index 00000000..c02d3e9b --- /dev/null +++ b/docs/default.template.html @@ -0,0 +1,93 @@ + + + + + + + + ${cursor.currentDocument.title} + @:for(laika.site.metadata.authors) + + @:@ + @:for(laika.site.metadata.description) + + @:@ + @:for(helium.favIcons) + + @:@ + @:for(helium.webFonts) + + @:@ + @:linkCSS { paths = ${helium.site.includeCSS} } + @:linkJS { paths = ${helium.site.includeJS} } + @:heliumInitVersions + @:heliumInitPreview(container) + + + + + +
+ +
+ +
+ + ${?helium.topBar.home} + + ${?helium.topBar.links} + +
+ + + +
+ + + +
+ + ${cursor.currentDocument.content} + + +
+ + + +
+ +
+ + + diff --git a/docs/styles/site.css b/docs/styles/site.css new file mode 100644 index 00000000..cf1a921d --- /dev/null +++ b/docs/styles/site.css @@ -0,0 +1,9 @@ +header img { + height: 28px; + width: auto; + margin-top: 6px; +} + +#sidebar li.nav-header { + margin-top: -20px; +} diff --git a/project/plugins.sbt b/project/plugins.sbt index 060ff733..cd1e3726 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -6,3 +6,4 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.7.1") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0") addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.24") +addSbtPlugin("org.planet42" % "laika-sbt" % "0.18.0") From 78e45b2d65605aaf7c35338c3e8ba42a13a38cdb Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Sun, 24 Oct 2021 12:58:33 -0700 Subject: [PATCH 05/20] Layout tweaking --- docs/default.template.html | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/default.template.html b/docs/default.template.html index c02d3e9b..d17f3293 100644 --- a/docs/default.template.html +++ b/docs/default.template.html @@ -29,8 +29,20 @@
-
- + + ${?helium.topBar.home} @@ -51,7 +63,6 @@