aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/messagebus/www/html_output.h
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commit1f553f46fb4f3c5eec631352cdd900a0709016af (patch)
treea231fba2c03b440becaea6c86a2702d0bfb0336e /library/cpp/messagebus/www/html_output.h
parentc4de7efdedc25b49cbea74bd589eecb61b55b60a (diff)
downloadydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/www/html_output.h')
-rw-r--r--library/cpp/messagebus/www/html_output.h548
1 files changed, 274 insertions, 274 deletions
diff --git a/library/cpp/messagebus/www/html_output.h b/library/cpp/messagebus/www/html_output.h
index 27e77adefa..ff1c5da17b 100644
--- a/library/cpp/messagebus/www/html_output.h
+++ b/library/cpp/messagebus/www/html_output.h
@@ -1,37 +1,37 @@
-#pragma once
-
+#pragma once
+
#include "concat_strings.h"
#include <util/generic/string.h>
-#include <util/stream/output.h>
+#include <util/stream/output.h>
#include <library/cpp/html/pcdata/pcdata.h>
-#include <util/system/tls.h>
-
+#include <util/system/tls.h>
+
extern Y_POD_THREAD(IOutputStream*) HtmlOutputStreamPtr;
-
+
static IOutputStream& HtmlOutputStream() {
Y_VERIFY(!!HtmlOutputStreamPtr);
- return *HtmlOutputStreamPtr;
-}
-
-struct THtmlOutputStreamPushPop {
+ return *HtmlOutputStreamPtr;
+}
+
+struct THtmlOutputStreamPushPop {
IOutputStream* const Prev;
-
+
THtmlOutputStreamPushPop(IOutputStream* outputStream)
- : Prev(HtmlOutputStreamPtr)
- {
- HtmlOutputStreamPtr = outputStream;
- }
-
- ~THtmlOutputStreamPushPop() {
- HtmlOutputStreamPtr = Prev;
- }
-};
-
-struct TChars {
+ : Prev(HtmlOutputStreamPtr)
+ {
+ HtmlOutputStreamPtr = outputStream;
+ }
+
+ ~THtmlOutputStreamPushPop() {
+ HtmlOutputStreamPtr = Prev;
+ }
+};
+
+struct TChars {
TString Text;
- bool NeedEscape;
-
+ bool NeedEscape;
+
TChars(TStringBuf text)
: Text(text)
, NeedEscape(true)
@@ -52,273 +52,273 @@ struct TChars {
, NeedEscape(escape)
{
}
-
+
TString Escape() {
- if (NeedEscape) {
- return EncodeHtmlPcdata(Text);
- } else {
- return Text;
- }
- }
-};
-
-struct TAttr {
+ if (NeedEscape) {
+ return EncodeHtmlPcdata(Text);
+ } else {
+ return Text;
+ }
+ }
+};
+
+struct TAttr {
TString Name;
TString Value;
-
- TAttr(TStringBuf name, TStringBuf value)
+
+ TAttr(TStringBuf name, TStringBuf value)
: Name(name)
, Value(value)
{
}
-
+
TAttr() {
}
-
- bool operator!() const {
- return !Name;
- }
-};
-
-static inline void Doctype() {
- HtmlOutputStream() << "<!doctype html>\n";
-}
-
-static inline void Nl() {
- HtmlOutputStream() << "\n";
-}
-
-static inline void Sp() {
- HtmlOutputStream() << " ";
-}
-
-static inline void Text(TStringBuf text) {
- HtmlOutputStream() << EncodeHtmlPcdata(text);
-}
-
-static inline void Line(TStringBuf text) {
- Text(text);
- Nl();
-}
-
-static inline void WriteAttr(TAttr a) {
- if (!!a) {
- HtmlOutputStream() << " " << a.Name << "='" << EncodeHtmlPcdata(a.Value) << "'";
- }
-}
-
-static inline void Open(TStringBuf tag, TAttr a1 = TAttr(), TAttr a2 = TAttr(), TAttr a3 = TAttr(), TAttr a4 = TAttr()) {
- HtmlOutputStream() << "<" << tag;
- WriteAttr(a1);
- WriteAttr(a2);
- WriteAttr(a3);
- WriteAttr(a4);
- HtmlOutputStream() << ">";
-}
-
-static inline void Open(TStringBuf tag, TStringBuf cssClass, TStringBuf id = "") {
- Open(tag, TAttr("class", cssClass), !!id ? TAttr("id", id) : TAttr());
-}
-
-static inline void OpenBlock(TStringBuf tag, TStringBuf cssClass = "") {
- Open(tag, cssClass);
- Nl();
-}
-
-static inline void Close(TStringBuf tag) {
- HtmlOutputStream() << "</" << tag << ">\n";
-}
-
-static inline void CloseBlock(TStringBuf tag) {
- Close(tag);
- Nl();
-}
-
-static inline void TagWithContent(TStringBuf tag, TChars content) {
- HtmlOutputStream() << "<" << tag << ">" << content.Escape() << "</" << tag << ">";
-}
-
-static inline void BlockTagWithContent(TStringBuf tag, TStringBuf content) {
- TagWithContent(tag, content);
- Nl();
-}
-
-static inline void TagWithClass(TStringBuf tag, TStringBuf cssClass) {
- Open(tag, cssClass);
- Close(tag);
-}
-
-static inline void Hn(unsigned n, TStringBuf title) {
- BlockTagWithContent(ConcatStrings("h", n), title);
-}
-
-static inline void Small(TStringBuf text) {
- TagWithContent("small", text);
-}
-
-static inline void HnWithSmall(unsigned n, TStringBuf title, TStringBuf small) {
+
+ bool operator!() const {
+ return !Name;
+ }
+};
+
+static inline void Doctype() {
+ HtmlOutputStream() << "<!doctype html>\n";
+}
+
+static inline void Nl() {
+ HtmlOutputStream() << "\n";
+}
+
+static inline void Sp() {
+ HtmlOutputStream() << " ";
+}
+
+static inline void Text(TStringBuf text) {
+ HtmlOutputStream() << EncodeHtmlPcdata(text);
+}
+
+static inline void Line(TStringBuf text) {
+ Text(text);
+ Nl();
+}
+
+static inline void WriteAttr(TAttr a) {
+ if (!!a) {
+ HtmlOutputStream() << " " << a.Name << "='" << EncodeHtmlPcdata(a.Value) << "'";
+ }
+}
+
+static inline void Open(TStringBuf tag, TAttr a1 = TAttr(), TAttr a2 = TAttr(), TAttr a3 = TAttr(), TAttr a4 = TAttr()) {
+ HtmlOutputStream() << "<" << tag;
+ WriteAttr(a1);
+ WriteAttr(a2);
+ WriteAttr(a3);
+ WriteAttr(a4);
+ HtmlOutputStream() << ">";
+}
+
+static inline void Open(TStringBuf tag, TStringBuf cssClass, TStringBuf id = "") {
+ Open(tag, TAttr("class", cssClass), !!id ? TAttr("id", id) : TAttr());
+}
+
+static inline void OpenBlock(TStringBuf tag, TStringBuf cssClass = "") {
+ Open(tag, cssClass);
+ Nl();
+}
+
+static inline void Close(TStringBuf tag) {
+ HtmlOutputStream() << "</" << tag << ">\n";
+}
+
+static inline void CloseBlock(TStringBuf tag) {
+ Close(tag);
+ Nl();
+}
+
+static inline void TagWithContent(TStringBuf tag, TChars content) {
+ HtmlOutputStream() << "<" << tag << ">" << content.Escape() << "</" << tag << ">";
+}
+
+static inline void BlockTagWithContent(TStringBuf tag, TStringBuf content) {
+ TagWithContent(tag, content);
+ Nl();
+}
+
+static inline void TagWithClass(TStringBuf tag, TStringBuf cssClass) {
+ Open(tag, cssClass);
+ Close(tag);
+}
+
+static inline void Hn(unsigned n, TStringBuf title) {
+ BlockTagWithContent(ConcatStrings("h", n), title);
+}
+
+static inline void Small(TStringBuf text) {
+ TagWithContent("small", text);
+}
+
+static inline void HnWithSmall(unsigned n, TStringBuf title, TStringBuf small) {
TString tagName = ConcatStrings("h", n);
- Open(tagName);
- HtmlOutputStream() << title;
- Sp();
- Small(small);
- Close(tagName);
-}
-
-static inline void H1(TStringBuf title) {
- Hn(1, title);
-}
-
-static inline void H2(TStringBuf title) {
- Hn(2, title);
-}
-
-static inline void H3(TStringBuf title) {
- Hn(3, title);
-}
-
-static inline void H4(TStringBuf title) {
- Hn(4, title);
-}
-
-static inline void H5(TStringBuf title) {
- Hn(5, title);
-}
-
-static inline void H6(TStringBuf title) {
- Hn(6, title);
-}
-
-static inline void Pre(TStringBuf content) {
- HtmlOutputStream() << "<pre>" << EncodeHtmlPcdata(content) << "</pre>\n";
-}
-
-static inline void Li(TStringBuf content) {
- BlockTagWithContent("li", content);
-}
-
-static inline void LiWithClass(TStringBuf cssClass, TStringBuf content) {
- Open("li", cssClass);
- Text(content);
- Close("li");
-}
-
-static inline void OpenA(TStringBuf href) {
- Open("a", TAttr("href", href));
-}
-
-static inline void A(TStringBuf href, TStringBuf text) {
- OpenA(href);
- Text(text);
- Close("a");
-}
-
-static inline void Td(TStringBuf content) {
- TagWithContent("td", content);
-}
-
-static inline void Th(TStringBuf content, TStringBuf cssClass = "") {
- OpenBlock("th", cssClass);
- Text(content);
- CloseBlock("th");
-}
-
-static inline void DivWithClassAndContent(TStringBuf cssClass, TStringBuf content) {
- Open("div", cssClass);
- Text(content);
- Close("div");
-}
-
-static inline void BootstrapError(TStringBuf text) {
- DivWithClassAndContent("alert alert-danger", text);
-}
-
-static inline void BootstrapInfo(TStringBuf text) {
- DivWithClassAndContent("alert alert-info", text);
-}
-
-static inline void ScriptHref(TStringBuf href) {
- Open("script",
+ Open(tagName);
+ HtmlOutputStream() << title;
+ Sp();
+ Small(small);
+ Close(tagName);
+}
+
+static inline void H1(TStringBuf title) {
+ Hn(1, title);
+}
+
+static inline void H2(TStringBuf title) {
+ Hn(2, title);
+}
+
+static inline void H3(TStringBuf title) {
+ Hn(3, title);
+}
+
+static inline void H4(TStringBuf title) {
+ Hn(4, title);
+}
+
+static inline void H5(TStringBuf title) {
+ Hn(5, title);
+}
+
+static inline void H6(TStringBuf title) {
+ Hn(6, title);
+}
+
+static inline void Pre(TStringBuf content) {
+ HtmlOutputStream() << "<pre>" << EncodeHtmlPcdata(content) << "</pre>\n";
+}
+
+static inline void Li(TStringBuf content) {
+ BlockTagWithContent("li", content);
+}
+
+static inline void LiWithClass(TStringBuf cssClass, TStringBuf content) {
+ Open("li", cssClass);
+ Text(content);
+ Close("li");
+}
+
+static inline void OpenA(TStringBuf href) {
+ Open("a", TAttr("href", href));
+}
+
+static inline void A(TStringBuf href, TStringBuf text) {
+ OpenA(href);
+ Text(text);
+ Close("a");
+}
+
+static inline void Td(TStringBuf content) {
+ TagWithContent("td", content);
+}
+
+static inline void Th(TStringBuf content, TStringBuf cssClass = "") {
+ OpenBlock("th", cssClass);
+ Text(content);
+ CloseBlock("th");
+}
+
+static inline void DivWithClassAndContent(TStringBuf cssClass, TStringBuf content) {
+ Open("div", cssClass);
+ Text(content);
+ Close("div");
+}
+
+static inline void BootstrapError(TStringBuf text) {
+ DivWithClassAndContent("alert alert-danger", text);
+}
+
+static inline void BootstrapInfo(TStringBuf text) {
+ DivWithClassAndContent("alert alert-info", text);
+}
+
+static inline void ScriptHref(TStringBuf href) {
+ Open("script",
TAttr("language", "javascript"),
TAttr("type", "text/javascript"),
TAttr("src", href));
- Close("script");
- Nl();
-}
-
-static inline void LinkStylesheet(TStringBuf href) {
- Open("link", TAttr("rel", "stylesheet"), TAttr("href", href));
- Close("link");
- Nl();
-}
-
-static inline void LinkFavicon(TStringBuf href) {
- Open("link", TAttr("rel", "shortcut icon"), TAttr("href", href));
- Close("link");
- Nl();
-}
-
-static inline void Title(TChars title) {
- TagWithContent("title", title);
- Nl();
-}
-
-static inline void Code(TStringBuf content) {
- TagWithContent("code", content);
-}
-
-struct TTagGuard {
+ Close("script");
+ Nl();
+}
+
+static inline void LinkStylesheet(TStringBuf href) {
+ Open("link", TAttr("rel", "stylesheet"), TAttr("href", href));
+ Close("link");
+ Nl();
+}
+
+static inline void LinkFavicon(TStringBuf href) {
+ Open("link", TAttr("rel", "shortcut icon"), TAttr("href", href));
+ Close("link");
+ Nl();
+}
+
+static inline void Title(TChars title) {
+ TagWithContent("title", title);
+ Nl();
+}
+
+static inline void Code(TStringBuf content) {
+ TagWithContent("code", content);
+}
+
+struct TTagGuard {
const TString TagName;
-
- TTagGuard(TStringBuf tagName, TStringBuf cssClass, TStringBuf id = "")
- : TagName(tagName)
+
+ TTagGuard(TStringBuf tagName, TStringBuf cssClass, TStringBuf id = "")
+ : TagName(tagName)
+ {
+ Open(TagName, cssClass, id);
+ }
+
+ TTagGuard(TStringBuf tagName, TAttr a1 = TAttr(), TAttr a2 = TAttr(), TAttr a3 = TAttr(), TAttr a4 = TAttr())
+ : TagName(tagName)
+ {
+ Open(tagName, a1, a2, a3, a4);
+ }
+
+ ~TTagGuard() {
+ Close(TagName);
+ }
+};
+
+struct TDivGuard: public TTagGuard {
+ TDivGuard(TStringBuf cssClass, TStringBuf id = "")
+ : TTagGuard("div", cssClass, id)
{
- Open(TagName, cssClass, id);
}
-
- TTagGuard(TStringBuf tagName, TAttr a1 = TAttr(), TAttr a2 = TAttr(), TAttr a3 = TAttr(), TAttr a4 = TAttr())
- : TagName(tagName)
- {
- Open(tagName, a1, a2, a3, a4);
- }
-
- ~TTagGuard() {
- Close(TagName);
- }
-};
-
-struct TDivGuard: public TTagGuard {
- TDivGuard(TStringBuf cssClass, TStringBuf id = "")
- : TTagGuard("div", cssClass, id)
+
+ TDivGuard(TAttr a1 = TAttr(), TAttr a2 = TAttr(), TAttr a3 = TAttr())
+ : TTagGuard("div", a1, a2, a3)
{
}
-
- TDivGuard(TAttr a1 = TAttr(), TAttr a2 = TAttr(), TAttr a3 = TAttr())
- : TTagGuard("div", a1, a2, a3)
- {
- }
-};
-
-struct TAGuard {
+};
+
+struct TAGuard {
TAGuard(TStringBuf href) {
- OpenA(href);
- }
-
- ~TAGuard() {
- Close("a");
- }
-};
-
-struct TScriptFunctionGuard {
- TTagGuard Script;
-
- TScriptFunctionGuard()
- : Script("script")
- {
- Line("$(function() {");
- }
-
+ OpenA(href);
+ }
+
+ ~TAGuard() {
+ Close("a");
+ }
+};
+
+struct TScriptFunctionGuard {
+ TTagGuard Script;
+
+ TScriptFunctionGuard()
+ : Script("script")
+ {
+ Line("$(function() {");
+ }
+
~TScriptFunctionGuard() {
- Line("});");
- }
-};
+ Line("});");
+ }
+};