Add emoji examples to documentation (#74)

Closes #43
This commit is contained in:
Jon Grace-Cox
2022-08-14 12:33:12 -04:00
committed by GitHub
parent ea2eccd948
commit 34374dbc2b
2 changed files with 58 additions and 1 deletions

View File

@@ -161,6 +161,35 @@ Available named colors are:
| yellow | #DFB317 | ![](https://cdn.rawgit.com/jongracecox/anybadge/master/examples/color_yellow.svg) |
| yellow_green | #A4A61D | ![](https://cdn.rawgit.com/jongracecox/anybadge/master/examples/color_yellow_green.svg) |
### Emojis
It is possible to use emoji characters in badge labels and values. Here are some examples:
![](https://cdn.rawgit.com/jongracecox/anybadge/master/examples/pipeline_frown.svg)
![](https://cdn.rawgit.com/jongracecox/anybadge/master/examples/pipeline_smile.svg)
![](https://cdn.rawgit.com/jongracecox/anybadge/master/examples/documentation_link.svg)
![](https://cdn.rawgit.com/jongracecox/anybadge/master/examples/pypi_link.svg)
These files were created by using the **actual** emoji character in the label/value text. For example:
```python
badge = anybadge.Badge(label="Pipeline status", value="😄")
```
There are some caveats worth mentioning:
- The "look" of the emoji is determined by the client (Emoji characters are placed as-is into the SVG file, and are
rendered client-side)
- Rendering may fail in some viewers and developer IDEs (for example, PyCharm does not render emojis in the svg viewer)
- Emojis can have different widths, so the layout may be affected. You can use `num_label_padding_chars` and
`num_value_padding_chars` to fix (see below)
Here are some examples to show how to use padding to fix layout:
| Badge | Code |
| ----- |----------------------------------------------------------------------|
| ![](https://cdn.rawgit.com/jongracecox/anybadge/master/examples/pipeline_smile.svg) | `anybadge.Badge("Pipeline status", "😄")` |
| ![](https://cdn.rawgit.com/jongracecox/anybadge/master/examples/pipeline_smile_padding.svg) | `anybadge.Badge("Pipeline status", "😄", num_value_padding_chars=1)` |
### Semantic version support
Anybadge supports semantic versions for value and threshold keys. This supports color-coded

View File

@@ -1,7 +1,10 @@
from pathlib import Path
import anybadge
def main():
def color_examples_table():
"""Output the Markdown table containing color examples."""
print(
"""
| Color Name | Hex | Example |
@@ -21,5 +24,30 @@ def main():
)
def emoji_examples():
"""Generate emoji example badges used in documentation."""
examples_dir = Path(__file__).parent / Path("examples")
for label, value, file, kwargs in [
("Pipeline status", "😄", "pipeline_smile.svg", {}),
(
"Pipeline status",
"😄",
"pipeline_smile_padding.svg",
{"num_value_padding_chars": 1},
),
("Pipeline status", "😟", "pipeline_frown.svg", {"default_color": "Red"}),
("🔗", "Documentation", "documentation_link.svg", {}),
("🔗", "PyPi", "pypi_link.svg", {}),
]:
anybadge.Badge(label=label, value=value, **kwargs).write_badge(
examples_dir / Path(file), overwrite=True
)
def main():
color_examples_table()
emoji_examples()
if __name__ == "__main__":
main()