Skip to content

Commit

Permalink
Merge pull request #52 from olafurpg/mdoc
Browse files Browse the repository at this point in the history
Rename project to mdoc
  • Loading branch information
olafurpg committed Aug 21, 2018
2 parents 9fc4263 + 14e44aa commit cacddcd
Show file tree
Hide file tree
Showing 68 changed files with 368 additions and 368 deletions.
20 changes: 10 additions & 10 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inThisBuild(
licenses := Seq(
"Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")
),
homepage := Some(url("https://github.com/olafurpg/vork")),
homepage := Some(url("https://github.com/olafurpg/mdoc")),
developers := List(
Developer(
"jvican",
Expand All @@ -23,7 +23,7 @@ inThisBuild(
)
)

name := "vorkRoot"
name := "mdocRoot"
skip in publish := true
val V = new {
val scalameta = "4.0.0-M8"
Expand All @@ -32,19 +32,19 @@ val V = new {

lazy val runtime = project
.settings(
moduleName := "vork-runtime",
moduleName := "mdoc-runtime",
libraryDependencies ++= List(
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"com.lihaoyi" %% "pprint" % "0.5.2"
)
)

lazy val vork = project
lazy val mdoc = project
.settings(
moduleName := "vork",
moduleName := "mdoc",
crossVersion := CrossVersion.full,
mainClass in assembly := Some("vork.Main"),
assemblyJarName in assembly := "vork.jar",
mainClass in assembly := Some("mdoc.Main"),
assemblyJarName in assembly := "mdoc.jar",
test in assembly := {},
assemblyMergeStrategy.in(assembly) ~= { old =>
{
Expand All @@ -53,7 +53,7 @@ lazy val vork = project
}
},
fork in run := true,
buildInfoPackage := "vork.internal",
buildInfoPackage := "mdoc.internal",
buildInfoKeys := Seq[BuildInfoKey](
version,
"stableVersion" -> "0.3.1"
Expand Down Expand Up @@ -95,7 +95,7 @@ lazy val unit = project
"testsInputClassDirectory" -> classDirectory.in(testsInput, Compile).value
)
)
.dependsOn(vork, testsInput)
.dependsOn(mdoc, testsInput)
.enablePlugins(BuildInfoPlugin)

lazy val website = project
Expand All @@ -106,4 +106,4 @@ lazy val website = project
watchSources += baseDirectory.in(ThisBuild).value / "docs",
cancelable in Global := true
)
.dependsOn(vork)
.dependsOn(mdoc)
98 changes: 49 additions & 49 deletions docs/readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Vork: markdown worksheets
# Mdoc: compiled markdown documentation

[![Build Status](https://travis-ci.org/olafurpg/vork.svg?branch=master)](https://travis-ci.org/olafurpg/vork)
[![Build Status](https://travis-ci.org/olafurpg/mdoc.svg?branch=master)](https://travis-ci.org/olafurpg/mdoc)

Vork is a documentation tool for Scala inspired by
[tut](http://tpolecat.github.io/tut/). Like tut, Vork interprets Scala code
Mdoc is a documentation tool for Scala inspired by
[tut](http://tpolecat.github.io/tut/). Like tut, mdoc interprets Scala code
examples in markdown files allowing you to compile markdown documentation as
part of your build. Distinguishing features of Vork include:
part of your build. Distinguishing features of mdoc include:

- [good performance](#performance): incremental, hot compilation gives you
snappy feedback while writing documentation.
Expand Down Expand Up @@ -61,7 +61,7 @@ To install my project
libraryDependencies += "com" % "lib" % "@@MY_VERSION@"
```
```scala vork
```scala mdoc
val x = 1
List(x, x)
```
Expand All @@ -88,30 +88,30 @@ List(x, x)
````

Observe that `MY_VERSION` has been replaced with `1.0.0` and that the
`scala vork` code fence has been interpreted by the Scala compiler.
`scala mdoc` code fence has been interpreted by the Scala compiler.

### Library

Add the following dependency to your build

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.geirsson/vork_2.12.6/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.geirsson/vork_2.12.6)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.geirsson/mdoc_2.12.6/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.geirsson/mdoc_2.12.6)

```scala
// build.sbt
libraryDependencies += "com.geirsson" % "vork" % "@VERSION@" cross CrossVersion.full
libraryDependencies += "com.geirsson" % "mdoc" % "@VERSION@" cross CrossVersion.full
```

Then write a main function that invokes Vork as a library
Then write a main function that invokes mdoc as a library

```scala
object Main {
def main(args: Array[String]): Unit = {
// build arguments for Vork
val settings = vork.MainSettings()
// build arguments for mdoc
val settings = mdoc.MainSettings()
.withSiteVariables(Map("MY_VERSION" -> "1.0.0"))
.withArgs(args.toList)
// generate out/readme.md from working directory
val exitCode = vork.Main.process(settings)
val exitCode = mdoc.Main.process(settings)
// (optional) exit the main function with exit code 0 (success) or 1 (error)
sys.exit(exitCode)
}
Expand All @@ -120,10 +120,10 @@ object Main {

Consult [--help](#--help) to see what arguments are valid for `withArgs`.

Consult the Vork source to learn more how to use the library API. Scaladocs are
available [here](https://www.javadoc.io/doc/com.geirsson/vork_2.12.6/@VERSION@)
Consult the mdoc source to learn more how to use the library API. Scaladocs are
available [here](https://www.javadoc.io/doc/com.geirsson/mdoc_2.12.6/@VERSION@)
but beware there are limited docstrings for classes and methods. Keep in mind
that code in the package `vork.internal` is subject to binary and source
that code in the package `mdoc.internal` is subject to binary and source
breaking changes between any release, including PATCH versions.

### Command-line
Expand All @@ -132,10 +132,10 @@ First, install the
[coursier command-line interface](https://github.com/coursier/coursier/#command-line).
Then run the following command:

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.geirsson/vork_2.12.6/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.geirsson/vork_2.12.6)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.geirsson/mdoc_2.12.6/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.geirsson/mdoc_2.12.6)

```
$ coursier launch com.geirsson:vork_2.12.6:@VERSION@ -- --site.MY_VERSION 1.0.0
$ coursier launch com.geirsson:mdoc_2.12.6:@VERSION@ -- --site.MY_VERSION 1.0.0
info: Compiling docs/readme.md
info: done => out/readme.md (120 ms)
```
Expand All @@ -147,14 +147,14 @@ Consult [`--help`](#--help) to learn more about the command-line interface.

## Modifiers

Vorks supports several modifiers to control the output of code fences.
Mdocs supports several modifiers to control the output of code fences.

### Default

The default modifier compiles and executes the code fence as normal

````scala vork:vork
```scala vork
````scala mdoc:mdoc
```scala mdoc
val x = 1
val y = 2
x + y
Expand All @@ -165,8 +165,8 @@ x + y

The `fail` modifier asserts that the code block will not compile

````scala vork:vork
```scala vork:fail
````scala mdoc:mdoc
```scala mdoc:fail
val x: Int = ""
```
````
Expand All @@ -178,8 +178,8 @@ runtime. To assert runtime exceptions, use the `crash` modifier.

The `crash` modifier asserts that the code block throws an exception at runtime

````scala vork:vork
```scala vork:crash
````scala mdoc:mdoc
```scala mdoc:crash
val y = ???
```
````
Expand All @@ -189,8 +189,8 @@ val y = ???
The `passthrough` modifier collects the stdout and stderr output from the
program and embeds it verbatim in the markdown file.

````scala vork:vork
```scala vork:passthrough
````scala mdoc:mdoc
```scala mdoc:passthrough
val matrix = Array.tabulate(4, 4) { (a, b) =>
val multiplied = (a + 1) * (b + 1)
f"$multiplied%2s"
Expand All @@ -213,57 +213,57 @@ $table

### Performance

Vork is designed to provide a tight edit/render/preview feedback loop while
writing documentation. Vork achieves good performance through
Mdoc is designed to provide a tight edit/render/preview feedback loop while
writing documentation. Mdoc achieves good performance through

- [script semantics](#script-semantics): each markdown file compiles into a
single Scala program that executes in one run.
- being incremental: with `--watch`, Vork compiles individual files as they
- being incremental: with `--watch`, mdoc compiles individual files as they
change avoiding unnecessary work re-generating the full site.
- keeping the compiler hot: with `--watch`, Vork re-uses the same Scala compiler
- keeping the compiler hot: with `--watch`, mdoc re-uses the same Scala compiler
instance for subsequent runs making compilation faster after a few iterations.
A medium sized document can go from compiling in ~5 seconds with a cold
compiler down to 500ms with a hot compiler.

### Good error messages

Vork tries to report helpful error messages when things go wrong. Here below,
Mdoc tries to report helpful error messages when things go wrong. Here below,
the program that is supposed to compile successfully but it has a type error so
the build is stopped with an error message from the Scala compiler.

````scala vork:vork:crash
```scala vork
````scala mdoc:mdoc:crash
```scala mdoc
val typeError: Int = "should be int"
```
````

Here below, the programs are supposed to fail due to the `fail` and `crash`
modifiers but they succeed so the build is stopped with an error message from
Vork.
mdoc.

````scala vork:vork:crash
```scala vork:fail
````scala mdoc:mdoc:crash
```scala mdoc:fail
val noFail = "success"
```
```scala vork:crash
```scala mdoc:crash
val noCrash = "success"
```
````

Observe that positions of the reported diagnostics point to line numbers and
columns in the original markdown document. Internally, Vork instruments code
columns in the original markdown document. Internally, mdoc instruments code
fences to extract metadata like variable types and runtime values. Positions of
error messages in the instrumented code are translated into positions in the
markdown document.

### Link hygiene

Docs get quickly out date, in particular links to different sections. After
generating a site, Vork analyzes links for references to non-existent sections.
For the example below, Vork reports a warning that the `doesnotexist` link is
generating a site, mdoc analyzes links for references to non-existent sections.
For the example below, mdoc reports a warning that the `doesnotexist` link is
invalid.

```scala vork:vork:crash
```scala mdoc:mdoc:crash
# My title

Link to [my title](#my-title).
Expand All @@ -272,16 +272,16 @@ Link to [old section](#doesnotexist).

### Script semantics

Vork interprets code fences as normal Scala programs instead of as if they're
Mdoc interprets code fences as normal Scala programs instead of as if they're
evaluated in the REPL. This behavior is different from tut that interprets
statements as if they were typed in a REPL session. Using "script semantics"
instead of "repl semantics" has both benefits and downsides.

**Downside**: It's not possible to bind the same variable twice, for example the
code below input fails compilation with Vork but compiles successfully with tut
code below input fails compilation with mdoc but compiles successfully with tut

````
```scala vork
```scala mdoc
val x = 1
val x = 1
```
Expand All @@ -292,8 +292,8 @@ compile.

**Upside**: Companion objects Just Work™️

````scala vork:vork
```scala vork
````scala mdoc:mdoc
```scala mdoc
case class User(name: String)
object User {
implicit val ordering: Ordering[User] = Ordering.by(_.name)
Expand All @@ -313,8 +313,8 @@ Contributions are welcome!

## --help

````scala vork:passthrough
````scala mdoc:passthrough
println("```")
println(vork.internal.cli.Settings.help.helpMessage(80))
println(mdoc.internal.cli.Settings.help.helpMessage(80))
println("```")
````
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package vork
package mdoc

import java.io.PrintStream
import java.nio.file.Path
import metaconfig.Configured
import scala.meta.internal.io.PathIO
import scala.meta.io.AbsolutePath
import vork.internal.cli.MainOps
import vork.internal.cli.Settings
import vork.internal.io.ConsoleReporter
import vork.internal.markdown.Markdown
import mdoc.internal.cli.MainOps
import mdoc.internal.cli.Settings
import mdoc.internal.io.ConsoleReporter
import mdoc.internal.markdown.Markdown

object Main {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vork
package mdoc

import java.io.InputStream
import java.nio.charset.Charset
Expand All @@ -8,12 +8,12 @@ import metaconfig.Conf
import metaconfig.Configured
import scala.meta.internal.io.PathIO
import scala.meta.io.AbsolutePath
import vork.internal.cli.Settings
import vork.internal.io.ConsoleReporter
import mdoc.internal.cli.Settings
import mdoc.internal.io.ConsoleReporter

final class MainSettings private (
private[vork] val settings: Settings,
private[vork] val reporter: Reporter
private[mdoc] val settings: Settings,
private[mdoc] val reporter: Reporter
) {
def withArgs(args: List[String]): MainSettings = {
if (args.isEmpty) this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vork
package mdoc

import scala.meta.inputs.Position

Expand All @@ -14,7 +14,7 @@ trait Reporter {
def print(msg: String): Unit
def println(msg: String): Unit

private[vork] def hasWarnings: Boolean
private[vork] def hasErrors: Boolean
private[vork] def reset(): Unit
private[mdoc] def hasWarnings: Boolean
private[mdoc] def hasErrors: Boolean
private[mdoc] def reset(): Unit
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package vork
package mdoc

import metaconfig.ConfDecoder
import metaconfig.ConfEncoder
import metaconfig.ConfError
import metaconfig.generic.Surface
import scala.meta.inputs.Input
import vork.internal.cli.Settings
import mdoc.internal.cli.Settings

trait StringModifier {
val name: String
Expand Down
Loading

0 comments on commit cacddcd

Please sign in to comment.