22 #include "compose.hpp"
25 #include <boost/filesystem.hpp>
45 : _formatter(formatter)
49 Wrap(
Formatter* formatter, std::string
const& close, std::function<
void ()> closer)
50 : _formatter(formatter)
57 std::swap(_formatter, other._formatter);
58 std::swap(_close, other._close);
59 std::swap(_closer, other._closer);
65 _formatter->file().
puts(_close.c_str());
75 std::function<void ()> _closer =
nullptr;
78 virtual Wrap document() {
return {}; }
80 virtual void heading(std::string
const& text) = 0;
81 virtual void subheading(std::string
const& text) = 0;
82 virtual Wrap body() {
return {}; }
84 virtual Wrap unordered_list() = 0;
85 virtual void list_item(std::string
const& text, boost::optional<std::string> type = {}) = 0;
87 virtual std::function<std::string (std::string)> process_string() = 0;
88 virtual std::function<std::string (std::string)> process_filename() = 0;
106 void heading(std::string
const& text)
override {
110 void subheading(std::string
const& text)
override {
115 Wrap unordered_list()
override {
117 return Wrap(
this,
"", [
this]() { _indent--; });
120 void list_item(std::string
const& text, boost::optional<std::string> type = {})
override {
122 for (
int i = 0; i < _indent * 2; ++i) {
129 std::function<std::string (std::string)> process_string()
override {
130 return [](std::string s) {
135 std::function<std::string (std::string)> process_filename()
override {
136 return [](std::string s) {
142 void print(std::string
const& text) {
143 _file.
puts(text.c_str());
158 void heading(std::string
const& text)
override {
162 void subheading(std::string
const& text)
override {
166 Wrap document()
override {
167 auto html = wrapped(
"html");
168 auto head = wrapped(
"head");
169 auto style = wrapped(
"style");
172 " padding: 2px 2px 2px 1em;\n"
175 _file.
puts(
"li.ok {\n"
176 " background-color: #00ff00;\n"
179 " background-color: #ffa500;\n"
182 " background-color: #ff0000;\n"
185 " background-color: #ff6666;\n"
188 " list-style: none;\n"
194 Wrap body()
override {
195 return wrapped(
"body");
198 Wrap unordered_list()
override {
199 return wrapped(
"ul");
202 void list_item(std::string
const& text, boost::optional<std::string> type = {})
override {
204 _file.
puts(dcp::String::compose(
"<li class=\"%1\">%2", *type, text).c_str());
206 _file.
puts(dcp::String::compose(
"<li>%1", text).c_str());
210 std::function<std::string (std::string)> process_string()
override {
211 return [](std::string s) {
212 boost::replace_all(s,
"<",
"<");
213 boost::replace_all(s,
">",
">");
218 std::function<std::string (std::string)> process_filename()
override {
219 return [](std::string s) {
220 return String::compose(
"<code>%1</code>", s);
225 void tagged(std::string tag, std::string content) {
226 _file.
puts(String::compose(
"<%1>%2</%3>\n", tag, content, tag).c_str());
229 Wrap wrapped(std::string
const& tag) {
230 _file.
puts(String::compose(
"<%1>", tag).c_str());
231 return Wrap(
this, String::compose(
"</%1>", tag));
Namespace for everything in libdcp.
dcp::verify() method and associated code