Skip to content

Commit 5ed4ca2

Browse files
authored
Merge pull request #16 from dwickern/mdoc
Fix non-compiling code in docs
2 parents 54234ef + ef8487b commit 5ed4ca2

File tree

4 files changed

+55
-57
lines changed

4 files changed

+55
-57
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
key: ${{ runner.os }}-sbt-${{ hashFiles('**/build.sbt', '**/plugins.sbt') }}
3030

3131
- name: Run tests
32-
run: sbt test
32+
run: sbt test mdoc

README.md

Lines changed: 51 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,85 +14,81 @@ Usage
1414
=====
1515

1616
Add the library as "provided", because it's only needed during compilation and not at runtime:
17-
1817
```sbt
1918
libraryDependencies += "com.github.dwickern" %% "scala-nameof" % "3.0.0" % "provided"
2019
```
2120

22-
Now you can use `nameOf` to get the name of a variable or class member:
23-
```scala
24-
import com.github.dwickern.macros.NameOf._
25-
26-
case class Person(name: String, age: Int)
21+
And import the package:
22+
```scala mdoc
23+
import com.github.dwickern.macros.NameOf._
24+
```
2725

28-
def toMap(person: Person) = Map(
29-
nameOf(person.name) -> person.name,
30-
nameOf(person.age) -> person.age
31-
)
26+
Now you can use `nameOf` to get the name of a variable or class member:
27+
```scala mdoc:nest
28+
case class Person(name: String, age: Int)
3229

33-
// compiles to:
30+
def toMap(person: Person) = Map(
31+
nameOf(person.name) -> person.name,
32+
nameOf(person.age) -> person.age
33+
)
34+
```
35+
```scala mdoc:nest
36+
// compiles to:
3437

35-
def toMap(person: Person) = Map(
36-
"name" -> person.name,
37-
"age" -> person.age
38-
)
38+
def toMap(person: Person) = Map(
39+
"name" -> person.name,
40+
"age" -> person.age
41+
)
3942
```
4043

4144
To get the name of a function:
42-
```scala
43-
import com.github.dwickern.macros.NameOf._
44-
45-
def startCalculation(value: Int): Unit = {
46-
println(s"Entered ${nameOf(startCalculation _)}")
47-
}
48-
49-
// compiles to:
45+
```scala mdoc:nest
46+
def startCalculation(value: Int): Unit = {
47+
println("Entered " + nameOf(startCalculation _))
48+
}
49+
```
50+
```scala mdoc:nest
51+
// compiles to:
5052

51-
def startCalculation(value: Int): Unit = {
52-
println(s"Entered startCalculation")
53-
}
53+
def startCalculation(value: Int): Unit = {
54+
println("Entered startCalculation")
55+
}
5456
```
5557

5658
Without having an instance of the type:
57-
```scala
58-
import com.github.dwickern.macros.NameOf._
59+
```scala mdoc:nest
60+
case class Person(name: String, age: Int) {
61+
def sayHello(other: Person) = s"Hello ${other.name}!"
62+
}
5963

60-
case class Person(name: String, age: Int) {
61-
def sayHello(other: Person) = s"Hello ${other.name}!"
62-
}
63-
64-
println(nameOf[Person](_.age))
65-
66-
// compiles to:
67-
68-
println("age")
64+
println(nameOf[Person](_.age))
65+
println(nameOf[Person](_.sayHello(???)))
66+
```
67+
```scala mdoc:nest
68+
// compiles to:
6969

70-
println(nameOf[Person](_.sayHello(???))
71-
72-
//compiles to:
73-
println("sayHello")
70+
println("age")
71+
println("sayHello")
7472
```
7573

7674
You can also use `nameOfType` to get the unqualified name of a type:
77-
```scala
78-
import com.github.dwickern.macros.NameOf._
79-
80-
println(nameOf[java.lang.String])
81-
82-
// compiles to:
75+
```scala mdoc:nest
76+
println(nameOfType[java.lang.String])
77+
```
78+
```scala mdoc:nest
79+
// compiles to:
8380

84-
println("String")
81+
println("String")
8582
```
8683

8784
And `qualifiedNameOfType` to get the qualified name:
88-
```scala
89-
import com.github.dwickern.macros.NameOf._
90-
91-
println(qualifiedNameOfType[java.lang.String])
92-
93-
// compiles to:
85+
```scala mdoc:nest
86+
println(qualifiedNameOfType[java.lang.String])
87+
```
88+
```scala mdoc:nest
89+
// compiles to:
9490

95-
println("java.lang.String")
91+
println("java.lang.String")
9692
```
9793

9894

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ lazy val scala211 = "2.11.12"
88

99
lazy val root = project.in(file("."))
1010
.aggregate(nameof.projectRefs: _*)
11+
.enablePlugins(MdocPlugin)
1112
.settings(
1213
// for IntelliJ import: pick one project from the matrix to use
1314
nameof.jvm(scala213).settings,
1415
target := baseDirectory.value / "target",
1516
ideSkipProject := false,
16-
compile / skip := true,
1717
publish / skip := true,
18+
mdocIn := baseDirectory.value / "README.md",
1819
)
1920

2021
lazy val nameof = (projectMatrix in file("."))

project/plugins.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.2")
66
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
77
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.7.0")
88
addSbtPlugin("org.jetbrains" % "sbt-ide-settings" % "1.1.0")
9+
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.17" )

0 commit comments

Comments
 (0)