Crates.io | badge-maker |
lib.rs | badge-maker |
version | 0.3.1 |
source | src |
created_at | 2021-01-08 20:11:48.955373 |
updated_at | 2022-06-21 04:21:11.726816 |
description | It makes badges. |
homepage | https://github.com/cgbur/badge-maker |
repository | https://github.com/cgbur/badge-maker |
max_upload_size | |
id | 334769 |
size | 251,562 |
Links are generated from cargo, view on docs page
A fast and accurate badge maker for services like shields.io. Verified to match badge-maker 1-to-1 with side by rendering tests*.
*This library differs in that it generates unique IDs for the svg so it can be directly embedded in websites (such as in this doc). So a diff between the outputs will not match. We only claim the visual outputs match which is whats important.
This library is meant to be the Rust version of badge-maker. The use cases for this library are two-fold:
Current todos
use badge_maker::BadgeBuilder;
let svg = BadgeBuilder::new()
.label("badge")
.message("maker")
.color_parse("#33B5E5")
.build()?
.svg();
println!("{}", svg);
# Ok::<(), badge_maker::error::Error>(())
This library is still in its infancy. Tests and documentation are being added whenever possible. If you are interested in contributing then check out the repository. The API is likely to change. If you see something you think would work better than the way I've done it open an issue, I'd love to hear your suggestions.
We support different styles, colors, logos, and links. The
badge builder accepts all of these options with the field()
and an
alternate method of field_parse()
which accepts a string and will attempt parse the text as
a valid field.
This is a library but you can use it with a simple cli tool as well.
install
cargo install badge-maker --features cli
use
badge-maker example badge -c informational -l #282828 -s flat
on windows the #
needs to be handled specially
badge-maker example badge -c informational -l "#282828" -s flat
We currently support hex colors 3 and 6 chars long, named colors
and their alias's, and RGB color inputs. These can be constructed
with their enum variants or using the ...parse()
methods.
use badge_maker::BadgeBuilder;
use badge_maker::color::{Color, AliasColor, NamedColor};
let svg = BadgeBuilder::new()
.label("color")
.message("example")
// by enums
.color(Color::Named(NamedColor::BrightGreen))
.color(Color::Alias(AliasColor::Success))
.color(Color::Rgb(10, 200, 50))
// or parsing
.color_parse("brightgreen")
.color_parse("success")
.color_parse("rgb(10, 200, 50)")
.build()?
.svg();
# Ok::<(), badge_maker::error::Error>(())
Supported. Others coming soon. See Style enum for choices when building or use the string literals.
use badge_maker::{BadgeBuilder, Style};
let svg = BadgeBuilder::new()
.label("example")
.message("plastic")
.color_parse("#FFB932")
.style(Style::Plastic) // example of using typed input
.style_parse("plastic") // example of parsing to derive
.build()?
.svg();
println!("{}", svg);
# Ok::<(), badge_maker::error::Error>(())
Adding links to the natively rendered badge supported. This is great if you need
to embed the svg directly. However, on a website like the rust docs they may show
the underline. To solve this, your third-party api that renders the badges should
wrap the svg in markdown [![name for readers](link to api endpoint)](link when clicked)
.
use badge_maker::BadgeBuilder;
let logo_url = "https://upload.wikimedia.org/wikipedia/commons/\
thumb/d/d5/Rust_programming_language_black_logo.svg/\
1024px-Rust_programming_language_black_logo.svg.png";
let svg = BadgeBuilder::new()
.label("lang")
.message("rust")
.color_parse("#F5F5F5")
.link("https://www.rust-lang.org/")
.logo_url(logo_url)
.style_parse("flatsquare")
.build()?
.svg();
# Ok::<(), badge_maker::error::Error>(())