From 60617d204b4577e010f137e8746c8d666542ec6c Mon Sep 17 00:00:00 2001 From: Noel Welsh Date: Fri, 23 Aug 2024 12:15:54 +0100 Subject: [PATCH] Update dependencies - Use Creative Scala theme - Update Doodle, plugins, etc. --- build.sbt | 15 +- project/CreativeScalaDirectives.scala | 232 -------------------------- project/plugins.sbt | 11 +- 3 files changed, 12 insertions(+), 246 deletions(-) delete mode 100644 project/CreativeScalaDirectives.scala diff --git a/build.sbt b/build.sbt index f93db089..9890a406 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ import scala.sys.process._ -import laika.config.LaikaKeys -import laika.theme.Theme +import laika.config.LinkConfig +import laika.config.ApiLinks val scala213 = "2.13.11" val scala3 = "3.3.1" @@ -29,8 +29,7 @@ lazy val build = taskKey[Unit]("Build the book") val commonSettings = Seq( libraryDependencies ++= Seq( - "org.creativescala" %%% "doodle" % "0.19.0", - "org.creativescala" %%% "doodle-svg" % "0.16.1" + "org.creativescala" %%% "doodle" % "0.23.0" ) ) @@ -52,20 +51,18 @@ lazy val book = project mdocOut := target.value / "pages", Laika / sourceDirectories := Seq( mdocOut.value, - sourceDirectory.value / "templates", sourceDirectory.value / "js", (examples / Compile / fastOptJS / artifactPath).value .getParentFile() / s"${(examples / moduleName).value}-fastopt" ), laikaExtensions ++= Seq( - laika.markdown.github.GitHubFlavor, - laika.parse.code.SyntaxHighlighting, - CreativeScalaDirectives + laika.format.Markdown.GitHubFlavor, + laika.config.SyntaxHighlighting, ), laikaSite / target := target.value / "creative-scala", laikaIncludeEPUB := false, laikaIncludePDF := false, - laikaTheme := Theme.empty, + laikaTheme := CreativeScalaTheme.empty.build, css := { val src = sourceDirectory.value / "css" val dest1 = mdocOut.value diff --git a/project/CreativeScalaDirectives.scala b/project/CreativeScalaDirectives.scala deleted file mode 100644 index a0de7b0a..00000000 --- a/project/CreativeScalaDirectives.scala +++ /dev/null @@ -1,232 +0,0 @@ -import cats.data._ -import cats.implicits._ -import laika.ast._ -import laika.directive._ -import laika.format.HTML - -object CreativeScalaDirectives extends DirectiveRegistry { - - override val description: String = - "Directive to work with CreativeScala SVG pictures." - - val leftArrow = "←" - val rightArrow = "→" - - val divWithId: Blocks.Directive = - Blocks.create("divWithId") { - import Blocks.dsl._ - - attribute(0) - .as[String] - .map { (id) => - RawContent( - NonEmptySet.one("html"), - s"""
""" - ) - } - } - - // Parameters are id and then JS function to call - val doodle: Blocks.Directive = - Blocks.create("doodle") { - import Blocks.dsl._ - - (attribute(0).as[String], attribute(1).as[String], cursor) - .mapN { (id, js, _) => - BlockSequence( - Seq( - RawContent( - NonEmptySet.one("html"), - s"""
""" - ), - RawContent( - NonEmptySet.one("html"), - s"""""" - ) - ) - ) - } - } - - // Insert a figure (image) - // - // Parameters: - // filename: String. The file name of the image - // key: String. The name of the reference for this image - // caption: String. The caption for this image - val figure: Blocks.Directive = - Blocks.create("figure") { - import Blocks.dsl._ - - ( - attribute("img").as[String].widen, - attribute("key").as[String].optional, - attribute("caption").as[String] - ).mapN { (img, key, caption) => - Paragraph( - Image( - Target.parse(img), - None, - None, - Some(caption), - Some(s"Figure $key: caption") - ) - ) - } - } - - val footnote: Blocks.Directive = - Blocks.create("footnote") { - import Blocks.dsl._ - - (attribute(0).as[String], parsedBody).mapN { (id, body) => - Footnote(id, body) - } - } - - // Insert a reference to a figure - // - // Parameters: - // key: String. The name of the figure being referred to. - val fref: Spans.Directive = - Spans.create("fref") { - import Spans.dsl._ - - (attribute(0).as[String]).map { (key) => Text(s"Figure $key") } - } - // - // Insert a reference to a footnote - // - // Parameters: - // key: String. The name of the footnote being referred to. - val fnref: Spans.Directive = - Spans.create("fnref") { - import Spans.dsl._ - - (attribute(0).as[String]).map { (key) => Text(s"Footnote $key") } - } - - val script: Blocks.Directive = - Blocks.create("script") { - import Blocks.dsl._ - - (attribute(0).as[String]).map { (js) => - RawContent(NonEmptySet.one("html"), s"") - } - } - - // @:exercise(title) - // Content - // @:@ - // @:solution - // Solution content - // @:@ - val exercise: Blocks.Directive = - Blocks.create("exercise") { - import Blocks.dsl._ - - (attribute(0).as[String], parsedBody).mapN((title, body) => - BlockSequence( - content = Header(4, "Exercise: " ++ title) +: body, - options = Options(styles = Set("exercise")) - ) - ) - } - - val solution: Blocks.Directive = - Blocks.create("solution") { - import Blocks.dsl._ - - parsedBody.map { body => - BlockSequence( - Seq( - BlockSequence(body).withOptions( - Options(styles = Set("solution-body")) - ) - ), - Options(id = None, styles = Set("solution")) - ) - } - } - - // Insert a reference to a table - // - // Parameters: - // key: String. The name of the figure being referred to. - val tref: Spans.Directive = - Spans.create("tref") { - import Spans.dsl._ - - (attribute(0).as[String]).map { (key) => Text(s"Table $key") } - } - - val compactNavBar: Templates.Directive = - Templates.create("compactNavBar") { - import Templates.dsl._ - - cursor.map { cursor => - val previous = - cursor.flattenedSiblings.previousDocument - .map(c => SpanLink(Seq(Text(leftArrow)), InternalTarget(c.path))) - .getOrElse(Text("")) - val next = cursor.flattenedSiblings.nextDocument - .map(c => SpanLink(Seq(Text(rightArrow)), InternalTarget(c.path))) - .getOrElse(Text("")) - val here = cursor.root.target.title - .map(title => SpanLink(Seq(title), InternalTarget(Path.Root))) - .getOrElse(Text("")) - - TemplateElement( - BlockSequence( - Seq(Paragraph(previous), Paragraph(here), Paragraph(next)) - ) - ) - } - } - - val previousPage: Templates.Directive = - Templates.create("previousPage") { - import Templates.dsl._ - - cursor.map { cursor => - val previous = cursor.flattenedSiblings.previousDocument - - val title = previous.flatMap(c => c.target.title) - val path = previous.map(c => c.path) - - val link = - (title, path).mapN { (t, p) => - SpanLink(Seq(Text(leftArrow), t), InternalTarget(p)) - .withStyle("pageNavigation") - } - - TemplateElement(link.getOrElse(Text(""))) - } - } - - val nextPage: Templates.Directive = - Templates.create("nextPage") { - import Templates.dsl._ - - cursor.map { cursor => - val next = cursor.flattenedSiblings.nextDocument - - val title = next.flatMap(c => c.target.title) - val path = next.map(c => c.path) - - val link = - (title, path).mapN { (t, p) => - SpanLink(Seq(t, Text(rightArrow)), InternalTarget(p)) - .withStyle("pageNavigation") - } - - TemplateElement(link.getOrElse(Text(""))) - } - } - - val spanDirectives = Seq(fref, fnref, tref) - val blockDirectives = - Seq(divWithId, doodle, exercise, figure, footnote, script, solution) - val templateDirectives = Seq(compactNavBar, previousPage, nextPage) - val linkDirectives = Seq() -} diff --git a/project/plugins.sbt b/project/plugins.sbt index 3aa1c755..249887d9 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,6 +1,7 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4") -addSbtPlugin("org.planet42" % "laika-sbt" % "0.19.0") -addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.3") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.13.0") +addSbtPlugin("org.typelevel" % "laika-sbt" % "1.1.0") +addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.4") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0") +addSbtPlugin("org.creativescala" %% "creative-scala-theme" % "0.2.1")