birdbadge/src/response/badge.cpp

58 lines
2.6 KiB
C++

#include "badge.h"
constexpr const char* openBracket("<");
constexpr const char* closeBracket(">");
constexpr const char* svgTag("svg");
constexpr const char* titleTag("title");
constexpr const char* svgAttrs =
"xmlns=\"http://www.w3.org/2000/svg\" "
"xmlns:xlink=\"http://www.w3.org/1999/xlink\" "
"width=\"134\" "
"height=\"20\" "
"role=\"img\"";
constexpr const char* ariaLabel("aria-label");
Badge::Badge(Badge::Kind kind, const std::string& title, const std::string& value, const std::string& color):
Response(Type::image),
kind(kind),
title(title),
value(value),
color(color)
{}
Badge::~Badge() {}
void Badge::writeHeader(std::ostream& out) const {
out << status200Header << newLine;
out << contentTypeSVG;
out << headerTerminator;
}
void Badge::writeBody(std::ostream& out) const {
out << openBracket << svgTag << " ";
out << svgAttrs << " ";
out << ariaLabel << "=\"" << title << ": " << value << "\"";
out << closeBracket;
out << openBracket << titleTag << closeBracket;
out << title << ": " << value;
out << openBracket << "/" << titleTag << closeBracket;
//may be gradients
//may be round corners
out << "<rect width=\"100\" height=\"20\" fill=\"#dddddd\" />";
out << "<rect x=\"100\" width=\"34\" height=\"20\" fill=\"#0044dd\" />";
out << openBracket << "/" << svgTag << closeBracket;
}
/**
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="134" height="20" role="img" aria-label="Documentation: HTML"><title>Documentation: HTML</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="134" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="93" height="20" fill="#555"/><rect x="93" width="41" height="20" fill="#97ca00"/><rect width="134" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="475" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="830">Documentation</text><text x="475" y="140" transform="scale(.1)" fill="#fff" textLength="830">Documentation</text><text aria-hidden="true" x="1125" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="310">HTML</text><text x="1125" y="140" transform="scale(.1)" fill="#fff" textLength="310">HTML</text></g></svg>
*/