I've just released skeptic 0.8.1.
This release features a more flexible template system (the old still works). Here's the description from the README:
Unlike rustdoc, Skeptic does not modify examples before testing by
default. Skeptic examples are placed in a '.rs' file, compiled, then
run.
This means that - by default - Skeptic examples require a main
function, as in all the examples above. Implicit wrapping of examples
in main
, and custom injection of extern crate
statements and crate
attributes are controlled through document-level templates.
Templates for a document are located in a separate file, that lives
next to the document on the filesystem, and has the same full name as
the document file, but with an additional ".skt.md" template.
So for example, this file, README.md
, stores its templates
in README.md.skt.md
.
This scheme allows the markdown to be displayed naturally be stock
Markdown renderers without displaying the template itself. The weird
file extension is similarly so that the templates themselves are
interpreted as valid markdown while being easy to ignore based on file
system.
Consider this example:
let p = PathBuf::from("foo");
println!("{:?}", p);
This example won't compile without defining main
and importing
PathBuf
, but the example itself does not contain that
boilerplate. Instead it is annotated skt-foo
, for skeptic template
foo, like so:
```rust,skt-foo
let p = PathBuf::from("foo");
println!("{:?}", p);
This tells skeptic to look in the template file for another
markdown block with the same `skt-foo` annotation, and composes
them together using the standard Rust `format!` macro. Here's
what the template looks like:
```rust,ignore
```rust,skt-foo
use std::path::PathBuf;
fn main() {{
{}
}}