Skip to content

Commit 8a19b72

Browse files
author
Steven Niemitz
authored
Merge pull request #256 from steveniemitz/fix-tut
change tut -> mdoc due to tut deprecation
2 parents e2ba283 + 6262eb6 commit 8a19b72

8 files changed

+49
-20
lines changed

build.sbt

+1-2
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,13 @@ val tutPath = settingKey[String]("Path to tutorials")
106106

107107
lazy val docs = project
108108
.settings(moduleName := "finagle-postgres-docs", buildSettings)
109-
.enablePlugins(GhpagesPlugin, TutPlugin, ScalaUnidocPlugin)
109+
.enablePlugins(GhpagesPlugin, ScalaUnidocPlugin)
110110
.settings(
111111
scaladocVersionPath := ("api/" + version.value),
112112
scaladocLatestPath := (if (isSnapshot.value) "api/latest-snapshot"
113113
else "api/latest"),
114114
tutPath := "doc",
115115
includeFilter in makeSite := (includeFilter in makeSite).value || "*.md" || "*.yml",
116-
addMappingsToSiteDir(tut in Compile, tutPath),
117116
addMappingsToSiteDir(
118117
mappings in (ScalaUnidoc, packageDoc),
119118
scaladocLatestPath

docs/src/main/tut/02-basic-usage.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ Finagle-postgres follows the conventions of the rest of the finagle ecosystem. T
99
the client builder accessed by `com.twitter.finagle.Postgres.Client()`:
1010

1111

12-
```tut:invisible
12+
```scala mdoc:invisible
1313
import com.twitter.util.Await
1414
object dontrun {
1515
```
1616

17-
```tut:book
17+
```scala mdoc
1818
import com.twitter.finagle.Postgres
1919

2020
val client = Postgres.Client()
@@ -27,7 +27,7 @@ val client = Postgres.Client()
2727
.newRichClient("localhost:5432")
2828
```
2929

30-
```tut:invisible
30+
```scala mdoc:invisible
3131

3232
Await.result(client.close())
3333
}

docs/src/main/tut/03-simple-queries.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ could be a vector for SQL injection attacks.
1212

1313
Still, it can be useful to try them out.
1414

15-
```tut:invisible
15+
```scala mdoc:invisible
1616
import com.twitter.finagle.Postgres
1717
import com.twitter.util.Await
1818
// create the client based on environment variables
@@ -29,7 +29,7 @@ val client = {
2929
Await.result(client.execute("DROP TABLE IF EXISTS demo"))
3030
```
3131

32-
```tut:book
32+
```scala mdoc
3333
import com.twitter.util.Await
3434

3535
// execute a query that has no results - i.e. CREATE TABLE, UPDATE, INSERT, DELETE, etc.
@@ -92,6 +92,6 @@ are happy to accept instances for built-in Scala or Java types into finagle-post
9292

9393
Next, read about [Parameterized Queries](04-parameterized-queries.html)
9494

95-
```tut:invisible
95+
```scala mdoc:invisible
9696
Await.result(client.close())
9797
```

docs/src/main/tut/04-parameterized-queries.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ layout: default
88
Since most database-driven applications will need to use user-supplied data as parameters to their queries,
99
finagle-postgres supports parameterized queries through its prepared statement interface:
1010

11-
```tut:invisible
11+
```scala mdoc:invisible
1212
import com.twitter.finagle.Postgres
1313
import com.twitter.util.Await
1414
// create the client based on environment variables
@@ -24,7 +24,7 @@ val client = {
2424
Await.result(client.execute("DROP TABLE IF EXISTS demo"))
2525
```
2626

27-
```tut:book
27+
```scala mdoc
2828
import com.twitter.util.Await
2929

3030
// execute a query that has no results - i.e. CREATE TABLE, UPDATE, INSERT, DELETE, etc.
@@ -50,6 +50,6 @@ query, which means they won't be a potential vector for SQL injection attacks.
5050

5151
Next, read about [Automatic case class marshalling](05-automatic-case-class-marshalling.html)
5252

53-
```tut:invisible
53+
```scala mdoc:invisible
5454
Await.result(client.close())
5555
```

docs/src/main/tut/05-automatic-case-class-marshalling.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function: `Future[Seq[T]]`.
1111

1212
This typically results in a pattern like this:
1313

14-
```tut:invisible
14+
```scala mdoc:invisible
1515
import com.twitter.finagle.Postgres
1616
import com.twitter.util.Await
1717
// create the client based on environment variables
@@ -30,7 +30,7 @@ Await.result(client.prepareAndExecute("CREATE TABLE demo(id serial PRIMARY KEY,
3030
Await.result(client.prepareAndExecute("INSERT INTO demo (foo) VALUES ($1)", "foo"))
3131
```
3232

33-
```tut:book
33+
```scala mdoc
3434
case class Demo(id: Int, foo: String)
3535

3636
val select = client.prepareAndQuery("SELECT * FROM demo") {
@@ -47,7 +47,7 @@ As you can see, this probably gets verbose and repetitive for rows which have a
4747
there must be a better way, and thanks to [shapeless](https://github.com/milessabin/shapeless), there is! Importing
4848
`com.twitter.finagle.postgres.generic._` enriches `client` with an additional operation, `queryAs`:
4949

50-
```tut:book
50+
```scala mdoc
5151
import com.twitter.finagle.postgres.generic._
5252

5353
val result = Await.result {
@@ -61,6 +61,6 @@ to instead do nothing to convert column names.
6161

6262
Next, read about [Query DSL](06-query-dsl.html)
6363

64-
```tut:invisible
64+
```scala mdoc:invisible
6565
Await.result(client.close())
6666
```

docs/src/main/tut/06-query-dsl.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ queries. The DSL lives in the `com.twitter.finagle.postgres.generic._` import.
1111
The abstraction provided is the `Query[T]` data type, which captures a query and its parameters. It's used in conjunction
1212
with the `QueryContext` implicit enrichment, which provides a `sql` String interpolator:
1313

14-
```tut:invisible
14+
```scala mdoc:invisible
1515
import com.twitter.finagle.Postgres
1616
import com.twitter.util.Await
1717
// create the client based on environment variables
@@ -30,7 +30,7 @@ Await.result(client.prepareAndExecute("INSERT INTO demo(foo) VALUES ($1)", "foo"
3030
case class Demo(id: Int, foo: String)
3131
```
3232

33-
```tut:book
33+
```scala mdoc
3434
import com.twitter.finagle.postgres.generic._
3535

3636
def insert(foo: String) = sql"INSERT INTO demo (foo) VALUES ($foo)"
@@ -57,7 +57,7 @@ For other types of values (like single-column results, for example) there is als
5757
from the current type of a query (i.e. `Row` for a freshly created `Query[Row]`) to some other type `T`, and appends the
5858
function to the continuation that will map the rows. For example:
5959

60-
```tut:book
60+
```scala mdoc
6161
def count(input: String) = sql"SELECT count(*) FROM demo WHERE foo = $input".map {
6262
row => row.get[Long]("count")
6363
}
@@ -71,6 +71,6 @@ class` with a `count` column); since there is only one row expected, we also `ma
7171
just the first row using `_.head`.
7272

7373
A more in-depth query DSL is planned, but this is the extent of what's currently offered.
74-
```tut:invisible
74+
```scala mdoc:invisible
7575
Await.result(client.close())
7676
```

project/MdocSitePlugin.scala

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import com.typesafe.sbt.site.SitePlugin.autoImport._
2+
import mdoc.MdocPlugin, MdocPlugin.autoImport._
3+
import sbt._, Keys._
4+
import sbt.plugins.{JvmPlugin, SbtPlugin}
5+
6+
/** Provides glue to integrate mdoc with sbt-site. */
7+
object MdocSitePlugin extends AutoPlugin {
8+
override def trigger = allRequirements
9+
10+
override def requires = JvmPlugin && MdocPlugin
11+
12+
object autoImport {
13+
val mdocSite = taskKey[Seq[(File, String)]]("create mdoc documentation in a way that lets sbt-site grab it")
14+
val mdocSiteOut = settingKey[String]("name of the directory in which sbt-site will store mdoc documentation")
15+
}
16+
17+
import autoImport._
18+
19+
override def projectSettings: Seq[Setting[_]] = Seq(
20+
mdocSite := {
21+
mdoc.toTask(" ").value
22+
val out = mdocOut.value
23+
for {
24+
(file, name) <- out ** AllPassFilter --- out pair Path.relativeTo(out)
25+
} yield file -> name
26+
},
27+
mdocSiteOut := "./",
28+
addMappingsToSiteDir(mdocSite, mdocSiteOut)
29+
)
30+
}

project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolvers ++= Seq(
33
Classpaths.sbtPluginReleases
44
)
55

6-
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.13")
6+
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.21")
77
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.0.15")
88
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.7")
99
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")

0 commit comments

Comments
 (0)