Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Make tutOnly autocomplete parser public #99

Merged
merged 1 commit into from
Mar 17, 2016

Conversation

adelbertc
Copy link
Contributor

I've found myself wanting this when defining SBT processes around slide generation.

I also have no clue what I'm doing with SBT so I hope someone with more knowledge than I yells at me if I did something wrong. This seemed to work when I did a publishLocal and toyed around with it in another project..

@adelbertc
Copy link
Contributor Author

For the record from the use site I'm doing something like:

val parser = Def.setting((state: State) => tutFiles.value(state))

val  blah = inputKey[Unit]("...")
blah := {
  val file = parser.parsed
  println(file)
}

@tpolecat
Copy link
Owner

👍

tpolecat added a commit that referenced this pull request Mar 17, 2016
Make tutOnly autocomplete parser public
@tpolecat tpolecat merged commit cde9fd1 into tpolecat:master Mar 17, 2016
@adelbertc
Copy link
Contributor Author

As an example, I used this to work with pandoc/reveal.js like so:

def checkExtension(extensions: Set[String])(file: File): Boolean =
  extensions.exists(s => file.getName.endsWith(s))

def replaceExtension(file: File, ext: String): File =
  new File(file.getAbsolutePath.replaceAll("\\.[^.]*$", "") + ext)

val markdownOnly = checkExtension(Set(".md", ".markdown")) _

def runRevealJs(file: File): Unit = {
  val outputFile = replaceExtension(file, ".html")
  val theme = List(
    ("controls", "false"),
    ("progress", "false"),
    ("theme", "white"),
    ("transition", "none")
  )
  val themeConfigString = theme.map { case (k, v) => s"-V ${k}:${v}"}.mkString(" ")
  Process(s"pandoc -t revealjs -s ${file.getAbsolutePath} --self-contained -o ${outputFile.getAbsolutePath} ${themeConfigString}").!
}

val parser = Def.setting { (state: State) =>
  tutFiles.value(state).filter(markdownOnly, identity)
}

def tutWith(file: File): Def.Initialize[Task[File]] = Def.taskDyn {
  val filename = file.getName
  tutOnly.toTask(s" ${filename}").map(_ => tutTargetDirectory.value / filename)
}

val revealJs = inputKey[Unit]("revealjs . tut")
revealJs := Def.inputTaskDyn {
  val file = parser.parsed
  tutWith(file)(_.map { tutFile =>
    runRevealJs(tutFile)
    ()
  })
}.evaluated

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants