#image #rustdoc #documentation #base64 #img

docima

Generate images at build time & embed them in the Rust documentation

7 releases (breaking)

0.9.1 Aug 22, 2021
0.8.1-builddep Aug 22, 2021

#74 in Build Utils

Download history 2/week @ 2022-03-08 71/week @ 2022-03-15 52/week @ 2022-03-22 2/week @ 2022-03-29 5/week @ 2022-04-05 3/week @ 2022-04-12 4/week @ 2022-04-19 48/week @ 2022-04-26 56/week @ 2022-05-03 112/week @ 2022-05-10 25/week @ 2022-05-17 66/week @ 2022-05-24 74/week @ 2022-05-31 16/week @ 2022-06-07 5/week @ 2022-06-14 5/week @ 2022-06-21

135 downloads per month
Used in docima

MIT/Apache

29KB
388 lines

docima

Generate images at build time for embedding in the Rust documentation.

Crate API Lines Of Code

Warning

The current API is going to evolve a lot while the major version number is 0.

Usage

  1. First configure your build script to generate the images in the desired path. They will be encoded as pngbase64 and saved as HTML tags. E.g.:
ImageFile::new()
    .path("images/my_image.html")
    .width(600)
    .height(400)
    .attr("title", "My image")
    .attr("id", "image-01")
    .attr("style", "display: block; margin:auto;")
    .wrapper("div")
    .wrapper_attr("style", "background-color:red; padding:3px;")
    .overwrite(true)
    .generate(my_image_generator_function)?;
  1. Include your image in the Rust documentation by using the doc attribute and the include_str macro.
#[doc = include_str!("../images/my_image.html") ]
  1. Generate the docs:
cargo doc --open

Features

There are several features that allows to customize the defaults.

not_default_overwrite

By default all images will always be generated even when the target file already exists. By using this feature you can avoid generation in case the file exists.

Note that you can always override the default by using the overwrite method.

build_when_doc

By enabling this feature images will only be generated when the following doc feature is also used.

This can be very useful in case you need to always overwrite the generated files but don't want to generate the images when normally compiling the source code.

doc

Use this feature manually, in conjunction to build_when_doc.

You'll have to customize your setup using the the following example as a model:

Add to Cargo.toml:

[features]
doc = ["docima/doc"]

[build-dependencies]
docima = { version = "*", features = ["build_when_doc"] }

Then the images will only be generated when you use this feature, like this:

doc --features=doc

For greater convenience you can create a new alias in .cargo/config.toml:

[alias]
docdoc = "doc --features=doc"

More info

You can refer to the crate documentation and the source code for more complete information and practical examples.

Similar crates

Dependencies

~0.9–2MB
~23K SLoC