All Downloads are FREE. Search and download functionalities are using the official Maven repository.

indigoplugin.generators.EmbedText.scala Maven / Gradle / Ivy

The newest version!
package indigoplugin.generators

object EmbedText {

  def generate(
      moduleName: String,
      fullyQualifiedPackage: String,
      filePath: os.Path
  ): os.Path => Seq[os.Path] = outDir => {

    val text =
      if (!os.exists(filePath)) throw new Exception("Text file to embed not found: " + filePath.toString())
      else {
        os.read(filePath)
      }

    val wd = outDir / Generators.OutputDirName

    os.makeDir.all(wd)

    val file = wd / s"$moduleName.scala"

    val contents =
      s"""package $fullyQualifiedPackage
      |
      |// DO NOT EDIT: Generated by Indigo.
      |object $moduleName:
      |
      |  val text: String =
      |    ${Generators.TripleQuotes}$text${Generators.TripleQuotes}
      |""".stripMargin

    os.write.over(file, contents)

    Seq(file)
  }

  def generate(
      moduleName: String,
      fullyQualifiedPackage: String,
      filePath: os.Path,
      present: String => String
  ): os.Path => Seq[os.Path] = outDir => {

    val text =
      if (!os.exists(filePath)) throw new Exception("Text file to embed not found: " + filePath.toString())
      else {
        os.read(filePath)
      }

    val wd = outDir / Generators.OutputDirName

    os.makeDir.all(wd)

    val file = wd / s"$moduleName.scala"

    val contents =
      s"""package $fullyQualifiedPackage
      |
      |// DO NOT EDIT: Generated by Indigo.
      |
      |${present(text)}
      |""".stripMargin

    os.write.over(file, contents)

    Seq(file)
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy