From 0148b476a41653e1fa6a27ab159f75fcecb7722d Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Tue, 24 Aug 2021 19:49:30 +0300 Subject: [PATCH] Improvements --- .github/images/flat_blue.svg | 2 +- .github/images/flat_brightgreen.svg | 2 +- .github/images/flat_critical.svg | 2 +- .github/images/flat_custom.svg | 2 +- .github/images/flat_green.svg | 2 +- .github/images/flat_important.svg | 2 +- .github/images/flat_inactive.svg | 2 +- .github/images/flat_informational.svg | 2 +- .github/images/flat_japanese.svg | 1 + .github/images/flat_lightgrey.svg | 2 +- .github/images/flat_orange.svg | 2 +- .github/images/flat_red.svg | 2 +- .github/images/flat_simple_blue.svg | 1 + .github/images/flat_simple_brightgreen.svg | 1 + .github/images/flat_simple_critical.svg | 1 + .github/images/flat_simple_custom.svg | 1 + .github/images/flat_simple_green.svg | 1 + .github/images/flat_simple_important.svg | 1 + .github/images/flat_simple_inactive.svg | 1 + .github/images/flat_simple_informational.svg | 1 + .github/images/flat_simple_japanese.svg | 1 + .github/images/flat_simple_lightgrey.svg | 1 + .github/images/flat_simple_orange.svg | 1 + .github/images/flat_simple_red.svg | 1 + .github/images/flat_simple_success.svg | 1 + .github/images/flat_simple_yellow.svg | 1 + .github/images/flat_simple_yellowgreen.svg | 1 + .github/images/flat_success.svg | 2 +- .github/images/flat_yellow.svg | 2 +- .github/images/flat_yellowgreen.svg | 2 +- .github/images/plastic_blue.svg | 2 +- .github/images/plastic_brightgreen.svg | 2 +- .github/images/plastic_critical.svg | 2 +- .github/images/plastic_custom.svg | 2 +- .github/images/plastic_green.svg | 2 +- .github/images/plastic_important.svg | 2 +- .github/images/plastic_inactive.svg | 2 +- .github/images/plastic_informational.svg | 2 +- .github/images/plastic_japanese.svg | 1 + .github/images/plastic_lightgrey.svg | 2 +- .github/images/plastic_orange.svg | 2 +- .github/images/plastic_red.svg | 2 +- .github/images/plastic_simple_blue.svg | 1 + .github/images/plastic_simple_brightgreen.svg | 1 + .github/images/plastic_simple_critical.svg | 1 + .github/images/plastic_simple_custom.svg | 1 + .github/images/plastic_simple_green.svg | 1 + .github/images/plastic_simple_important.svg | 1 + .github/images/plastic_simple_inactive.svg | 1 + .../images/plastic_simple_informational.svg | 1 + .github/images/plastic_simple_japanese.svg | 1 + .github/images/plastic_simple_lightgrey.svg | 1 + .github/images/plastic_simple_orange.svg | 1 + .github/images/plastic_simple_red.svg | 1 + .github/images/plastic_simple_success.svg | 1 + .github/images/plastic_simple_yellow.svg | 1 + .github/images/plastic_simple_yellowgreen.svg | 1 + .github/images/plastic_success.svg | 2 +- .github/images/plastic_yellow.svg | 2 +- .github/images/plastic_yellowgreen.svg | 2 +- .github/images/square_blue.svg | 2 +- .github/images/square_brightgreen.svg | 2 +- .github/images/square_critical.svg | 2 +- .github/images/square_custom.svg | 2 +- .github/images/square_green.svg | 2 +- .github/images/square_important.svg | 2 +- .github/images/square_inactive.svg | 2 +- .github/images/square_informational.svg | 2 +- .github/images/square_japanese.svg | 1 + .github/images/square_lightgrey.svg | 2 +- .github/images/square_orange.svg | 2 +- .github/images/square_red.svg | 2 +- .github/images/square_simple_blue.svg | 1 + .github/images/square_simple_brightgreen.svg | 1 + .github/images/square_simple_critical.svg | 1 + .github/images/square_simple_custom.svg | 1 + .github/images/square_simple_green.svg | 1 + .github/images/square_simple_important.svg | 1 + .github/images/square_simple_inactive.svg | 1 + .../images/square_simple_informational.svg | 1 + .github/images/square_simple_japanese.svg | 1 + .github/images/square_simple_lightgrey.svg | 1 + .github/images/square_simple_orange.svg | 1 + .github/images/square_simple_red.svg | 1 + .github/images/square_simple_success.svg | 1 + .github/images/square_simple_yellow.svg | 1 + .github/images/square_simple_yellowgreen.svg | 1 + .github/images/square_success.svg | 2 +- .github/images/square_yellow.svg | 2 +- .github/images/square_yellowgreen.svg | 2 +- .github/workflows/ci.yml | 20 +-- README.md | 37 ++-- badge.go | 160 +++++++++++++++--- badge_test.go | 85 +++++++++- testdata/black.svg | 1 + testdata/flat-square.svg | 1 - testdata/flat.svg | 2 +- testdata/flat_simple.svg | 1 + testdata/plastic.svg | 2 +- testdata/plastic_simple.svg | 1 + testdata/square.svg | 1 + testdata/square_simple.svg | 1 + testdata/white.svg | 1 + 103 files changed, 342 insertions(+), 103 deletions(-) create mode 100644 .github/images/flat_japanese.svg create mode 100644 .github/images/flat_simple_blue.svg create mode 100644 .github/images/flat_simple_brightgreen.svg create mode 100644 .github/images/flat_simple_critical.svg create mode 100644 .github/images/flat_simple_custom.svg create mode 100644 .github/images/flat_simple_green.svg create mode 100644 .github/images/flat_simple_important.svg create mode 100644 .github/images/flat_simple_inactive.svg create mode 100644 .github/images/flat_simple_informational.svg create mode 100644 .github/images/flat_simple_japanese.svg create mode 100644 .github/images/flat_simple_lightgrey.svg create mode 100644 .github/images/flat_simple_orange.svg create mode 100644 .github/images/flat_simple_red.svg create mode 100644 .github/images/flat_simple_success.svg create mode 100644 .github/images/flat_simple_yellow.svg create mode 100644 .github/images/flat_simple_yellowgreen.svg create mode 100644 .github/images/plastic_japanese.svg create mode 100644 .github/images/plastic_simple_blue.svg create mode 100644 .github/images/plastic_simple_brightgreen.svg create mode 100644 .github/images/plastic_simple_critical.svg create mode 100644 .github/images/plastic_simple_custom.svg create mode 100644 .github/images/plastic_simple_green.svg create mode 100644 .github/images/plastic_simple_important.svg create mode 100644 .github/images/plastic_simple_inactive.svg create mode 100644 .github/images/plastic_simple_informational.svg create mode 100644 .github/images/plastic_simple_japanese.svg create mode 100644 .github/images/plastic_simple_lightgrey.svg create mode 100644 .github/images/plastic_simple_orange.svg create mode 100644 .github/images/plastic_simple_red.svg create mode 100644 .github/images/plastic_simple_success.svg create mode 100644 .github/images/plastic_simple_yellow.svg create mode 100644 .github/images/plastic_simple_yellowgreen.svg create mode 100644 .github/images/square_japanese.svg create mode 100644 .github/images/square_simple_blue.svg create mode 100644 .github/images/square_simple_brightgreen.svg create mode 100644 .github/images/square_simple_critical.svg create mode 100644 .github/images/square_simple_custom.svg create mode 100644 .github/images/square_simple_green.svg create mode 100644 .github/images/square_simple_important.svg create mode 100644 .github/images/square_simple_inactive.svg create mode 100644 .github/images/square_simple_informational.svg create mode 100644 .github/images/square_simple_japanese.svg create mode 100644 .github/images/square_simple_lightgrey.svg create mode 100644 .github/images/square_simple_orange.svg create mode 100644 .github/images/square_simple_red.svg create mode 100644 .github/images/square_simple_success.svg create mode 100644 .github/images/square_simple_yellow.svg create mode 100644 .github/images/square_simple_yellowgreen.svg create mode 100644 testdata/black.svg delete mode 100644 testdata/flat-square.svg create mode 100644 testdata/flat_simple.svg create mode 100644 testdata/plastic_simple.svg create mode 100644 testdata/square.svg create mode 100644 testdata/square_simple.svg create mode 100644 testdata/white.svg diff --git a/.github/images/flat_blue.svg b/.github/images/flat_blue.svg index 49e9f87..6772f9f 100644 --- a/.github/images/flat_blue.svg +++ b/.github/images/flat_blue.svg @@ -1 +1 @@ -flat: blueflatblue \ No newline at end of file +flat: blueflatblue \ No newline at end of file diff --git a/.github/images/flat_brightgreen.svg b/.github/images/flat_brightgreen.svg index dbccd09..cc33cee 100644 --- a/.github/images/flat_brightgreen.svg +++ b/.github/images/flat_brightgreen.svg @@ -1 +1 @@ -flat: brightgreenflatbrightgreen \ No newline at end of file +flat: brightgreenflatbrightgreen \ No newline at end of file diff --git a/.github/images/flat_critical.svg b/.github/images/flat_critical.svg index 69ac634..382fb87 100644 --- a/.github/images/flat_critical.svg +++ b/.github/images/flat_critical.svg @@ -1 +1 @@ -flat: criticalflatcritical \ No newline at end of file +flat: criticalflatcritical \ No newline at end of file diff --git a/.github/images/flat_custom.svg b/.github/images/flat_custom.svg index 0024b92..875a3b6 100644 --- a/.github/images/flat_custom.svg +++ b/.github/images/flat_custom.svg @@ -1 +1 @@ -flat: ff69b4flatff69b4 \ No newline at end of file +flat: #ff69b4flat#ff69b4 \ No newline at end of file diff --git a/.github/images/flat_green.svg b/.github/images/flat_green.svg index 929da59..0ea53b8 100644 --- a/.github/images/flat_green.svg +++ b/.github/images/flat_green.svg @@ -1 +1 @@ -flat: greenflatgreen \ No newline at end of file +flat: greenflatgreen \ No newline at end of file diff --git a/.github/images/flat_important.svg b/.github/images/flat_important.svg index 3bfa71c..076c6c2 100644 --- a/.github/images/flat_important.svg +++ b/.github/images/flat_important.svg @@ -1 +1 @@ -flat: importantflatimportant \ No newline at end of file +flat: importantflatimportant \ No newline at end of file diff --git a/.github/images/flat_inactive.svg b/.github/images/flat_inactive.svg index 88be8a2..d6d021e 100644 --- a/.github/images/flat_inactive.svg +++ b/.github/images/flat_inactive.svg @@ -1 +1 @@ -flat: inactiveflatinactive \ No newline at end of file +flat: inactiveflatinactive \ No newline at end of file diff --git a/.github/images/flat_informational.svg b/.github/images/flat_informational.svg index 3c0b0d6..b0e5aed 100644 --- a/.github/images/flat_informational.svg +++ b/.github/images/flat_informational.svg @@ -1 +1 @@ -flat: informationalflatinformational \ No newline at end of file +flat: informationalflatinformational \ No newline at end of file diff --git a/.github/images/flat_japanese.svg b/.github/images/flat_japanese.svg new file mode 100644 index 0000000..77aee17 --- /dev/null +++ b/.github/images/flat_japanese.svg @@ -0,0 +1 @@ +ラベル: メッセージラベルメッセージ \ No newline at end of file diff --git a/.github/images/flat_lightgrey.svg b/.github/images/flat_lightgrey.svg index be4d04a..f14aacc 100644 --- a/.github/images/flat_lightgrey.svg +++ b/.github/images/flat_lightgrey.svg @@ -1 +1 @@ -flat: lightgreyflatlightgrey \ No newline at end of file +flat: lightgreyflatlightgrey \ No newline at end of file diff --git a/.github/images/flat_orange.svg b/.github/images/flat_orange.svg index da8f358..9a94907 100644 --- a/.github/images/flat_orange.svg +++ b/.github/images/flat_orange.svg @@ -1 +1 @@ -flat: orangeflatorange \ No newline at end of file +flat: orangeflatorange \ No newline at end of file diff --git a/.github/images/flat_red.svg b/.github/images/flat_red.svg index 7d3b69d..24112d8 100644 --- a/.github/images/flat_red.svg +++ b/.github/images/flat_red.svg @@ -1 +1 @@ -flat: redflatred \ No newline at end of file +flat: redflatred \ No newline at end of file diff --git a/.github/images/flat_simple_blue.svg b/.github/images/flat_simple_blue.svg new file mode 100644 index 0000000..8b4965d --- /dev/null +++ b/.github/images/flat_simple_blue.svg @@ -0,0 +1 @@ +blueblue \ No newline at end of file diff --git a/.github/images/flat_simple_brightgreen.svg b/.github/images/flat_simple_brightgreen.svg new file mode 100644 index 0000000..b27d929 --- /dev/null +++ b/.github/images/flat_simple_brightgreen.svg @@ -0,0 +1 @@ +brightgreenbrightgreen \ No newline at end of file diff --git a/.github/images/flat_simple_critical.svg b/.github/images/flat_simple_critical.svg new file mode 100644 index 0000000..5ad65e9 --- /dev/null +++ b/.github/images/flat_simple_critical.svg @@ -0,0 +1 @@ +criticalcritical \ No newline at end of file diff --git a/.github/images/flat_simple_custom.svg b/.github/images/flat_simple_custom.svg new file mode 100644 index 0000000..023bab6 --- /dev/null +++ b/.github/images/flat_simple_custom.svg @@ -0,0 +1 @@ +#ff69b4#ff69b4 \ No newline at end of file diff --git a/.github/images/flat_simple_green.svg b/.github/images/flat_simple_green.svg new file mode 100644 index 0000000..07ad6e4 --- /dev/null +++ b/.github/images/flat_simple_green.svg @@ -0,0 +1 @@ +greengreen \ No newline at end of file diff --git a/.github/images/flat_simple_important.svg b/.github/images/flat_simple_important.svg new file mode 100644 index 0000000..e811308 --- /dev/null +++ b/.github/images/flat_simple_important.svg @@ -0,0 +1 @@ +importantimportant \ No newline at end of file diff --git a/.github/images/flat_simple_inactive.svg b/.github/images/flat_simple_inactive.svg new file mode 100644 index 0000000..6410785 --- /dev/null +++ b/.github/images/flat_simple_inactive.svg @@ -0,0 +1 @@ +inactiveinactive \ No newline at end of file diff --git a/.github/images/flat_simple_informational.svg b/.github/images/flat_simple_informational.svg new file mode 100644 index 0000000..674a1ac --- /dev/null +++ b/.github/images/flat_simple_informational.svg @@ -0,0 +1 @@ +informationalinformational \ No newline at end of file diff --git a/.github/images/flat_simple_japanese.svg b/.github/images/flat_simple_japanese.svg new file mode 100644 index 0000000..77aee17 --- /dev/null +++ b/.github/images/flat_simple_japanese.svg @@ -0,0 +1 @@ +ラベル: メッセージラベルメッセージ \ No newline at end of file diff --git a/.github/images/flat_simple_lightgrey.svg b/.github/images/flat_simple_lightgrey.svg new file mode 100644 index 0000000..10dca79 --- /dev/null +++ b/.github/images/flat_simple_lightgrey.svg @@ -0,0 +1 @@ +lightgreylightgrey \ No newline at end of file diff --git a/.github/images/flat_simple_orange.svg b/.github/images/flat_simple_orange.svg new file mode 100644 index 0000000..c718f9f --- /dev/null +++ b/.github/images/flat_simple_orange.svg @@ -0,0 +1 @@ +orangeorange \ No newline at end of file diff --git a/.github/images/flat_simple_red.svg b/.github/images/flat_simple_red.svg new file mode 100644 index 0000000..8c392b0 --- /dev/null +++ b/.github/images/flat_simple_red.svg @@ -0,0 +1 @@ +redred \ No newline at end of file diff --git a/.github/images/flat_simple_success.svg b/.github/images/flat_simple_success.svg new file mode 100644 index 0000000..7e654ed --- /dev/null +++ b/.github/images/flat_simple_success.svg @@ -0,0 +1 @@ +successsuccess \ No newline at end of file diff --git a/.github/images/flat_simple_yellow.svg b/.github/images/flat_simple_yellow.svg new file mode 100644 index 0000000..4b090b7 --- /dev/null +++ b/.github/images/flat_simple_yellow.svg @@ -0,0 +1 @@ +yellowyellow \ No newline at end of file diff --git a/.github/images/flat_simple_yellowgreen.svg b/.github/images/flat_simple_yellowgreen.svg new file mode 100644 index 0000000..20247ad --- /dev/null +++ b/.github/images/flat_simple_yellowgreen.svg @@ -0,0 +1 @@ +yellowgreenyellowgreen \ No newline at end of file diff --git a/.github/images/flat_success.svg b/.github/images/flat_success.svg index ba92a33..f940dc9 100644 --- a/.github/images/flat_success.svg +++ b/.github/images/flat_success.svg @@ -1 +1 @@ -flat: successflatsuccess \ No newline at end of file +flat: successflatsuccess \ No newline at end of file diff --git a/.github/images/flat_yellow.svg b/.github/images/flat_yellow.svg index b91b878..8e6659b 100644 --- a/.github/images/flat_yellow.svg +++ b/.github/images/flat_yellow.svg @@ -1 +1 @@ -flat: yellowflatyellow \ No newline at end of file +flat: yellowflatyellow \ No newline at end of file diff --git a/.github/images/flat_yellowgreen.svg b/.github/images/flat_yellowgreen.svg index 28ec70b..5a09129 100644 --- a/.github/images/flat_yellowgreen.svg +++ b/.github/images/flat_yellowgreen.svg @@ -1 +1 @@ -flat: yellowgreenflatyellowgreen \ No newline at end of file +flat: yellowgreenflatyellowgreen \ No newline at end of file diff --git a/.github/images/plastic_blue.svg b/.github/images/plastic_blue.svg index 51f2a78..e6999af 100644 --- a/.github/images/plastic_blue.svg +++ b/.github/images/plastic_blue.svg @@ -1 +1 @@ -plastic: blueplasticblue \ No newline at end of file +plastic: blueplasticblue \ No newline at end of file diff --git a/.github/images/plastic_brightgreen.svg b/.github/images/plastic_brightgreen.svg index 61b9312..3faabfa 100644 --- a/.github/images/plastic_brightgreen.svg +++ b/.github/images/plastic_brightgreen.svg @@ -1 +1 @@ -plastic: brightgreenplasticbrightgreen \ No newline at end of file +plastic: brightgreenplasticbrightgreen \ No newline at end of file diff --git a/.github/images/plastic_critical.svg b/.github/images/plastic_critical.svg index b3668fc..5763409 100644 --- a/.github/images/plastic_critical.svg +++ b/.github/images/plastic_critical.svg @@ -1 +1 @@ -plastic: criticalplasticcritical \ No newline at end of file +plastic: criticalplasticcritical \ No newline at end of file diff --git a/.github/images/plastic_custom.svg b/.github/images/plastic_custom.svg index 1751619..3e85a3b 100644 --- a/.github/images/plastic_custom.svg +++ b/.github/images/plastic_custom.svg @@ -1 +1 @@ -plastic: ff69b4plasticff69b4 \ No newline at end of file +plastic: #ff69b4plastic#ff69b4 \ No newline at end of file diff --git a/.github/images/plastic_green.svg b/.github/images/plastic_green.svg index 07c890b..1ddf761 100644 --- a/.github/images/plastic_green.svg +++ b/.github/images/plastic_green.svg @@ -1 +1 @@ -plastic: greenplasticgreen \ No newline at end of file +plastic: greenplasticgreen \ No newline at end of file diff --git a/.github/images/plastic_important.svg b/.github/images/plastic_important.svg index 78b3f98..025031a 100644 --- a/.github/images/plastic_important.svg +++ b/.github/images/plastic_important.svg @@ -1 +1 @@ -plastic: importantplasticimportant \ No newline at end of file +plastic: importantplasticimportant \ No newline at end of file diff --git a/.github/images/plastic_inactive.svg b/.github/images/plastic_inactive.svg index f8924c7..955b912 100644 --- a/.github/images/plastic_inactive.svg +++ b/.github/images/plastic_inactive.svg @@ -1 +1 @@ -plastic: inactiveplasticinactive \ No newline at end of file +plastic: inactiveplasticinactive \ No newline at end of file diff --git a/.github/images/plastic_informational.svg b/.github/images/plastic_informational.svg index 0e715a2..9f73d88 100644 --- a/.github/images/plastic_informational.svg +++ b/.github/images/plastic_informational.svg @@ -1 +1 @@ -plastic: informationalplasticinformational \ No newline at end of file +plastic: informationalplasticinformational \ No newline at end of file diff --git a/.github/images/plastic_japanese.svg b/.github/images/plastic_japanese.svg new file mode 100644 index 0000000..b666023 --- /dev/null +++ b/.github/images/plastic_japanese.svg @@ -0,0 +1 @@ +ラベル: メッセージラベルメッセージ \ No newline at end of file diff --git a/.github/images/plastic_lightgrey.svg b/.github/images/plastic_lightgrey.svg index 03e1526..dd239ed 100644 --- a/.github/images/plastic_lightgrey.svg +++ b/.github/images/plastic_lightgrey.svg @@ -1 +1 @@ -plastic: lightgreyplasticlightgrey \ No newline at end of file +plastic: lightgreyplasticlightgrey \ No newline at end of file diff --git a/.github/images/plastic_orange.svg b/.github/images/plastic_orange.svg index 2b0075e..4f04319 100644 --- a/.github/images/plastic_orange.svg +++ b/.github/images/plastic_orange.svg @@ -1 +1 @@ -plastic: orangeplasticorange \ No newline at end of file +plastic: orangeplasticorange \ No newline at end of file diff --git a/.github/images/plastic_red.svg b/.github/images/plastic_red.svg index cc7ebd7..a7ca147 100644 --- a/.github/images/plastic_red.svg +++ b/.github/images/plastic_red.svg @@ -1 +1 @@ -plastic: redplasticred \ No newline at end of file +plastic: redplasticred \ No newline at end of file diff --git a/.github/images/plastic_simple_blue.svg b/.github/images/plastic_simple_blue.svg new file mode 100644 index 0000000..93bb034 --- /dev/null +++ b/.github/images/plastic_simple_blue.svg @@ -0,0 +1 @@ +TESTTESTblue \ No newline at end of file diff --git a/.github/images/plastic_simple_brightgreen.svg b/.github/images/plastic_simple_brightgreen.svg new file mode 100644 index 0000000..2438eac --- /dev/null +++ b/.github/images/plastic_simple_brightgreen.svg @@ -0,0 +1 @@ +TESTTESTbrightgreen \ No newline at end of file diff --git a/.github/images/plastic_simple_critical.svg b/.github/images/plastic_simple_critical.svg new file mode 100644 index 0000000..8e6e2ac --- /dev/null +++ b/.github/images/plastic_simple_critical.svg @@ -0,0 +1 @@ +TESTTESTcritical \ No newline at end of file diff --git a/.github/images/plastic_simple_custom.svg b/.github/images/plastic_simple_custom.svg new file mode 100644 index 0000000..c4e5f2c --- /dev/null +++ b/.github/images/plastic_simple_custom.svg @@ -0,0 +1 @@ +TESTTEST#ff69b4 \ No newline at end of file diff --git a/.github/images/plastic_simple_green.svg b/.github/images/plastic_simple_green.svg new file mode 100644 index 0000000..bf39fdf --- /dev/null +++ b/.github/images/plastic_simple_green.svg @@ -0,0 +1 @@ +TESTTESTgreen \ No newline at end of file diff --git a/.github/images/plastic_simple_important.svg b/.github/images/plastic_simple_important.svg new file mode 100644 index 0000000..6cc6828 --- /dev/null +++ b/.github/images/plastic_simple_important.svg @@ -0,0 +1 @@ +TESTTESTimportant \ No newline at end of file diff --git a/.github/images/plastic_simple_inactive.svg b/.github/images/plastic_simple_inactive.svg new file mode 100644 index 0000000..ec21f48 --- /dev/null +++ b/.github/images/plastic_simple_inactive.svg @@ -0,0 +1 @@ +TESTTESTinactive \ No newline at end of file diff --git a/.github/images/plastic_simple_informational.svg b/.github/images/plastic_simple_informational.svg new file mode 100644 index 0000000..f32e5cb --- /dev/null +++ b/.github/images/plastic_simple_informational.svg @@ -0,0 +1 @@ +TESTTESTinformational \ No newline at end of file diff --git a/.github/images/plastic_simple_japanese.svg b/.github/images/plastic_simple_japanese.svg new file mode 100644 index 0000000..b666023 --- /dev/null +++ b/.github/images/plastic_simple_japanese.svg @@ -0,0 +1 @@ +ラベル: メッセージラベルメッセージ \ No newline at end of file diff --git a/.github/images/plastic_simple_lightgrey.svg b/.github/images/plastic_simple_lightgrey.svg new file mode 100644 index 0000000..7602dcd --- /dev/null +++ b/.github/images/plastic_simple_lightgrey.svg @@ -0,0 +1 @@ +TESTTESTlightgrey \ No newline at end of file diff --git a/.github/images/plastic_simple_orange.svg b/.github/images/plastic_simple_orange.svg new file mode 100644 index 0000000..1fc829f --- /dev/null +++ b/.github/images/plastic_simple_orange.svg @@ -0,0 +1 @@ +TESTTESTorange \ No newline at end of file diff --git a/.github/images/plastic_simple_red.svg b/.github/images/plastic_simple_red.svg new file mode 100644 index 0000000..dc0737b --- /dev/null +++ b/.github/images/plastic_simple_red.svg @@ -0,0 +1 @@ +TESTTESTred \ No newline at end of file diff --git a/.github/images/plastic_simple_success.svg b/.github/images/plastic_simple_success.svg new file mode 100644 index 0000000..6cd1c1f --- /dev/null +++ b/.github/images/plastic_simple_success.svg @@ -0,0 +1 @@ +TESTTESTsuccess \ No newline at end of file diff --git a/.github/images/plastic_simple_yellow.svg b/.github/images/plastic_simple_yellow.svg new file mode 100644 index 0000000..9ca1649 --- /dev/null +++ b/.github/images/plastic_simple_yellow.svg @@ -0,0 +1 @@ +TESTTESTyellow \ No newline at end of file diff --git a/.github/images/plastic_simple_yellowgreen.svg b/.github/images/plastic_simple_yellowgreen.svg new file mode 100644 index 0000000..6d57856 --- /dev/null +++ b/.github/images/plastic_simple_yellowgreen.svg @@ -0,0 +1 @@ +TESTTESTyellowgreen \ No newline at end of file diff --git a/.github/images/plastic_success.svg b/.github/images/plastic_success.svg index 06c80c3..e39ece6 100644 --- a/.github/images/plastic_success.svg +++ b/.github/images/plastic_success.svg @@ -1 +1 @@ -plastic: successplasticsuccess \ No newline at end of file +plastic: successplasticsuccess \ No newline at end of file diff --git a/.github/images/plastic_yellow.svg b/.github/images/plastic_yellow.svg index 236afb2..8d2a55f 100644 --- a/.github/images/plastic_yellow.svg +++ b/.github/images/plastic_yellow.svg @@ -1 +1 @@ -plastic: yellowplasticyellow \ No newline at end of file +plastic: yellowplasticyellow \ No newline at end of file diff --git a/.github/images/plastic_yellowgreen.svg b/.github/images/plastic_yellowgreen.svg index 00242a2..f7c7105 100644 --- a/.github/images/plastic_yellowgreen.svg +++ b/.github/images/plastic_yellowgreen.svg @@ -1 +1 @@ -plastic: yellowgreenplasticyellowgreen \ No newline at end of file +plastic: yellowgreenplasticyellowgreen \ No newline at end of file diff --git a/.github/images/square_blue.svg b/.github/images/square_blue.svg index aeaa4da..94d3bc6 100644 --- a/.github/images/square_blue.svg +++ b/.github/images/square_blue.svg @@ -1 +1 @@ -square: bluesquareblue \ No newline at end of file +square: bluesquareblue \ No newline at end of file diff --git a/.github/images/square_brightgreen.svg b/.github/images/square_brightgreen.svg index 475ed2e..00976be 100644 --- a/.github/images/square_brightgreen.svg +++ b/.github/images/square_brightgreen.svg @@ -1 +1 @@ -square: brightgreensquarebrightgreen \ No newline at end of file +square: brightgreensquarebrightgreen \ No newline at end of file diff --git a/.github/images/square_critical.svg b/.github/images/square_critical.svg index bd1d2df..b422207 100644 --- a/.github/images/square_critical.svg +++ b/.github/images/square_critical.svg @@ -1 +1 @@ -square: criticalsquarecritical \ No newline at end of file +square: criticalsquarecritical \ No newline at end of file diff --git a/.github/images/square_custom.svg b/.github/images/square_custom.svg index d778ed1..e50f693 100644 --- a/.github/images/square_custom.svg +++ b/.github/images/square_custom.svg @@ -1 +1 @@ -square: ff69b4squareff69b4 \ No newline at end of file +square: #ff69b4square#ff69b4 \ No newline at end of file diff --git a/.github/images/square_green.svg b/.github/images/square_green.svg index 519f770..f0358d5 100644 --- a/.github/images/square_green.svg +++ b/.github/images/square_green.svg @@ -1 +1 @@ -square: greensquaregreen \ No newline at end of file +square: greensquaregreen \ No newline at end of file diff --git a/.github/images/square_important.svg b/.github/images/square_important.svg index 27606f3..8d0ecd9 100644 --- a/.github/images/square_important.svg +++ b/.github/images/square_important.svg @@ -1 +1 @@ -square: importantsquareimportant \ No newline at end of file +square: importantsquareimportant \ No newline at end of file diff --git a/.github/images/square_inactive.svg b/.github/images/square_inactive.svg index 4bab468..128a41d 100644 --- a/.github/images/square_inactive.svg +++ b/.github/images/square_inactive.svg @@ -1 +1 @@ -square: inactivesquareinactive \ No newline at end of file +square: inactivesquareinactive \ No newline at end of file diff --git a/.github/images/square_informational.svg b/.github/images/square_informational.svg index 2d7d5b5..d9ff929 100644 --- a/.github/images/square_informational.svg +++ b/.github/images/square_informational.svg @@ -1 +1 @@ -square: informationalsquareinformational \ No newline at end of file +square: informationalsquareinformational \ No newline at end of file diff --git a/.github/images/square_japanese.svg b/.github/images/square_japanese.svg new file mode 100644 index 0000000..8ca7cb7 --- /dev/null +++ b/.github/images/square_japanese.svg @@ -0,0 +1 @@ +ラベル: メッセージラベルメッセージ \ No newline at end of file diff --git a/.github/images/square_lightgrey.svg b/.github/images/square_lightgrey.svg index f6a400f..d8da43c 100644 --- a/.github/images/square_lightgrey.svg +++ b/.github/images/square_lightgrey.svg @@ -1 +1 @@ -square: lightgreysquarelightgrey \ No newline at end of file +square: lightgreysquarelightgrey \ No newline at end of file diff --git a/.github/images/square_orange.svg b/.github/images/square_orange.svg index 525f701..62828a4 100644 --- a/.github/images/square_orange.svg +++ b/.github/images/square_orange.svg @@ -1 +1 @@ -square: orangesquareorange \ No newline at end of file +square: orangesquareorange \ No newline at end of file diff --git a/.github/images/square_red.svg b/.github/images/square_red.svg index 04c3ce0..821b4b7 100644 --- a/.github/images/square_red.svg +++ b/.github/images/square_red.svg @@ -1 +1 @@ -square: redsquarered \ No newline at end of file +square: redsquarered \ No newline at end of file diff --git a/.github/images/square_simple_blue.svg b/.github/images/square_simple_blue.svg new file mode 100644 index 0000000..3cf1f7e --- /dev/null +++ b/.github/images/square_simple_blue.svg @@ -0,0 +1 @@ +blueblue \ No newline at end of file diff --git a/.github/images/square_simple_brightgreen.svg b/.github/images/square_simple_brightgreen.svg new file mode 100644 index 0000000..19a7660 --- /dev/null +++ b/.github/images/square_simple_brightgreen.svg @@ -0,0 +1 @@ +brightgreenbrightgreen \ No newline at end of file diff --git a/.github/images/square_simple_critical.svg b/.github/images/square_simple_critical.svg new file mode 100644 index 0000000..6d6c744 --- /dev/null +++ b/.github/images/square_simple_critical.svg @@ -0,0 +1 @@ +criticalcritical \ No newline at end of file diff --git a/.github/images/square_simple_custom.svg b/.github/images/square_simple_custom.svg new file mode 100644 index 0000000..dcb8b4f --- /dev/null +++ b/.github/images/square_simple_custom.svg @@ -0,0 +1 @@ +#ff69b4#ff69b4 \ No newline at end of file diff --git a/.github/images/square_simple_green.svg b/.github/images/square_simple_green.svg new file mode 100644 index 0000000..ab1eb3b --- /dev/null +++ b/.github/images/square_simple_green.svg @@ -0,0 +1 @@ +greengreen \ No newline at end of file diff --git a/.github/images/square_simple_important.svg b/.github/images/square_simple_important.svg new file mode 100644 index 0000000..88ea336 --- /dev/null +++ b/.github/images/square_simple_important.svg @@ -0,0 +1 @@ +importantimportant \ No newline at end of file diff --git a/.github/images/square_simple_inactive.svg b/.github/images/square_simple_inactive.svg new file mode 100644 index 0000000..84a8038 --- /dev/null +++ b/.github/images/square_simple_inactive.svg @@ -0,0 +1 @@ +inactiveinactive \ No newline at end of file diff --git a/.github/images/square_simple_informational.svg b/.github/images/square_simple_informational.svg new file mode 100644 index 0000000..a38a68d --- /dev/null +++ b/.github/images/square_simple_informational.svg @@ -0,0 +1 @@ +informationalinformational \ No newline at end of file diff --git a/.github/images/square_simple_japanese.svg b/.github/images/square_simple_japanese.svg new file mode 100644 index 0000000..8ca7cb7 --- /dev/null +++ b/.github/images/square_simple_japanese.svg @@ -0,0 +1 @@ +ラベル: メッセージラベルメッセージ \ No newline at end of file diff --git a/.github/images/square_simple_lightgrey.svg b/.github/images/square_simple_lightgrey.svg new file mode 100644 index 0000000..b56efa7 --- /dev/null +++ b/.github/images/square_simple_lightgrey.svg @@ -0,0 +1 @@ +lightgreylightgrey \ No newline at end of file diff --git a/.github/images/square_simple_orange.svg b/.github/images/square_simple_orange.svg new file mode 100644 index 0000000..b6ebef7 --- /dev/null +++ b/.github/images/square_simple_orange.svg @@ -0,0 +1 @@ +orangeorange \ No newline at end of file diff --git a/.github/images/square_simple_red.svg b/.github/images/square_simple_red.svg new file mode 100644 index 0000000..6b2c8e5 --- /dev/null +++ b/.github/images/square_simple_red.svg @@ -0,0 +1 @@ +redred \ No newline at end of file diff --git a/.github/images/square_simple_success.svg b/.github/images/square_simple_success.svg new file mode 100644 index 0000000..0b33ece --- /dev/null +++ b/.github/images/square_simple_success.svg @@ -0,0 +1 @@ +successsuccess \ No newline at end of file diff --git a/.github/images/square_simple_yellow.svg b/.github/images/square_simple_yellow.svg new file mode 100644 index 0000000..e6df125 --- /dev/null +++ b/.github/images/square_simple_yellow.svg @@ -0,0 +1 @@ +yellowyellow \ No newline at end of file diff --git a/.github/images/square_simple_yellowgreen.svg b/.github/images/square_simple_yellowgreen.svg new file mode 100644 index 0000000..a389937 --- /dev/null +++ b/.github/images/square_simple_yellowgreen.svg @@ -0,0 +1 @@ +yellowgreenyellowgreen \ No newline at end of file diff --git a/.github/images/square_success.svg b/.github/images/square_success.svg index 9a9dacd..4a9d802 100644 --- a/.github/images/square_success.svg +++ b/.github/images/square_success.svg @@ -1 +1 @@ -square: successsquaresuccess \ No newline at end of file +square: successsquaresuccess \ No newline at end of file diff --git a/.github/images/square_yellow.svg b/.github/images/square_yellow.svg index fa43fda..40605ce 100644 --- a/.github/images/square_yellow.svg +++ b/.github/images/square_yellow.svg @@ -1 +1 @@ -square: yellowsquareyellow \ No newline at end of file +square: yellowsquareyellow \ No newline at end of file diff --git a/.github/images/square_yellowgreen.svg b/.github/images/square_yellowgreen.svg index 294f829..3dbc363 100644 --- a/.github/images/square_yellowgreen.svg +++ b/.github/images/square_yellowgreen.svg @@ -1 +1 @@ -square: yellowgreensquareyellowgreen \ No newline at end of file +square: yellowgreensquareyellowgreen \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a81805c..8f7c9d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: matrix: - go: [ '1.15.x', '1.16.x' ] + go: [ '1.16.x', '1.17.x' ] steps: - name: Set up Go @@ -106,16 +106,8 @@ jobs: working-directory: ${{env.SRC_DIR}} run: make deps - - name: Install Aligo - working-directory: ${{env.SRC_DIR}} - run: | - wget https://apps.kaos.st/aligo/latest/linux/x86_64/aligo - chmod +x aligo - - - name: Print Aligo version info - working-directory: ${{env.SRC_DIR}} - run: ./aligo --version - - - name: Check Go structs alignment info - working-directory: ${{env.SRC_DIR}} - run: ./aligo check ./... + - name: Check Golang sources with Aligo + uses: essentialkaos/aligo-action@v1 + with: + path: ${{env.SRC_DIR}} + files: ./... diff --git a/README.md b/README.md index 887f5e6..c33973f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ ### Installation -Make sure you have a working Go 1.15+ workspace (_[instructions](https://golang.org/doc/install)_), then: +Make sure you have a working Go 1.16+ workspace (_[instructions](https://golang.org/doc/install)_), then: ````bash go get -d pkg.re/essentialkaos/go-badge.v1 @@ -57,22 +57,25 @@ func main() { ### Examples -| Flat | Flat Square | Plastic | -|------|-------------|---------| -| ![flat](.github/images/flat_brightgreen.svg) | ![square](.github/images/square_brightgreen.svg) | ![plastic](.github/images/plastic_brightgreen.svg) | -| ![flat](.github/images/flat_green.svg) | ![square](.github/images/square_green.svg) | ![plastic](.github/images/plastic_green.svg) | -| ![flat](.github/images/flat_yellowgreen.svg) | ![square](.github/images/square_yellowgreen.svg) | ![plastic](.github/images/plastic_yellowgreen.svg) | -| ![flat](.github/images/flat_yellow.svg) | ![square](.github/images/square_yellow.svg) | ![plastic](.github/images/plastic_yellow.svg) | -| ![flat](.github/images/flat_orange.svg) | ![square](.github/images/square_orange.svg) | ![plastic](.github/images/plastic_orange.svg) | -| ![flat](.github/images/flat_red.svg) | ![square](.github/images/square_red.svg) | ![plastic](.github/images/plastic_red.svg) | -| ![flat](.github/images/flat_blue.svg) | ![square](.github/images/square_blue.svg) | ![plastic](.github/images/plastic_blue.svg) | -| ![flat](.github/images/flat_lightgrey.svg) | ![square](.github/images/square_lightgrey.svg) | ![plastic](.github/images/plastic_lightgrey.svg) | -| ![flat](.github/images/flat_success.svg) | ![square](.github/images/square_success.svg) | ![plastic](.github/images/plastic_success.svg) | -| ![flat](.github/images/flat_important.svg) | ![square](.github/images/square_important.svg) | ![plastic](.github/images/plastic_important.svg) | -| ![flat](.github/images/flat_critical.svg) | ![square](.github/images/square_critical.svg) | ![plastic](.github/images/plastic_critical.svg) | -| ![flat](.github/images/flat_informational.svg) | ![square](.github/images/square_informational.svg) | ![plastic](.github/images/plastic_informational.svg) | -| ![flat](.github/images/flat_inactive.svg) | ![square](.github/images/square_inactive.svg) | ![plastic](.github/images/plastic_inactive.svg) | -| ![flat](.github/images/flat_custom.svg) | ![square](.github/images/square_custom.svg) | ![plastic](.github/images/plastic_custom.svg) | +| Flat | Flat Square | Plastic | Flat (Simple) | Flat Square (Simple) | Plastic (Simple) | +|------|-------------|---------|---------------|----------------------|------------------| +| ![flat](.github/images/flat_flat_brightgreen.svg) | ![square](.github/images/square_flat_brightgreen.svg) | ![plastic](.github/images/plastic_flat_brightgreen.svg) | ![flat-simple](.github/images/flat_simple_flat_brightgreen.svg) | ![square-simple](.github/images/square_simple_flat_brightgreen.svg) | ![plastic-simple](.github/images/plastic_simple_flat_brightgreen.svg) | +| ![flat](.github/images/flat_flat_green.svg) | ![square](.github/images/square_flat_green.svg) | ![plastic](.github/images/plastic_flat_green.svg) | ![flat-simple](.github/images/flat_simple_flat_green.svg) | ![square-simple](.github/images/square_simple_flat_green.svg) | ![plastic-simple](.github/images/plastic_simple_flat_green.svg) | +| ![flat](.github/images/flat_flat_yellowgreen.svg) | ![square](.github/images/square_flat_yellowgreen.svg) | ![plastic](.github/images/plastic_flat_yellowgreen.svg) | ![flat-simple](.github/images/flat_simple_flat_yellowgreen.svg) | ![square-simple](.github/images/square_simple_flat_yellowgreen.svg) | ![plastic-simple](.github/images/plastic_simple_flat_yellowgreen.svg) | +| ![flat](.github/images/flat_flat_yellow.svg) | ![square](.github/images/square_flat_yellow.svg) | ![plastic](.github/images/plastic_flat_yellow.svg) | ![flat-simple](.github/images/flat_simple_flat_yellow.svg) | ![square-simple](.github/images/square_simple_flat_yellow.svg) | ![plastic-simple](.github/images/plastic_simple_flat_yellow.svg) | +| ![flat](.github/images/flat_flat_orange.svg) | ![square](.github/images/square_flat_orange.svg) | ![plastic](.github/images/plastic_flat_orange.svg) | ![flat-simple](.github/images/flat_simple_flat_orange.svg) | ![square-simple](.github/images/square_simple_flat_orange.svg) | ![plastic-simple](.github/images/plastic_simple_flat_orange.svg) | +| ![flat](.github/images/flat_flat_red.svg) | ![square](.github/images/square_flat_red.svg) | ![plastic](.github/images/plastic_flat_red.svg) | ![flat-simple](.github/images/flat_simple_flat_red.svg) | ![square-simple](.github/images/square_simple_flat_red.svg) | ![plastic-simple](.github/images/plastic_simple_flat_red.svg) | +| ![flat](.github/images/flat_flat_blue.svg) | ![square](.github/images/square_flat_blue.svg) | ![plastic](.github/images/plastic_flat_blue.svg) | ![flat-simple](.github/images/flat_simple_flat_blue.svg) | ![square-simple](.github/images/square_simple_flat_blue.svg) | ![plastic-simple](.github/images/plastic_simple_flat_blue.svg) | +| ![flat](.github/images/flat_flat_lightgrey.svg) | ![square](.github/images/square_flat_lightgrey.svg) | ![plastic](.github/images/plastic_flat_lightgrey.svg) | ![flat-simple](.github/images/flat_simple_flat_lightgrey.svg) | ![square-simple](.github/images/square_simple_flat_lightgrey.svg) | ![plastic-simple](.github/images/plastic_simple_flat_lightgrey.svg) | +| ![flat](.github/images/flat_flat_success.svg) | ![square](.github/images/square_flat_success.svg) | ![plastic](.github/images/plastic_flat_success.svg) | ![flat-simple](.github/images/flat_simple_flat_success.svg) | ![square-simple](.github/images/square_simple_flat_success.svg) | ![plastic-simple](.github/images/plastic_simple_flat_success.svg) | +| ![flat](.github/images/flat_flat_important.svg) | ![square](.github/images/square_flat_important.svg) | ![plastic](.github/images/plastic_flat_important.svg) | ![flat-simple](.github/images/flat_simple_flat_important.svg) | ![square-simple](.github/images/square_simple_flat_important.svg) | ![plastic-simple](.github/images/plastic_simple_flat_important.svg) | +| ![flat](.github/images/flat_flat_critical.svg) | ![square](.github/images/square_flat_critical.svg) | ![plastic](.github/images/plastic_flat_critical.svg) | ![flat-simple](.github/images/flat_simple_flat_critical.svg) | ![square-simple](.github/images/square_simple_flat_critical.svg) | ![plastic-simple](.github/images/plastic_simple_flat_critical.svg) | +| ![flat](.github/images/flat_flat_informational.svg) | ![square](.github/images/square_flat_informational.svg) | ![plastic](.github/images/plastic_flat_informational.svg) | ![flat-simple](.github/images/flat_simple_flat_informational.svg) | ![square-simple](.github/images/square_simple_flat_informational.svg) | ![plastic-simple](.github/images/plastic_simple_flat_informational.svg) | +| ![flat](.github/images/flat_flat_inactive.svg) | ![square](.github/images/square_flat_inactive.svg) | ![plastic](.github/images/plastic_flat_inactive.svg) | ![flat-simple](.github/images/flat_simple_flat_inactive.svg) | ![square-simple](.github/images/square_simple_flat_inactive.svg) | ![plastic-simple](.github/images/plastic_simple_flat_inactive.svg) | +| ![flat](.github/images/flat_flat_custom.svg) | ![square](.github/images/square_flat_custom.svg) | ![plastic](.github/images/plastic_flat_custom.svg) | ![flat-simple](.github/images/flat_simple_flat_custom.svg) | ![square-simple](.github/images/square_simple_flat_custom.svg) | ![plastic-simple](.github/images/plastic_simple_flat_custom.svg) | +| ![flat](.github/images/flat_flat_japanese.svg) | ![square](.github/images/square_flat_japanese.svg) | ![plastic](.github/images/plastic_flat_japanese.svg) | ![flat-simple](.github/images/flat_simple_flat_japanese.svg) | ![square-simple](.github/images/square_simple_flat_japanese.svg) | ![plastic-simple](.github/images/plastic_simple_flat_japanese.svg) | + +_All badges are generated with the latest version of the package._ ### Build Status diff --git a/badge.go b/badge.go index adca173..1b3553e 100644 --- a/badge.go +++ b/badge.go @@ -10,6 +10,7 @@ package badge import ( "io/ioutil" + "math" "strconv" "strings" @@ -20,6 +21,9 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // +// VERSION is current package version +const VERSION = "1.2.0" + const ( COLOR_BLUE = "#007ec6" COLOR_BRIGHTGREEN = "#4c1" @@ -45,11 +49,17 @@ const ( // ////////////////////////////////////////////////////////////////////////////////// // -const _TEMPLATE_PLASTIC = `{LABEL}: {MESSAGE}{LABEL}{MESSAGE}` +const _TEMPLATE_PLASTIC = `{LABEL}: {MESSAGE}{LABEL}{MESSAGE}` + +const _TEMPLATE_FLAT = `{LABEL}: {MESSAGE}{LABEL}{MESSAGE}` + +const _TEMPLATE_FLAT_SQUARE = `{LABEL}: {MESSAGE}{LABEL}{MESSAGE}` + +const _TEMPLATE_FLAT_SIMPLE = `{MESSAGE}{MESSAGE}` -const _TEMPLATE_FLAT = `{LABEL}: {MESSAGE}{LABEL}{MESSAGE}` +const _TEMPLATE_PLASTIC_SIMPLE = `TESTTEST{MESSAGE}` -const _TEMPLATE_FLAT_SQUARE = `{LABEL}: {MESSAGE}{LABEL}{MESSAGE}` +const _TEMPLATE_FLAT_SQUARE_SIMPLE = `{MESSAGE}{MESSAGE}` // ////////////////////////////////////////////////////////////////////////////////// // @@ -100,48 +110,158 @@ func NewGenerator(fontFile string, fontSize int) (*Generator, error) { // GeneratePlastic generates SVG badge in plastic style func (g *Generator) GeneratePlastic(label, message, color string) []byte { + if label == "" { + return g.generateBadgeSimple(_TEMPLATE_PLASTIC_SIMPLE, message, color) + } + return g.generateBadge(_TEMPLATE_PLASTIC, label, message, color) } // GenerateFlat generates SVG badge in flat style func (g *Generator) GenerateFlat(label, message, color string) []byte { + if label == "" { + return g.generateBadgeSimple(_TEMPLATE_FLAT_SIMPLE, message, color) + } + return g.generateBadge(_TEMPLATE_FLAT, label, message, color) } // GenerateFlatSquare generates SVG badge in flat-square style func (g *Generator) GenerateFlatSquare(label, message, color string) []byte { + if label == "" { + return g.generateBadgeSimple(_TEMPLATE_FLAT_SQUARE_SIMPLE, message, color) + } + return g.generateBadge(_TEMPLATE_FLAT_SQUARE, label, message, color) } +// GeneratePlasticSimple generates SVG simple badge in plastic style +func (g *Generator) GeneratePlasticSimple(message, color string) []byte { + return g.generateBadgeSimple(_TEMPLATE_PLASTIC_SIMPLE, message, color) +} + +// GenerateFlatSimple generates SVG simple badge in flat style +func (g *Generator) GenerateFlatSimple(message, color string) []byte { + return g.generateBadgeSimple(_TEMPLATE_FLAT_SIMPLE, message, color) +} + +// GenerateFlatSquareSimple generates SVG simple badge in flat-square style +func (g *Generator) GenerateFlatSquareSimple(message, color string) []byte { + return g.generateBadgeSimple(_TEMPLATE_FLAT_SQUARE_SIMPLE, message, color) +} + // ////////////////////////////////////////////////////////////////////////////////// // // generateBadge generates badge with given template func (g *Generator) generateBadge(template, label, message, color string) []byte { - if !strings.HasPrefix(color, "#") { - color = "#" + color - } + color = formatColor(color) - lW := int(g.drawer.MeasureString(label)>>6) + g.Offset - mW := int(g.drawer.MeasureString(message)>>6) + g.Offset + gF := float64(g.Offset) + lW := float64(g.drawer.MeasureString(label)>>6) + gF + mW := float64(g.drawer.MeasureString(message)>>6) + gF fW := lW + mW - lX := ((lW/2 + 1) * 10) + 5 - mX := ((lW + (mW / 2) - 1) * 10) + 5 - lL := int(float64(lW-10) * (10.0 + g.Spacing)) - mL := int(float64(mW-10) * (10.0 + g.Spacing)) + lX := (lW/2 + 1) * 10 + mX := (lW + (mW / 2) - 1) * 10 + lL := (lW - gF) * (10.0 + g.Spacing - 0.5) + mL := (mW - gF) * (10.0 + g.Spacing - 0.5) fS := g.fontSize * 10 + mC, mS := getMessageColors(color) + badge := strings.ReplaceAll(template, "{LABEL}", label) badge = strings.ReplaceAll(badge, "{MESSAGE}", message) - badge = strings.ReplaceAll(badge, "{COLOR}", color) - badge = strings.ReplaceAll(badge, "{WIDTH}", strconv.Itoa(fW)) - badge = strings.ReplaceAll(badge, "{LABEL_WIDTH}", strconv.Itoa(lW)) - badge = strings.ReplaceAll(badge, "{MESSAGE_WIDTH}", strconv.Itoa(mW)) - badge = strings.ReplaceAll(badge, "{LABEL_X}", strconv.Itoa(lX)) - badge = strings.ReplaceAll(badge, "{MESSAGE_X}", strconv.Itoa(mX)) - badge = strings.ReplaceAll(badge, "{LABEL_LENGTH}", strconv.Itoa(lL)) - badge = strings.ReplaceAll(badge, "{MESSAGE_LENGTH}", strconv.Itoa(mL)) + badge = strings.ReplaceAll(badge, "{COLOR}", "#"+color) + badge = strings.ReplaceAll(badge, "{WIDTH}", formatFloat(fW)) + badge = strings.ReplaceAll(badge, "{LABEL_WIDTH}", formatFloat(lW)) + badge = strings.ReplaceAll(badge, "{MESSAGE_WIDTH}", formatFloat(mW)) + badge = strings.ReplaceAll(badge, "{LABEL_X}", formatFloat(lX)) + badge = strings.ReplaceAll(badge, "{MESSAGE_X}", formatFloat(mX)) + badge = strings.ReplaceAll(badge, "{LABEL_LENGTH}", formatFloat(lL)) + badge = strings.ReplaceAll(badge, "{MESSAGE_LENGTH}", formatFloat(mL)) + badge = strings.ReplaceAll(badge, "{MESSAGE_COLOR}", mC) + badge = strings.ReplaceAll(badge, "{MESSAGE_SHADOW}", mS) + badge = strings.ReplaceAll(badge, "{FONT}", g.fontName) + badge = strings.ReplaceAll(badge, "{FONT_SIZE}", strconv.Itoa(fS)) + + return []byte(badge) +} + +// generateBadgeSimple generates badge with given template +func (g *Generator) generateBadgeSimple(template, message, color string) []byte { + color = formatColor(color) + + gF := float64(g.Offset) + fW := float64(g.drawer.MeasureString(message)>>6) + gF + mX := (fW / 2) * 10 + mL := (fW - gF) * (10.0 + g.Spacing) + fS := g.fontSize * 10 + + mC, mS := getMessageColors(color) + + badge := strings.ReplaceAll(template, "{MESSAGE}", message) + badge = strings.ReplaceAll(badge, "{COLOR}", "#"+color) + badge = strings.ReplaceAll(badge, "{WIDTH}", strconv.Itoa(int(fW))) + badge = strings.ReplaceAll(badge, "{MESSAGE_X}", strconv.Itoa(int(mX))) + badge = strings.ReplaceAll(badge, "{MESSAGE_LENGTH}", strconv.Itoa(int(mL))) + badge = strings.ReplaceAll(badge, "{MESSAGE_COLOR}", mC) + badge = strings.ReplaceAll(badge, "{MESSAGE_SHADOW}", mS) badge = strings.ReplaceAll(badge, "{FONT}", g.fontName) badge = strings.ReplaceAll(badge, "{FONT_SIZE}", strconv.Itoa(fS)) return []byte(badge) } + +// ////////////////////////////////////////////////////////////////////////////////// // + +func formatColor(c string) string { + if strings.HasPrefix(c, "#") { + c = strings.TrimLeft(c, "#") + } + + // Short hex + if len(c) == 3 { + c = c + c + } + + return c +} + +// formatFloat formats float values +func formatFloat(v float64) string { + return strconv.FormatFloat(v, 'f', 0, 64) +} + +// getMessageColors returns message text and shadow colors based on color of badge +func getMessageColors(badgeColor string) (string, string) { + c := parseColor(badgeColor) + + if c == 0 || calcLuminance(c) < 0.5 { + return "#fff", "#010101" + } + + return "#333", "#ccc" +} + +// parseColor parses hex color +func parseColor(c string) int { + i, _ := strconv.ParseInt(c, 16, 64) + return int(i) +} + +// calcLuminance calculates relative luminance +func calcLuminance(color int) float64 { + r := calcLumColor(float64(color>>16&0xFF) / 255) + g := calcLumColor(float64(color>>8&0xFF) / 255) + b := calcLumColor(float64(color&0xFF) / 255) + + return 0.2126*r + 0.7152*g + 0.0722*b +} + +// calcLumColor calculates luminance for one color +func calcLumColor(c float64) float64 { + if c <= 0.03928 { + return c / 12.92 + } + + return math.Pow(((c + 0.055) / 1.055), 2.4) +} diff --git a/badge_test.go b/badge_test.go index 8b8a8b6..eb643be 100644 --- a/badge_test.go +++ b/badge_test.go @@ -54,9 +54,9 @@ func (s *BadgeSuite) TestPlastic(c *C) { c.Fatal(err.Error()) } - ourBadge := s.generator.GeneratePlastic("test1", "good", "ff69b4") + ourBadge := s.generator.GeneratePlastic("label", "message", COLOR_RED) - c.Assert(ourBadge, DeepEquals, srcBadge) + c.Assert(string(ourBadge), Equals, string(srcBadge)) } func (s *BadgeSuite) TestFlat(c *C) { @@ -66,19 +66,90 @@ func (s *BadgeSuite) TestFlat(c *C) { c.Fatal(err.Error()) } - ourBadge := s.generator.GenerateFlat("test1", "good", "ff69b4") + ourBadge := s.generator.GenerateFlat("label", "message", COLOR_RED) - c.Assert(ourBadge, DeepEquals, srcBadge) + c.Assert(string(ourBadge), Equals, string(srcBadge)) } func (s *BadgeSuite) TestFlatSquare(c *C) { - srcBadge, err := ioutil.ReadFile("testdata/flat-square.svg") + srcBadge, err := ioutil.ReadFile("testdata/square.svg") if err != nil { c.Fatal(err.Error()) } - ourBadge := s.generator.GenerateFlatSquare("test1", "good", "ff69b4") + ourBadge := s.generator.GenerateFlatSquare("label", "message", COLOR_RED) - c.Assert(ourBadge, DeepEquals, srcBadge) + c.Assert(string(ourBadge), Equals, string(srcBadge)) +} + +func (s *BadgeSuite) TestPlasticSimple(c *C) { + srcBadge, err := ioutil.ReadFile("testdata/plastic_simple.svg") + + if err != nil { + c.Fatal(err.Error()) + } + + ourBadge := s.generator.GeneratePlastic("", "message", COLOR_RED) + c.Assert(string(ourBadge), Equals, string(srcBadge)) + + ourBadge = s.generator.GeneratePlasticSimple("message", COLOR_RED) + c.Assert(string(ourBadge), Equals, string(srcBadge)) +} + +func (s *BadgeSuite) TestFlatSimple(c *C) { + srcBadge, err := ioutil.ReadFile("testdata/flat_simple.svg") + + if err != nil { + c.Fatal(err.Error()) + } + + ourBadge := s.generator.GenerateFlat("", "message", COLOR_RED) + c.Assert(string(ourBadge), Equals, string(srcBadge)) + + ourBadge = s.generator.GenerateFlatSimple("message", COLOR_RED) + c.Assert(string(ourBadge), Equals, string(srcBadge)) +} + +func (s *BadgeSuite) TestFlatSquareSimple(c *C) { + srcBadge, err := ioutil.ReadFile("testdata/square_simple.svg") + + if err != nil { + c.Fatal(err.Error()) + } + + ourBadge := s.generator.GenerateFlatSquare("", "message", COLOR_RED) + c.Assert(string(ourBadge), Equals, string(srcBadge)) + + ourBadge = s.generator.GenerateFlatSquareSimple("message", COLOR_RED) + c.Assert(string(ourBadge), Equals, string(srcBadge)) +} + +func (s *BadgeSuite) TestBlackAndWhite(c *C) { + bb, err := ioutil.ReadFile("testdata/black.svg") + + if err != nil { + c.Fatal(err.Error()) + } + + wb, err := ioutil.ReadFile("testdata/white.svg") + + if err != nil { + c.Fatal(err.Error()) + } + + ourBadge := s.generator.GenerateFlatSimple("message", "#FFFFFF") + c.Assert(string(ourBadge), Equals, string(wb)) + + ourBadge = s.generator.GenerateFlatSimple("message", "#000000") + c.Assert(string(ourBadge), Equals, string(bb)) +} + +func (s *BadgeSuite) TestAux(c *C) { + c.Assert(formatColor("000000"), Equals, "000000") + c.Assert(formatColor("#000000"), Equals, "000000") + c.Assert(formatColor("#000"), Equals, "000000") + + c.Assert(calcLumColor(0.7), Equals, 0.4479884124418833) + c.Assert(calcLumColor(0.01), Equals, 0.0007739938080495357) } diff --git a/testdata/black.svg b/testdata/black.svg new file mode 100644 index 0000000..9289b6e --- /dev/null +++ b/testdata/black.svg @@ -0,0 +1 @@ +messagemessage \ No newline at end of file diff --git a/testdata/flat-square.svg b/testdata/flat-square.svg deleted file mode 100644 index fdb7e3b..0000000 --- a/testdata/flat-square.svg +++ /dev/null @@ -1 +0,0 @@ -test1: goodtest1good \ No newline at end of file diff --git a/testdata/flat.svg b/testdata/flat.svg index 78e2054..f7c966c 100644 --- a/testdata/flat.svg +++ b/testdata/flat.svg @@ -1 +1 @@ -test1: goodtest1good \ No newline at end of file +label: messagelabelmessage \ No newline at end of file diff --git a/testdata/flat_simple.svg b/testdata/flat_simple.svg new file mode 100644 index 0000000..66c478e --- /dev/null +++ b/testdata/flat_simple.svg @@ -0,0 +1 @@ +messagemessage \ No newline at end of file diff --git a/testdata/plastic.svg b/testdata/plastic.svg index 0713c43..c121b2c 100644 --- a/testdata/plastic.svg +++ b/testdata/plastic.svg @@ -1 +1 @@ -test1: goodtest1good \ No newline at end of file +label: messagelabelmessage \ No newline at end of file diff --git a/testdata/plastic_simple.svg b/testdata/plastic_simple.svg new file mode 100644 index 0000000..62e15a3 --- /dev/null +++ b/testdata/plastic_simple.svg @@ -0,0 +1 @@ +TESTTESTmessage \ No newline at end of file diff --git a/testdata/square.svg b/testdata/square.svg new file mode 100644 index 0000000..e6ec58d --- /dev/null +++ b/testdata/square.svg @@ -0,0 +1 @@ +label: messagelabelmessage \ No newline at end of file diff --git a/testdata/square_simple.svg b/testdata/square_simple.svg new file mode 100644 index 0000000..602f825 --- /dev/null +++ b/testdata/square_simple.svg @@ -0,0 +1 @@ +messagemessage \ No newline at end of file diff --git a/testdata/white.svg b/testdata/white.svg new file mode 100644 index 0000000..7c7c717 --- /dev/null +++ b/testdata/white.svg @@ -0,0 +1 @@ +messagemessage \ No newline at end of file