From 748070125ff43c001feb8e191cf2be8d0f59d01d Mon Sep 17 00:00:00 2001 From: Xavi Artigas Date: Thu, 11 Apr 2019 10:37:33 +0200 Subject: [PATCH] efl-mono: Allow doc XML tags to be nested Summary: This allows inserting nested tags like: bla bla bla The generate_tag_example() is currently unused but serves as an example. Depends on D8585 Test Plan: Not much, unless you want to manually call generate_tag_example() (Which I have done, and it works, I promise). Reviewers: lauromoura, vitor.sousa Reviewed By: vitor.sousa Subscribers: vitor.sousa, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8587 --- .../eolian_mono/eolian/mono/documentation.hh | 40 +++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/bin/eolian_mono/eolian/mono/documentation.hh b/src/bin/eolian_mono/eolian/mono/documentation.hh index e7666a922c..c46cbd4231 100644 --- a/src/bin/eolian_mono/eolian/mono/documentation.hh +++ b/src/bin/eolian_mono/eolian/mono/documentation.hh @@ -244,7 +244,19 @@ struct documentation_generator /// Tag generator helpers template - bool generate_tag(OutputIterator sink, std::string const& tag, std::string const &text, Context const& context, std::string tag_params = "") const + bool generate_opening_tag(OutputIterator sink, std::string const& tag, Context const& context, std::string tag_params = "") const + { + return as_generator("<" << tag << tag_params << ">").generate(sink, attributes::unused, context); + } + + template + bool generate_closing_tag(OutputIterator sink, std::string const& tag, Context const& context) const + { + return as_generator("").generate(sink, attributes::unused, context); + } + + template + bool generate_escaped_content(OutputIterator sink, std::string const &text, Context const& context) const { std::string new_text; if (!as_generator(html_escaped_string).generate(std::back_inserter(new_text), text, context)) @@ -256,14 +268,24 @@ struct documentation_generator std::istringstream ss(new_text); std::string para; - std::string final_text = "<" + tag + tag_params + ">"; + std::string final_text; bool first = true; while (std::getline(ss, para)) { if (first) final_text += para; else final_text += "\n" + tabs + para; first = false; } - return as_generator(scope_tab(scope_size) << "/// " << final_text << "\n").generate(sink, attributes::unused, context); + return as_generator(final_text).generate(sink, attributes::unused, context); + } + + template + bool generate_tag(OutputIterator sink, std::string const& tag, std::string const &text, Context const& context, std::string tag_params = "") const + { + if (!as_generator(scope_tab(scope_size) << "/// ").generate(sink, attributes::unused, context)) return false; + if (!generate_opening_tag(sink, tag, context, tag_params)) return false; + if (!generate_escaped_content(sink, text, context)) return false; + if (!generate_closing_tag(sink, tag, context)) return false; + return as_generator("\n").generate(sink, attributes::unused, context); } template @@ -290,6 +312,18 @@ struct documentation_generator return generate_tag(sink, "value", text, context); } + template + bool generate_tag_example(OutputIterator sink, std::string const& example, Context const& context) const + { + if (!as_generator(scope_tab(scope_size) << "/// ").generate(sink, attributes::unused, context)) return false; + if (!generate_opening_tag(sink, "example", context)) return false; + if (!generate_opening_tag(sink, "code", context)) return false; + if (!generate_escaped_content(sink, example, context)) return false; + if (!generate_closing_tag(sink, "code", context)) return false; + if (!generate_closing_tag(sink, "example", context)) return false; + return as_generator("\n").generate(sink, attributes::unused, context); + } + // Actual exported generators template bool generate(OutputIterator sink, Attribute const& attr, Context const& context) const