Skip to content

Commit b7c4ba3

Browse files
author
Olafur Pall Geirsson
committed
Add more tests and docs
1 parent 20e71df commit b7c4ba3

File tree

6 files changed

+112
-14
lines changed

6 files changed

+112
-14
lines changed

docs/installation.md

+34-5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ info: Compiling 1 file to website/target/docs
134134
info: Compiled in 1.2s (0 errors)
135135
```
136136

137+
### Add library dependencies to classpath
138+
137139
Add libraries to the launched classpath to include them for compilation.
138140

139141
```diff
@@ -142,14 +144,18 @@ Add libraries to the launched classpath to include them for compilation.
142144
+ org.typelevel:cats-core_@SCALA_BINARY_VERSION@:1.5.0
143145
```
144146

145-
Use `--in` to customize the input directory where markdown sources are
146-
contained, by default the `docs/` directory is used.
147+
### Customize input directory
148+
149+
By default the `docs/` directory is processed as input. Use `--in` to customize
150+
the input directory where markdown sources are contained,
147151

148152
```diff
149153
coursier launch org.scalameta:mdoc_@SCALA_BINARY_VERSION@:@VERSION@ -- \
150154
+ --in mydocs
151155
```
152156

157+
### Process single markdown file
158+
153159
The `--in` flag doesn't have to be a directory, it also supports individual
154160
files.
155161

@@ -158,6 +164,8 @@ files.
158164
+ --in mydocs/readme.md
159165
```
160166

167+
### Configure site variables like `@VERSION@`
168+
161169
Use `--site.VARIABLE=value` to add site variables that can be referenced from
162170
markdown as `@@VARIABLE@`.
163171

@@ -166,6 +174,8 @@ markdown as `@@VARIABLE@`.
166174
+ --site.SCALA_VERSION @SCALA_VERSION@
167175
```
168176

177+
### Customize output directory
178+
169179
Use `--out` to customize where your markdown sources are generated, by default
170180
the `out/` directory is used.
171181

@@ -174,15 +184,34 @@ the `out/` directory is used.
174184
+ --out target/docs
175185
```
176186

177-
The `--out` flag doesn't have to be a directory, it can also be an individual
178-
file. However, this assumes that your `--in` was also an individual file.
187+
### Generate single output file instead of directory
188+
189+
The `--out` flag doesn't have to be a directory when the `--in` argument is a
190+
regular file, it can also be an individual file.
179191

180192
```diff
181193
coursier launch org.scalameta:mdoc_@SCALA_BINARY_VERSION@:@VERSION@ -- \
182-
+ --in mydocs/readme.template.md \
194+
+ --in readme.template.md \
183195
+ --out readme.md
184196
```
185197

198+
### Process multiple input directories and files
199+
200+
Repeat the `--in` and `--out` arguments to process multiple directories and
201+
regular files.
202+
203+
```diff
204+
coursier launch org.scalameta:mdoc_@SCALA_BINARY_VERSION@:@VERSION@ -- \
205+
+ --in readme.template.md \
206+
+ --out readme.md \
207+
+ --in example.template.md \
208+
+ --out example.md \
209+
+ --in mydocs-directory \
210+
+ --out out-directory \
211+
```
212+
213+
### Live reload HTML preview on file save
214+
186215
Use `--watch` to start the file watcher with livereload. It's recommended to use
187216
`--watch` while writing documentation to enjoy 3-4x faster compilation
188217
performance.

mdoc-docs/src/main/scala/mdoc/docs/SbtModifier.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ class SbtModifier extends StringModifier {
3939
</tr>
4040
{rows}
4141
</table>
42-
}.toString()
42+
}.toString() + "\n\n"
4343
}

mdoc/src/main/scala/mdoc/internal/cli/InputFile.scala

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ case class InputFile(
2323
)
2424

