Skip to content

Commit

Permalink
Configure scalafmt for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospereira committed Jul 14, 2019
1 parent f5be1b1 commit 9e4886a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
1 change: 1 addition & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Keep in sync with docs/.scalafmt.conf
align = true
assumeStandardLibraryStripMargin = true
danglingParentheses = true
Expand Down
26 changes: 15 additions & 11 deletions docs/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,34 @@ lazy val docs = project
// use special snapshot play version for now
resolvers ++= DefaultOptions.resolvers(snapshot = true),
resolvers += Resolver.typesafeRepo("releases"),
libraryDependencies += component("play-test") % "test",
libraryDependencies += component("play-test") % "test",
libraryDependencies += component("play-specs2") % "test",
PlayDocsKeys.javaManualSourceDirectories := (baseDirectory.value / "manual" / "working" / "javaGuide" ** "code").get,
PlayDocsKeys.scalaManualSourceDirectories := (baseDirectory.value / "manual" / "working" / "scalaGuide" ** "code").get,
headerLicense := {
val currentYear = java.time.Year.now(java.time.Clock.systemUTC).getValue
Some(HeaderLicense.Custom(
s"Copyright (C) 2009-$currentYear Lightbend Inc. <https://www.lightbend.com>"
))
Some(
HeaderLicense.Custom(
s"Copyright (C) 2009-$currentYear Lightbend Inc. <https://www.lightbend.com>"
)
)
},
headerEmptyLine := false
).settings(overrideTwirlSettings: _*)
)
.settings(overrideTwirlSettings: _*)
.dependsOn(twirlApi)

// The changes in Twirl imports cause a problem with the PlayDocsPlugin, which defines its own twirl compile tasks
// and doesn't use the default imports provided by Twirl but defines its own by scratch, and since the defaults
// have changed, this breaks. So, first we need to set all source generators in test to Nil, then we can redefine the
// twirl settings.
def overrideTwirlSettings: Seq[Setting[_]] = Seq(
sourceGenerators in Test := Nil
) ++ inConfig(Test)(SbtTwirl.twirlSettings) ++ SbtTwirl.defaultSettings ++ SbtTwirl.positionSettings ++ Seq(
sourceDirectories in (Test, TwirlKeys.compileTemplates) ++=
(PlayDocsKeys.javaManualSourceDirectories.value ++ PlayDocsKeys.scalaManualSourceDirectories.value)
)
def overrideTwirlSettings: Seq[Setting[_]] =
Seq(
sourceGenerators in Test := Nil
) ++ inConfig(Test)(SbtTwirl.twirlSettings) ++ SbtTwirl.defaultSettings ++ SbtTwirl.positionSettings ++ Seq(
sourceDirectories in (Test, TwirlKeys.compileTemplates) ++=
(PlayDocsKeys.javaManualSourceDirectories.value ++ PlayDocsKeys.scalaManualSourceDirectories.value)
)

// the twirl plugin automatically adds this dependency, but this overrides it so
// it can be an interproject dependency, rather than requiring it to be published
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ package html.utils {
object ScalaTemplatesSpec extends Specification {

val customer = Customer("mr customer")
val orders = List(Order("foo"), Order("bar"))

val orders = List(Order("foo"), Order("bar"))

"Scala templates" should {
"support an example template" in {
Expand All @@ -57,7 +56,7 @@ object ScalaTemplatesSpec extends Specification {
import play.twirl.api.StringInterpolation

val name = "Martin"
val p = html"<p>Hello $name</p>"
val p = html"<p>Hello $name</p>"
//#string-interpolation

p.body must_== "<p>Hello Martin</p>"
Expand Down Expand Up @@ -100,13 +99,17 @@ object ScalaTemplatesSpec extends Specification {
"allow comments on the first line" in {
val body = html.firstLineComment("blah").body
body must contain("blah")
body must not contain("Home page")
body must not contain ("Home page")
}

{
val body = html.snippets(Seq(Product("p1", "1"), Product("p2", "2")), User("John", "Doe"), Article("<foo>")).body
def segment(name: String) = {
body.linesIterator.dropWhile(_ != "<span class=\"" + name + "\">").drop(1).takeWhile(_ != "</span>").mkString("\n")
body.linesIterator
.dropWhile(_ != "<span class=\"" + name + "\">")
.drop(1)
.takeWhile(_ != "</span>")
.mkString("\n")
}

"allow escaping the @ character" in {
Expand Down Expand Up @@ -140,7 +143,7 @@ object ScalaTemplatesSpec extends Specification {
}

"allow comments" in {
body must not contain("This is a comment")
body must not contain ("This is a comment")
}

"allow intering raw HTML" in {
Expand All @@ -153,10 +156,10 @@ object ScalaTemplatesSpec extends Specification {

body must contain("User(Foo,Bar)")
body must contain("value inside option")
body must not contain("Option(value inside option)")
body must not contain ("Option(value inside option)")
body must contain("firstlast")
body must not contain("List")
body must not contain ("List")
body must contain("helloUser(Foo,Bar)value inside optionfirstlast")
}
}
}
}
4 changes: 2 additions & 2 deletions docs/project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ lazy val sbtTwirl = ProjectRef(Path.fileProperty("user.dir").getParentFile, "plu
resolvers ++= DefaultOptions.resolvers(snapshot = true)

addSbtPlugin("com.typesafe.play" % "play-docs-sbt-plugin" % sys.props.getOrElse("play.version", "2.8.0-M3"))

addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0")

0 comments on commit 9e4886a

Please sign in to comment.