xartigas pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=4673120a19c7ffb76c191e4ec248d65b4788f35b

commit 4673120a19c7ffb76c191e4ec248d65b4788f35b
Author: Xavi Artigas <xavierarti...@yahoo.es>
Date:   Tue Sep 17 12:02:19 2019 +0200

    mono-docs: Allow embedding examples in XML format
    
    XML examples must provide their own <example> and <code> tags, and these
    tags MUST be escaped: \< \> \" etc.
    This is more inconvenient, but it allows adding explanatory text outside
    the <code> and inside the <example>.
    Examples are first looked for in XML format, and if not found, in CS format.
---
 src/bin/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<options_context>(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);
    }
 

-- 


Reply via email to