summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2019-09-17 12:02:19 +0200
committerXavi Artigas <xavierartigas@yahoo.es>2019-09-17 12:02:19 +0200
commit4673120a19c7ffb76c191e4ec248d65b4788f35b (patch)
tree6d31d75aa325d3c34259d7bd38998646b3a638d1 /src/bin
parent24ed24a9db3cb947084ce446b0b1c130852071d5 (diff)
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.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/eolian_mono/eolian/mono/documentation.hh28
1 files 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 6cf57fd..201ee16 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
367 auto options = efl::eolian::grammar::context_find_tag<options_context>(context); 367 auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
368 // Example embedding not requested 368 // Example embedding not requested
369 if (options.examples_dir.empty()) return true; 369 if (options.examples_dir.empty()) return true;
370 std::string file_name = options.examples_dir + full_object_name + ".cs"; 370 bool is_plain_code = false;
371 std::string file_name = options.examples_dir + full_object_name + ".xml";
371 std::ifstream exfile(file_name); 372 std::ifstream exfile(file_name);
372 // There is no example file for this class or method, just return 373 if (!exfile.good())
373 if (!exfile.good()) return true; 374 {
375 // There is no example XML file for this class, try a CS file
376 file_name = options.examples_dir + full_object_name + ".cs";
377 exfile.open(file_name);
378 // There are no example files for this class or method, just return
379 if (!exfile.good()) return true;
380 is_plain_code = true;
381 }
374 std::stringstream example_buff; 382 std::stringstream example_buff;
375 // Start with a newline so the first line renders with same indentation as the rest 383 // Start with a newline so the first line renders with same indentation as the rest
376 example_buff << std::endl << exfile.rdbuf(); 384 example_buff << std::endl << exfile.rdbuf();
377 385
378 if (!as_generator(scope_tab(scope_size) << "/// ").generate(sink, attributes::unused, context)) return false; 386 if (!as_generator(scope_tab(scope_size) << "/// ").generate(sink, attributes::unused, context)) return false;
379 if (!generate_opening_tag(sink, "example", context)) return false; 387 if (is_plain_code)
380 if (!generate_opening_tag(sink, "code", context)) return false; 388 {
389 if (!generate_opening_tag(sink, "example", context)) return false;
390 if (!generate_opening_tag(sink, "code", context)) return false;
391 }
381 if (!generate_escaped_content(sink, example_buff.str(), context)) return false; 392 if (!generate_escaped_content(sink, example_buff.str(), context)) return false;
382 if (!generate_closing_tag(sink, "code", context)) return false; 393 if (is_plain_code)
383 if (!generate_closing_tag(sink, "example", context)) return false; 394 {
395 if (!generate_closing_tag(sink, "code", context)) return false;
396 if (!generate_closing_tag(sink, "example", context)) return false;
397 }
384 return as_generator("\n").generate(sink, attributes::unused, context); 398 return as_generator("\n").generate(sink, attributes::unused, context);
385 } 399 }
386 400