Skip to content

Commit

Permalink
Separate html and theme output per configuration (#312)
Browse files Browse the repository at this point in the history
Separate html and theme output per configuration
  • Loading branch information
2m authored May 22, 2019
2 parents 1e99bfa + 09efac0 commit d6004ce
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 15 deletions.
14 changes: 8 additions & 6 deletions docs/src/main/paradox/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ If a file duplicate exist between the directories, the overlay file is dropped i

## Multi Configuration

Paradox supports multiple sbt configurations. Each configuration is by default located to `src/configName` of the project,
with the target directory defined as `target/paradox/site/configName`, `configName` corresponding to configuration.name of
a particular configuration. There still remains the usual main project in `src/main` of course if you don't need multiple
paradox project directories.
By default, Paradox expects documentation source files in the `src/main/paradox` directory.
For situations where different parts of the documentation are stored separately, Paradox supports custom sbt configuration scopes.
Each custom configuration source files are by default located in the `src/<config-name>/paradox` directory.
The target directory is defined as `target/paradox/site/<config-name>`.
Here `<config-name>` corresponds to `configuration.name` of a particular configuration.

To associate a configuration to paradox, use its settings, and change its default source and/or target directorie(s) if needed:
To associate a configuration to paradox, manually add settings from `ParadoxPlugin.paradoxSettings`, and change its default source and/or target directories if needed:

```scala
val SomeConfig = config("some-config")
Expand All @@ -49,7 +50,8 @@ lazy val root = (project in file(".")).
)
```

Now, either you run paradox on one configuration; "sbt someConfig:paradox" or you can run the main project with the usual way; "sbt paradox".
Now, to run paradox for custom configuration execute `sbt someConfig:paradox`.
It is still possible to run paradox for the main configuration the usual way `sbt paradox`.

## Version warning

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ object ParadoxPlugin extends AutoPlugin {
excludeFilter in paradoxMarkdownToHtml := HiddenFileFilter,
sources in paradoxMarkdownToHtml := Defaults.collectFiles(sourceDirectories in paradox, includeFilter in paradoxMarkdownToHtml, excludeFilter in paradoxMarkdownToHtml).value,
mappings in paradoxMarkdownToHtml := Defaults.relativeMappings(sources in paradoxMarkdownToHtml, sourceDirectories in paradox).value,
target in paradoxMarkdownToHtml := target.value / "paradox" / "html",
target in paradoxMarkdownToHtml := target.value / "paradox" / "html" / configTarget(configuration.value),

managedSourceDirectories in paradoxTheme := paradoxTheme.value.toSeq.map { theme =>
(WebKeys.webJarsDirectory in Assets).value / (WebKeys.webModulesLib in Assets).value / theme.name
Expand All @@ -130,7 +130,7 @@ object ParadoxPlugin extends AutoPlugin {
// if there are duplicates, select the file from the local template to allow overrides/extensions in themes
WebKeys.deduplicators in paradoxTheme += SbtWeb.selectFileFrom((sourceDirectory in paradoxTheme).value),
mappings in paradoxTheme := SbtWeb.deduplicateMappings((mappings in paradoxTheme).value, (WebKeys.deduplicators in paradoxTheme).value),
target in paradoxTheme := target.value / "paradox" / "theme",
target in paradoxTheme := target.value / "paradox" / "theme" / configTarget(configuration.value),
paradoxThemeDirectory := SbtWeb.syncMappings(WCompat.cacheStore(streams.value, "paradox-theme"), (mappings in paradoxTheme).value, (target in paradoxTheme).value),

paradoxTemplate := {
Expand Down Expand Up @@ -185,13 +185,7 @@ object ParadoxPlugin extends AutoPlugin {
val themeFilter = (managedSourceDirectories in paradoxTheme).value.headOption.map(InDirectoryFilter).getOrElse(NothingFilter)
(mappings in Assets).value filterNot { case (file, path) => themeFilter.accept(file) }
},
target in paradox := {
val config = configuration.value
if (config.name != Compile.name)
target.value / "paradox" / "site" / config.name
else
target.value / "paradox" / "site" / "main"
},
target in paradox := target.value / "paradox" / "site" / configTarget(configuration.value),

watchSources in Defaults.ConfigGlobal ++= Compat.sourcesFor((sourceDirectories in paradox).value),

Expand All @@ -200,6 +194,10 @@ object ParadoxPlugin extends AutoPlugin {
paradox := SbtWeb.syncMappings(WCompat.cacheStore(streams.value, "paradox"), (mappings in paradox).value, (target in paradox).value)
)

private def configTarget(config: Configuration) =
if (config.name == Compile.name) "main"
else config.name

def shortVersion(version: String): String = version.replace("-SNAPSHOT", "*")

def dateProperties: Map[String, String] = {
Expand Down
23 changes: 23 additions & 0 deletions plugin/src/sbt-test/paradox/custom-configuration/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
val Docs1 = config("docs1")
val Docs2 = config("docs2")

enablePlugins(ParadoxPlugin)

ParadoxPlugin.paradoxSettings(Docs1)
ParadoxPlugin.paradoxSettings(Docs2)

TaskKey[Unit]("makeDocs") := {
(Docs1 / paradox).value
(Docs2 / paradox).value
}

TaskKey[Unit]("check") := {
def checkFileContent(file: File, expected: String) = {
assert(file.exists, s"${file.getAbsolutePath} does not exists")
val contents = IO.readLines(file)
assert(contents.exists(_.contains(expected)), s"Did not find '$expected' in\n${contents.mkString("\n")}")
}

checkFileContent((Docs1 / paradox / target).value / "index.html", "Docs1 index")
checkFileContent((Docs2 / paradox / target).value / "index.html", "Docs2 index")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.2.8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % sys.props("project.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Docs1 index.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Docs2 index.
2 changes: 2 additions & 0 deletions plugin/src/sbt-test/paradox/custom-configuration/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> makeDocs
> check

0 comments on commit d6004ce

Please sign in to comment.