2525
object InputFile {
26+
implicit val ordering: Ordering[InputFile] = new Ordering[InputFile] {
27+
def compare(x: InputFile, y: InputFile): Int = {
28+
x.inputFile.toNIO.compareTo(y.inputFile.toNIO)
29+
}
30+
}
31+
2632
def fromSettings(filename: String, settings: Settings): InputFile = {
2733
val relpath = RelativePath(filename)
2834
val inputDir = settings.in.head

mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ final class MainOps(
133133
}
134134

135135
def generateCompleteSite(): Exit = {
136-
val files = IO.inputFiles(settings)
136+
// NOTE(olafur): we sort the input files for reproducible output in cases
137+
// where multiple input files write to the same output file.
138+
val files = IO.inputFiles(settings).sorted
137139
val timer = new Timer()
138140
val n = files.length
139141
compilingFiles(n)

mdoc/src/main/scala/mdoc/internal/cli/Settings.scala

+8-7
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ class Section(val name: String) extends StaticAnnotation
3636
case class Settings(
3737
@Section("Common options")
3838
@Description(
39-
"The input directory containing markdown and other documentation sources " +
40-
"or an individual file that you'd like to target. Markdown files will be " +
41-
"processed by mdoc while other files will be copied verbatim to the output directory."
39+
"The input directory or regular file containing markdown and other documentation sources that should be processed. " +
40+
"Markdown files are processed by mdoc while non-markdown files are copied verbatim to the output directory. " +
41+
"Can be repeated to process multiple input directories/files."
4242
)
4343
@ExtraName("i")
4444
in: List[AbsolutePath],
4545
@Description(
46-
"The output directory where you'd like to generate your markdown or other documentation " +
47-
"sources. This can also be an individual filename, but it then assumes that your `--in` " +
48-
"was also an indiviudal file."
46+
"The output directory or regular where you'd like to generate your markdown or other documentation sources. " +
47+
"Must be repeated to match the number of `--in` arguments and must be a directory when the matching `--in` argument is a directory."
4948
)
5049
@ExtraName("o")
5150
out: List[AbsolutePath],
@@ -303,11 +302,13 @@ object Settings extends MetaconfigScalametaImplicits {
303302
s"mdoc v$displayVersion"
304303
def usage: String =
305304
"""|Usage: mdoc [<option> ...]
306-
|Example: mdoc --in <path> --out <path> (customize input/output directories)
305+
|Example: mdoc --in mydocs --out _site (custom input/output directories)
307306
| mdoc --watch (watch for file changes)
308307
| mdoc --site.VERSION 1.0.0 (pass in site variables)
309308
| mdoc --include **/example.md (process only files named example.md)
310309
| mdoc --exclude node_modules (don't process node_modules directory)
310+
| mdoc --in readme.template.md --out readme.md \
311+
| --in examples.template.md --out examples.md (multiple input/output pairs)
311312
|""".stripMargin
312313
def description: Doc =
313314
Doc.paragraph(

tests/unit/src/test/scala/tests/cli/CliSuite.scala

+60
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,64 @@ class CliSuite extends BaseCliSuite {
291291
extraArgs = Array("--in", "index2.md", "--out", out().resolve("out2.md").toString)
292292
)
293293

294+
checkCli(
295+
"multiple-out-directories",
296+
"""
297+
|/in1/index.md
298+
|```scala mdoc
299+
|println("1 file")
300+
|```
301+
|/in2/index.md
302+
|```scala mdoc
303+
|println("2 file")
304+
|```
305+
|/in3/index.md
306+
|```scala mdoc
307+
|println("3 file")
308+
|```
309+
|""".stripMargin,
310+
"""
311+
|/out1/index.md
312+
|```scala
313+
|println("1 file")
314+
|// 1 file
315+
|```
316+
|/out2/index.md
317+
|```scala
318+
|println("2 file")
319+
|// 2 file
320+
|```
321+
|""".stripMargin,
322+
input = "in1",
323+
output = out().resolve("out1").toString,
324+
extraArgs = Array("--in", "in2", "--out", out().resolve("out2").toString)
325+
)
326+
327+
checkCli(
328+
"conflicting-out",
329+
"""
330+
|/in1/index.md
331+
|```scala mdoc
332+
|println("1 file")
333+
|```
334+
|/in2/index.md
335+
|```scala mdoc
336+
|println("2 file")
337+
|```
338+
|""".stripMargin,
339+
// NOTE(olafur) Last one wins in case of conflict. Feel free to update the
340+
// expected behavior here if we want to error instead. This test is only to
341+
// document that the current behavior even if this behavior is undesirable.
342+
"""
343+
|/out/index.md
344+
|```scala
345+
|println("2 file")
346+
|// 2 file
347+
|```
348+
|""".stripMargin,
349+
input = "in1",
350+
output = out().resolve("out").toString,
351+
extraArgs = Array("--in", "in2", "--out", out().resolve("out").toString)
352+
)
353+
294354
}

0 commit comments

Comments
 (0)