Crate shield_maker

source ·
Expand description

A simple badge generator in shields.io style, for Rust.

Features

  • Simple, bare-minimum API.
  • Plastic, Flat, and Flat-Squared styles
  • SVG output

Example

use std::fs;
use std::io;
use ab_glyph::FontArc;
use shield_maker::{Renderer, Metadata, Style, FontFamily};

fn main() -> io::Result<()> {
    let font_bytes = fs::read("tests/resources/DejaVuSans.ttf")
        .expect("could not read DejaVuSans.ttf");
    let font = FontArc::try_from_vec(font_bytes)
        .expect("could not parse DejaVuSans.ttf");

    let meta = &Metadata {
        style: Style::Plastic,
        label: "coverage",
        message: "100%",
        font,
        font_family: FontFamily::Default,
        label_color: None,
        color: None,
    };

    let output = Renderer::render(meta);
    let raw_plastic_badge = fs::read("tests/resources/plastic_badge.svg")
        .expect("could not read plastic_badge.svg");
    let plastic_badge: String = String::from_utf8(raw_plastic_badge)
        .expect("failed converting plastic_badge.svg to String")
        .trim()
        .into();
    assert_eq!(plastic_badge, output);

    Ok(())
}

Structs

Metadata represents all information required to build a badge.
Renderer implements all mechanisms required to turn a provided badge Metadata into its SVG representation.

Enums

Represents the desired font family of a badge
Represents the desired style of a badge