Rust badge maker

Overview

Badge-Maker

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*.

example_flat

example_plastic

example_flat_square

example_badge_maker

example_color

example_badge

*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.

About

This library is meant to be the Rust version of badge-maker. The use cases for this library are two-fold:

  • Rusty badge maker for any rust-based shields.io clones
  • WASM based npm package for a speed increase over the node based version (numbers coming when optimizations are finished)

Current todos

  1. Better code coverage
  2. Optimize text formatters
  3. Fix errors. The output is ugly.
  4. Other badge styles (requires a custom renderer)

Example

example_badge_maker

use badge_maker::BadgeBuilder;

let svg = BadgeBuilder::new()
      .label("badge")
      .message("maker")
      .color_parse("#33B5E5")
      .build()?
      .svg();

println!("{}", svg);

# Ok::<(), badge_maker::error::Error>(())

Features

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.

CLI

This is a library but you can use it with a simple cli tool as well.

cli

install

cargo install badge-maker --features cli

use

badge-maker example badge -c informational -l #282828 -s flat

Colors

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.

example_color

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>(())

Styles

Supported. Others coming soon. See Style enum for choices when building or use the string literals.

  • Flat example_flat
  • Plastic example_plastic
  • FlatSquare example_flat_square
  • ForTheBadge
  • Social
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>(())

Links & Logos

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).

