diff --git a/CHANGELOG.md b/CHANGELOG.md index e8818cd..aca5dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.4.0 + +Replace Laika with a generic `String => String` transformations. + ## 0.3.1 Removed a bad println. diff --git a/README.md b/README.md index 1855381..895086e 100644 --- a/README.md +++ b/README.md @@ -171,20 +171,12 @@ object EmbeddedFilesIndex { } ``` -## Laika transform (markdown) +## Transforming text -It is possible to configure a basic transformation for text files using [Laika](https://planet42.github.io/Laika). +It is possible to configure a basic transformation for text files using. ```scala -import laika.api.Transformer -import laika.ast.Path.Root -import laika.format.{AST, HTML, Markdown, ReStructuredText, XSLFO} -import laika.markdown.bundle.VerbatimHTML -import laika.markdown.github.GitHubFlavor -import laika.parse.code.SyntaxHighlighting -import laika.rewrite.link.LinkConfig - project // ... .settings( @@ -193,20 +185,14 @@ project embedTransform := Seq( TransformConfig( when = _.getFileName.toString.endsWith(".md"), - transformer = - Transformer - .from(Markdown) - .to(HTML) - .using(GitHubFlavor, VerbatimHTML, SyntaxHighlighting) - .withConfigValue(LinkConfig(excludeFromValidation = Seq(Root))) - .build + transform = _.toUpperCase ) ), (Compile / sourceGenerators) += embedFiles ) ``` -For each text file, the `.transformer` of the first of the `TransformConfig`-s to match the path (`.when` returns `true`) +For each text file, the `.transform` function of the first of the `TransformConfig`-s to match the path (`.when` returns `true`) will be applied to the contents of the file. If none of the configuration matches - the file contents will be used as is. diff --git a/build.sbt b/build.sbt index 0973a19..f8e023b 100644 --- a/build.sbt +++ b/build.sbt @@ -27,8 +27,4 @@ console / initialCommands := """import com.yurique.embedded.sbt._""" enablePlugins(ScriptedPlugin) scriptedLaunchOpts ++= Seq("-Xmx1024M", "-Dplugin.version=" + version.value) -libraryDependencies ++= Seq( - "org.planet42" %% "laika-core" % "0.19.0", // % Provided, - "org.planet42" %% "laika-core" % "0.19.0" % Test -) // test := scripted.value diff --git a/src/main/scala/com/yurique/embedded/sbt/EmbeddedFilesPlugin.scala b/src/main/scala/com/yurique/embedded/sbt/EmbeddedFilesPlugin.scala index 01b09e4..eeb21ad 100644 --- a/src/main/scala/com/yurique/embedded/sbt/EmbeddedFilesPlugin.scala +++ b/src/main/scala/com/yurique/embedded/sbt/EmbeddedFilesPlugin.scala @@ -6,7 +6,6 @@ import sbt.Keys._ import java.nio.file.Files import java.nio.file.Path import sbt.nio.Keys._ -import laika.api.Transformer object EmbeddedFilesPlugin extends AutoPlugin { @@ -16,7 +15,7 @@ object EmbeddedFilesPlugin extends AutoPlugin { case class TransformConfig( when: Path => Boolean, - transformer: Transformer + transform: String => String ) val embedFiles = taskKey[Seq[File]]("Creates an ExternalFile object with a content field for each file.") @@ -209,9 +208,7 @@ object EmbeddedFilesPlugin extends AutoPlugin { ): Unit = { def doTransform(s: String): String = - transform.find(_.when(input)).fold(s) { transform => - transform.transformer.transform(s).fold(throw _, identity) - } + transform.find(_.when(input)).fold(s)(_.transform(s)) val fileContent = doTransform(IO.read(input.toFile)) diff --git a/src/sbt-test/sbt-embedded-files/without-index-transform/build.sbt b/src/sbt-test/sbt-embedded-files/without-index-transform/build.sbt index bd4b3f7..e21c99a 100644 --- a/src/sbt-test/sbt-embedded-files/without-index-transform/build.sbt +++ b/src/sbt-test/sbt-embedded-files/without-index-transform/build.sbt @@ -1,12 +1,3 @@ -import laika.api.Transformer -import laika.ast.Path.Root -import laika.format.{AST, HTML, Markdown, ReStructuredText, XSLFO} -import laika.markdown.bundle.VerbatimHTML -import laika.markdown.github.GitHubFlavor -import laika.parse.code.SyntaxHighlighting -import laika.rewrite.link.LinkConfig - - version := "0.1" scalaVersion := "2.13.6" @@ -19,8 +10,8 @@ val root = project embedDirectories ++= (Compile / unmanagedSourceDirectories).value, embedTransform := Seq( TransformConfig( - when = _.getFileName.toString.endsWith(".md"), - transformer = Transformer.from(Markdown).to(HTML).using(GitHubFlavor, VerbatimHTML, SyntaxHighlighting).build + when = _.getFileName.toString.endsWith("test-resource.txt"), + transform = _.toUpperCase ) ), (Compile / sourceGenerators) += embedFiles diff --git a/src/sbt-test/sbt-embedded-files/without-index-transform/expected/__embedded_files/test_resource_md.scala b/src/sbt-test/sbt-embedded-files/without-index-transform/expected/__embedded_files/test_resource_md.scala deleted file mode 100644 index f044c22..0000000 --- a/src/sbt-test/sbt-embedded-files/without-index-transform/expected/__embedded_files/test_resource_md.scala +++ /dev/null @@ -1,11 +0,0 @@ -package __embedded_files - -object test_resource_md extends __embedded_files.EmbeddedTextFile { - - val path: String = """test-resource.md""" - - val content: String = """ -

