1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-30 12:07:46 +00:00

feat: sponsor benefits

This commit is contained in:
Kevin Amado 2022-08-09 12:47:15 -06:00
parent cf8b9d8cfa
commit 1c3fdf5b60
11 changed files with 106 additions and 14 deletions

View file

@ -275,6 +275,7 @@ Thank you ❤️
- [Norbert Melzer](https://github.com/NobbZ).
- [Patrick Stevens](https://github.com/Smaug123).
- [Connor Baker](https://github.com/ConnorBaker).
- [Matthew Kenigsberg](https://github.com/mkenigs).
- [Florian Finkernagel](https://github.com/TyberiusPrime).
## Footnotes

View file

@ -15,7 +15,10 @@ futures = { version = "*", default_features = false, features = [
"thread-pool"
] }
num_cpus = { version = "*", default_features = false, features = [] }
rand = { version = "*", default-features = false, features = ["getrandom"] }
rand = { version = "*", default-features = false, features = [
"alloc",
"getrandom"
] }
walkdir = { version = "*", default_features = false, features = [] }
[package]

View file

@ -0,0 +1,2 @@
👏 Special thanks to {name} for helping improve this project:
https://github.com/{github}

View file

@ -1,2 +0,0 @@
If Alejandra is useful to you, please sponsor its author.
Thank you! https://github.com/sponsors/kamadorueda

View file

@ -1,11 +1,94 @@
use rand::distributions::weighted::WeightedIndex;
use rand::distributions::Distribution;
use rand::distributions::Uniform;
use rand::rngs::OsRng;
pub(crate) fn random_ad() -> &'static str {
let ads = [include_str!("star.txt"), include_str!("donation.txt")];
pub(crate) fn random_ad() -> String {
let ads = [
// 90% distributed proportional to total past and present contributions
// (0.9001, sponsor_benefits as fn() -> String),
// 10% is reserved for everything else
(0.0333, contributor_thanks as fn() -> String),
(0.0333, please_sponsor as fn() -> String),
(0.0333, please_star as fn() -> String),
];
let ads_index = Uniform::from(0..ads.len()).sample(&mut OsRng);
ads[ads_index]
random_weighted_choice(&ads[..])()
}
fn sponsor_benefits() -> String {
#[allow(dead_code)]
enum Sponsor<'a> {
Individual { name: &'a str },
Company { ad: &'a str },
}
let sponsors = [];
match random_weighted_choice(&sponsors[..]) {
Sponsor::Company { ad } => {
include_str!("sponsor_advertisement.txt").replace("{ad}", ad)
},
Sponsor::Individual { name } => {
include_str!("sponsor_thanks.txt").replace("{name}", name)
},
}
}
fn contributor_thanks() -> String {
let names = [
(1.0, ("Connor Baker", "ConnorBaker")),
(1.0, ("David Arnold", "blaggacao")),
(1.0, ("David Hauer", "DavHau")),
(1.0, ("Fabian Möller", "B4dM4n")),
(1.0, ("Florian Finkernagel", "TyberiusPrime")),
(1.0, ("Jamie Quigley", "Sciencentistguy")),
(1.0, ("Joachim Ernst", "0x4A6F")),
(1.0, ("Jörg Thalheim", "Mic92")),
(1.0, ("Kevin Amado", "kamadorueda")),
(1.0, ("Loïc Reynier", "loicreynier")),
(1.0, ("Matthew Kenigsberg", "mkenigs")),
(1.0, ("Mr Hedgehog", "ModdedGamers")),
(1.0, ("Norbert Melzer", "NobbZ")),
(1.0, ("Patrick Stevens", "Smaug123")),
(1.0, ("Piegames", "piegamesde")),
(1.0, ("Rehno Lindeque", "rehno-lindeque")),
(1.0, ("Rok Garbas", "garbas")),
(1.0, ("Ryan Mulligan", "ryantm")),
(1.0, ("Thomas Bereknyei", "tomberek")),
(1.0, ("Tristan Maat", "TLATER")),
(1.0, ("Vincent Ambo", "tazjin")),
(1.0, ("Yorick van Pelt", "yorickvP")),
];
let (name, github) = random_weighted_choice(&names[..]);
include_str!("contributor_thanks.txt")
.replace("{github}", github)
.replace("{name}", name)
}
fn please_sponsor() -> String {
let messages = [
(0.5000, include_str!("sponsor_advertisement.txt").replace(
"{ad}",
concat!(
"Advertise your company here, reach lots of active Nix users!\n",
"More information at: https://github.com/sponsors/kamadorueda\n"
),
)),
(0.5000, include_str!("please_sponsor.txt").to_string()),
];
random_weighted_choice(&messages[..]).clone()
}
fn please_star() -> String {
include_str!("please_star.txt").to_string()
}
fn random_weighted_choice<T>(choices: &[(f64, T)]) -> &T {
let weights = choices.iter().map(|(weight, _)| *weight);
let index: usize = WeightedIndex::new(weights).unwrap().sample(&mut OsRng);
&choices[index].1
}

View file

@ -0,0 +1,2 @@
🤟 If Alejandra is useful to you, please consider sponsoring its author!
There are cool benefits for you: https://github.com/sponsors/kamadorueda

View file

@ -0,0 +1,2 @@
⭐ If Alejandra is useful to you, please add your star to the repository.
Thank you! https://github.com/kamadorueda/alejandra

View file

@ -0,0 +1 @@
👉 [Sponsored] {ad}

View file

@ -0,0 +1 @@
👏 Special thanks to {name} for being a sponsor of Alejandra!

View file

@ -1,2 +0,0 @@
If Alejandra is useful to you, please add your star to the repository.
Thank you! https://github.com/kamadorueda/alejandra

View file

@ -87,8 +87,7 @@ fn format_paths(
if verbosity.allows_info() {
eprintln!(
"{} {paths_len} file{} using {threads} thread{}.",
"Checking style in",
"Checking style in {paths_len} file{} using {threads} thread{}.",
if paths_len == 1 { "" } else { "s" },
if threads == 1 { "" } else { "s" },
);
@ -218,7 +217,9 @@ pub fn main() -> std::io::Result<()> {
if verbosity.allows_info() {
eprintln!();
eprintln!("Congratulations! Your code complies with the Alejandra style.");
eprintln!(
"Congratulations! Your code complies with the Alejandra style."
);
eprintln!();
eprint!("{}", random_ad());
}