From 4673120a19c7ffb76c191e4ec248d65b4788f35b Mon Sep 17 00:00:00 2001 From: Xavi Artigas Date: Tue, 17 Sep 2019 12:02:19 +0200 Subject: [PATCH] mono-docs: Allow embedding examples in XML format XML examples must provide their own and tags, and these tags MUST be escaped: \< \> \" etc. This is more inconvenient, but it allows adding explanatory text outside the and inside the . Examples are first looked for in XML format, and if not found, in CS format. --- .../eolian_mono/eolian/mono/documentation.hh | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/bin/eolian_mono/eolian/mono/documentation.hh b/src/bin/eolian_mono/eolian/mono/documentation.hh index 6cf57fd342..201ee168a9 100644 --- a/src/bin/eolian_mono/eolian/mono/documentation.hh +++ b/src/bin/eolian_mono/eolian/mono/documentation.hh @@ -367,20 +367,34 @@ struct documentation_generator auto options = efl::eolian::grammar::context_find_tag(context); // Example embedding not requested if (options.examples_dir.empty()) return true; - std::string file_name = options.examples_dir + full_object_name + ".cs"; + bool is_plain_code = false; + std::string file_name = options.examples_dir + full_object_name + ".xml"; std::ifstream exfile(file_name); - // There is no example file for this class or method, just return - if (!exfile.good()) return true; + if (!exfile.good()) + { + // There is no example XML file for this class, try a CS file + file_name = options.examples_dir + full_object_name + ".cs"; + exfile.open(file_name); + // There are no example files for this class or method, just return + if (!exfile.good()) return true; + is_plain_code = true; + } std::stringstream example_buff; // Start with a newline so the first line renders with same indentation as the rest example_buff << std::endl << exfile.rdbuf(); 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 (is_plain_code) + { + if (!generate_opening_tag(sink, "example", context)) return false; + if (!generate_opening_tag(sink, "code", context)) return false; + } if (!generate_escaped_content(sink, example_buff.str(), context)) return false; - if (!generate_closing_tag(sink, "code", context)) return false; - if (!generate_closing_tag(sink, "example", context)) return false; + if (is_plain_code) + { + 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); }