I'm markdown

-

I'm a link

""" - -} diff --git a/src/sbt-test/sbt-embedded-files/without-index-transform/expected/__embedded_files/test_resource_txt.scala b/src/sbt-test/sbt-embedded-files/without-index-transform/expected/__embedded_files/test_resource_txt.scala index 5823216..5a67556 100644 --- a/src/sbt-test/sbt-embedded-files/without-index-transform/expected/__embedded_files/test_resource_txt.scala +++ b/src/sbt-test/sbt-embedded-files/without-index-transform/expected/__embedded_files/test_resource_txt.scala @@ -4,7 +4,7 @@ object test_resource_txt extends __embedded_files.EmbeddedTextFile { val path: String = """test-resource.txt""" - val content: String = """A file from resources. + val content: String = """A FILE FROM RESOURCES. """ } diff --git a/src/sbt-test/sbt-embedded-files/without-index-transform/src/main/resources/test-resource.md b/src/sbt-test/sbt-embedded-files/without-index-transform/src/main/resources/test-resource.md deleted file mode 100644 index b2a256a..0000000 --- a/src/sbt-test/sbt-embedded-files/without-index-transform/src/main/resources/test-resource.md +++ /dev/null @@ -1,3 +0,0 @@ -### I'm markdown - -[I'm a link](https://site.nowhere/) diff --git a/src/sbt-test/sbt-embedded-files/without-index-transform/test b/src/sbt-test/sbt-embedded-files/without-index-transform/test index f74a8f9..16eea93 100644 --- a/src/sbt-test/sbt-embedded-files/without-index-transform/test +++ b/src/sbt-test/sbt-embedded-files/without-index-transform/test @@ -2,7 +2,6 @@ > compile $ must-mirror target/scala-2.13/src_managed/main/scala/__embedded_files/com/yurique/embedded/sbt/txt/test_file_1_txt.scala expected/__embedded_files/com/yurique/embedded/sbt/txt/test_file_1_txt.scala $ must-mirror target/scala-2.13/src_managed/main/scala/__embedded_files/test_resource_txt.scala expected/__embedded_files/test_resource_txt.scala -$ must-mirror target/scala-2.13/src_managed/main/scala/__embedded_files/test_resource_md.scala expected/__embedded_files/test_resource_md.scala $ must-mirror target/scala-2.13/src_managed/main/scala/__embedded_files/com/yurique/embedded/sbt/binary/test_bin_file_1_bin.scala expected/__embedded_files/com/yurique/embedded/sbt/binary/test_bin_file_1_bin.scala $ must-mirror target/scala-2.13/src_managed/main/scala/__embedded_files/test/test_bin_resource_bin.scala expected/__embedded_files/test/test_bin_resource_bin.scala $ must-mirror target/scala-2.13/src_managed/main/scala/__embedded_files/EmbeddedTextFile.scala expected/__embedded_files/EmbeddedTextFile.scala