example_link_logo

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>(())
Comments
  • New logos

    New logos

    1. So I updated the depend itoa. In 1.0.0 they drop the fmt function. I replaced the code with the equivalent https://docs.rs/itoa/0.4.7/src/itoa/lib.rs.html#90-93
    2. Closes #10
    3. Redid the gen_id function. I did this to make it more easily compatible with the new logo api.
    4. Changed the color function in the badge builder to take a generic for Into. To allow for easier setting of colors.
    5. Removed some clippy warnings. None of this could should be breaking.

    Gen_ID could possible break something. However, I don't see that happening.

    opened by wyatt-herkamp 2
  • Could not compile badge_maker

    Could not compile badge_maker

    When installing, I get the following error

    ❯ cargo install badge-maker --features cli
    
        Updating crates.io index
      Installing badge-maker v0.1.2
      Downloaded heck v0.3.3
      Downloaded clap_derive v3.0.0-beta.2
      Downloaded 2 crates (33.7 KB) in 0.50s
       Compiling proc-macro2 v1.0.27
       Compiling unicode-xid v0.2.2
       Compiling syn v1.0.72
       Compiling version_check v0.9.3
       Compiling autocfg v1.0.1
       Compiling memchr v2.4.0
       Compiling libc v0.2.95
       Compiling serde_derive v1.0.126
       Compiling bitflags v1.2.1
       Compiling unicode-segmentation v1.7.1
       Compiling serde v1.0.126
       Compiling hashbrown v0.9.1
       Compiling unicode-width v0.1.8
       Compiling regex-syntax v0.6.25
       Compiling strsim v0.10.0
       Compiling termcolor v1.1.2
       Compiling lazy_static v1.4.0
       Compiling vec_map v0.8.2
       Compiling os_str_bytes v2.4.0
       Compiling itoa v0.4.7
       Compiling seahash v4.1.0
       Compiling proc-macro-error-attr v1.0.4
       Compiling proc-macro-error v1.0.4
       Compiling textwrap v0.12.1
       Compiling indexmap v1.6.2
       Compiling heck v0.3.3
       Compiling aho-corasick v0.7.18
       Compiling quote v1.0.9
       Compiling atty v0.2.14
       Compiling regex v1.5.4
       Compiling clap_derive v3.0.0-beta.2
       Compiling thiserror-impl v1.0.25
       Compiling thiserror v1.0.25
       Compiling clap v3.0.0-beta.2
       Compiling bincode v1.3.3
       Compiling badge-maker v0.1.2
    error[E0603]: module `export` is private
       --> /Users/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/badge-maker-0.1.2/src/badge/style.rs:4:12
        |
    4   | use serde::export::Formatter;
        |            ^^^^^^ private module
        |
    note: the module `export` is defined here
       --> /Users/nathan/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.126/src/lib.rs:275:5
        |
    275 | use self::__private as export;
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0603`.
    error: failed to compile `badge-maker v0.1.2`, intermediate artifacts can be found at `/var/folders/wh/8s7_fv950zbbt9lq77xq4z780000gn/T/cargo-installhHTxrC`
    
    Caused by:
      could not compile `badge-maker`
    
    To learn more, run the command again with --verbose.
    
    opened by nathom 1
  • Fix failed import of serde::export::Formatter

    Fix failed import of serde::export::Formatter

    • use std::fmt::Formatter - as it was just reexport from std
    • make bin target conditional on cli feature

    Problem is with serde >= 1.0.119 - serde::export in now private module.

    opened by izderadicka 1
  • Add support for logoColor

    Add support for logoColor

    Hello there!

    Very nice crate!

    Would be great to get support for logoColor, just like img.shields.io.

    Here's an example:

    [Badge]badge

    Moreover, if a logoColor is not specified, the logo's svg colors should be displayed. Right now the logos show as black silhouettes regardless.

    As convenience for test purposes, this icon could be used: https://upload.wikimedia.org/wikipedia/commons/d/d5/Slack_icon_2019.svg

    opened by tarmath 0
  • Fix build and cargo install.

    Fix build and cargo install.

    This fixes the following error:

    # cargo build --features cli
       Compiling badge-maker v0.2.0 (/home/oni/VCS/rust-badge-maker)
    error[E0599]: no function or associated item named `parse` found for struct `Opts` in the current scope
      --> src/main.rs:21:28
       |
    5  | struct Opts {
       | ----------- function or associated item `parse` not found for this
    ...
    21 |     let opts: Opts = Opts::parse();
       |                            ^^^^^ function or associated item not found in `Opts`
       |
       = help: items from traits can only be used if the trait is in scope
    help: the following trait is implemented but not in scope; perhaps add a `use` for it:
       |
    1  | use clap::Parser;
       |
    
    For more information about this error, try `rustc --explain E0599`.
    error: could not compile `badge-maker` due to previous error
    
    opened by oniboni 0
  • Installation with CLI feature fails

    Installation with CLI feature fails

    Hi, I am experiencing an issue installing with the cli feature:

    docker run -it rust:1.56
    cargo install badge-maker --features cli
    

    fails with errors around clap. clap::Clap was renamed to clap::Parser in 3.0.0-beta.5: https://github.com/clap-rs/clap/blob/master/CHANGELOG.md

    opened by dreraic 0
  • Width calculation discrepancy when rendering emojis/utf16

    Width calculation discrepancy when rendering emojis/utf16

    This issue occurs in the e2e test when comparing the render width to the node version. Need to investigate at which point we deviate or miscalculate something.

    The end result is still usable just slightly off when 2-3 amount of emojis used.

    bug invalid 
    opened by cgbur 0
  • Refactor badge-maker node version to support e2e testing for logos/links

    Refactor badge-maker node version to support e2e testing for logos/links

    Currently the npm module has the logos and links rendering behind an API call so you cannot access them. This is probably because on shields.io logos and links are handled another way? Not sure but need to refactor the JS code they have to make the private API the public one. Then it can be integrated into the tests/e2e.rs we already have.

    code coverage 
    opened by cgbur 0
Rust parser combinator framework

nom, eating data byte by byte nom is a parser combinators library written in Rust. Its goal is to provide tools to build safe parsers without compromi

Geoffroy Couprie 7.6k Jan 7, 2023
Parsing Expression Grammar (PEG) parser generator for Rust

Parsing Expression Grammars in Rust Documentation | Release Notes rust-peg is a simple yet flexible parser generator that makes it easy to write robus

Kevin Mehall 1.2k Dec 30, 2022
A fast monadic-style parser combinator designed to work on stable Rust.

Chomp Chomp is a fast monadic-style parser combinator library designed to work on stable Rust. It was written as the culmination of the experiments de

Martin Wernstål 228 Oct 31, 2022
A parser combinator library for Rust

combine An implementation of parser combinators for Rust, inspired by the Haskell library Parsec. As in Parsec the parsers are LL(1) by default but th

Markus Westerlind 1.1k Dec 28, 2022
LR(1) parser generator for Rust

LALRPOP LALRPOP is a Rust parser generator framework with usability as its primary goal. You should be able to write compact, DRY, readable grammars.

null 2.4k Jan 7, 2023
A Rust library for zero-allocation parsing of binary data.

Zero A Rust library for zero-allocation parsing of binary data. Requires Rust version 1.6 or later (requires stable libcore for no_std). See docs for

Nick Cameron 45 Nov 27, 2022
A typed parser generator embedded in Rust code for Parsing Expression Grammars

Oak Compiled on the nightly channel of Rust. Use rustup for managing compiler channels. You can download and set up the exact same version of the comp

Pierre Talbot 138 Nov 25, 2022
Rust query string parser with nesting support

What is Queryst? This is a fork of the original, with serde and serde_json updated to 0.9 A query string parsing library for Rust inspired by https://

Stanislav Panferov 67 Nov 16, 2022
JsonPath engine written in Rust. Webassembly and Javascript support too

jsonpath_lib Rust 버전 JsonPath 구현으로 Webassembly와 Javascript에서도 유사한 API 인터페이스를 제공 한다. It is JsonPath JsonPath engine written in Rust. it provide a simil

Changseok Han 95 Dec 29, 2022
Soon to be AsciiDoc parser implemented in rust!

pagliascii "But ASCII Doc, I am Pagliascii" Soon to be AsciiDoc parser implemented in rust! This project is the current implementation of the requeste

Lukas Wirth 49 Dec 11, 2022
Parsing and inspecting Rust literals (particularly useful for proc macros)

litrs: parsing and inspecting Rust literals litrs offers functionality to parse Rust literals, i.e. tokens in the Rust programming language that repre

Lukas Kalbertodt 31 Dec 26, 2022
Rust library for parsing configuration files

configster Rust library for parsing configuration files Config file format The 'option' can be any string with no whitespace. arbitrary_option = false

The Impossible Astronaut 19 Jan 5, 2022
PEG parser for YAML written in Rust 🦀

yaml-peg PEG parser (pest) for YAML written in Rust ?? Quick Start ⚡️ # Run cargo run -- --file example_files/test.yaml # Output { "xmas": "true",

Visarut Phusua 4 Sep 17, 2022
This project aims to implement a CSS(less like) parser in rust. Currently the code is targeting the PostCSS AST.

CSS(less like) parser written in rust (WIP) This project aims to implement a CSS(less like) parser in rust. Currently the code is targeting the PostCS

Huang Liuhaoran 21 Aug 23, 2022
MRT/BGP data parser written in Rust.

BGPKIT Parser BGPKIT Parser aims to provides the most ergonomic MRT/BGP message parsing Rust API. BGPKIT Parser has the following features: performant

BGPKIT 46 Dec 19, 2022
This project aims to implement a CSS(less like) parser in rust. Currently the code is targeting the PostCSS AST. Very early stage, do not use in production.

CSS(less like) parser written in rust (WIP) This project aims to implement a CSS(less like) parser in rust. Currently the code is targeting the PostCS

Huang Liuhaoran 21 Aug 23, 2022
A feature-few, no-allocation JSON parser in `no_std` rust.

Small JSON Parser in no_std This library reads and parses JSON strings. Its intended use case is to read a JSON payload once. It does not serialise da

Robert Spencer 18 Nov 29, 2022
A Rust crate for RDF parsing and inferencing.

RDF-rs This crate provides the tools necessary to parse RDF graphs. It currently contains a full (with very few exceptions) Turtle parser that can par

null 2 May 29, 2022
Yet Another Parser library for Rust. A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing strings and slices.

Yap: Yet another (rust) parsing library A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing input.

James Wilson 117 Dec 14, 2022