summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson_options.txt6
-rw-r--r--src/bin/eolian_mono/eolian/mono/documentation.hh34
-rw-r--r--src/bin/eolian_mono/eolian/mono/generation_contexts.hh1
-rw-r--r--src/bin/eolian_mono/eolian_mono.cc13
-rw-r--r--src/bindings/mono/meson.build1
5 files changed, 47 insertions, 8 deletions
diff --git a/meson_options.txt b/meson_options.txt
index 105f4cf..0b6b0bb 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -323,6 +323,12 @@ option('mono-beta',
323 description: 'Flag for enabling @beta Eo methods in the api' 323 description: 'Flag for enabling @beta Eo methods in the api'
324) 324)
325 325
326option('mono-examples-dir',
327 type: 'string',
328 value: '',
329 description: 'Directory where eolian_mono will search for examples to embed into the documentation'
330)
331
326option('lua-interpreter', 332option('lua-interpreter',
327 type: 'combo', 333 type: 'combo',
328 choices: ['luajit', 'lua'], 334 choices: ['luajit', 'lua'],
diff --git a/src/bin/eolian_mono/eolian/mono/documentation.hh b/src/bin/eolian_mono/eolian/mono/documentation.hh
index c46cbd4..0460b57 100644
--- a/src/bin/eolian_mono/eolian/mono/documentation.hh
+++ b/src/bin/eolian_mono/eolian/mono/documentation.hh
@@ -313,12 +313,22 @@ struct documentation_generator
313 } 313 }
314 314
315 template<typename OutputIterator, typename Context> 315 template<typename OutputIterator, typename Context>
316 bool generate_tag_example(OutputIterator sink, std::string const& example, Context const& context) const 316 bool generate_tag_example(OutputIterator sink, std::string const& object_name, Context const& context) const
317 { 317 {
318 auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
319 // Example embedding not requested
320 if (options.examples_dir.empty()) return true;
321 std::string file_name = options.examples_dir + object_name + ".cs";
322 std::ifstream exfile(file_name);
323 // There is no example file for this class or method, just return
324 if (!exfile.good()) return true;
325 std::stringstream example_buff;
326 example_buff << exfile.rdbuf();
327
318 if (!as_generator(scope_tab(scope_size) << "/// ").generate(sink, attributes::unused, context)) return false; 328 if (!as_generator(scope_tab(scope_size) << "/// ").generate(sink, attributes::unused, context)) return false;
319 if (!generate_opening_tag(sink, "example", context)) return false; 329 if (!generate_opening_tag(sink, "example", context)) return false;
320 if (!generate_opening_tag(sink, "code", context)) return false; 330 if (!generate_opening_tag(sink, "code", context)) return false;
321 if (!generate_escaped_content(sink, example, context)) return false; 331 if (!generate_escaped_content(sink, example_buff.str(), context)) return false;
322 if (!generate_closing_tag(sink, "code", context)) return false; 332 if (!generate_closing_tag(sink, "code", context)) return false;
323 if (!generate_closing_tag(sink, "example", context)) return false; 333 if (!generate_closing_tag(sink, "example", context)) return false;
324 return as_generator("\n").generate(sink, attributes::unused, context); 334 return as_generator("\n").generate(sink, attributes::unused, context);
@@ -332,6 +342,15 @@ struct documentation_generator
332 } 342 }
333 343
334 template<typename OutputIterator, typename Context> 344 template<typename OutputIterator, typename Context>
345 bool generate(OutputIterator sink, attributes::klass_def const& klass, Context const& context) const
346 {
347 if (!generate(sink, klass.documentation, context)) return false;
348
349 std::string klass_name = name_helpers::klass_full_concrete_or_interface_name(klass);
350 return generate_tag_example(sink, klass_name, context);
351 }
352
353 template<typename OutputIterator, typename Context>
335 bool generate(OutputIterator sink, attributes::property_def const& prop, Context const& context) const 354 bool generate(OutputIterator sink, attributes::property_def const& prop, Context const& context) const
336 { 355 {
337 if (!generate(sink, prop.documentation, context)) 356 if (!generate(sink, prop.documentation, context))
@@ -343,9 +362,12 @@ struct documentation_generator
343 else if (prop.getter.is_engaged()) 362 else if (prop.getter.is_engaged())
344 text = prop.getter->return_documentation.full_text; 363 text = prop.getter->return_documentation.full_text;
345 // If there are no docs at all, do not generate <value> tag 364 // If there are no docs at all, do not generate <value> tag
346 else return true; 365 if (!text.empty())
366 if (!generate_tag_value(sink, text, context)) return false;
347 367
348 return generate_tag_value(sink, text, context); 368 std::string managed_name = name_helpers::klass_full_concrete_or_interface_name(prop.klass);
369 managed_name += "." + name_helpers::property_managed_name(prop);
370 return generate_tag_example(sink, managed_name, context);
349 } 371 }
350 372
351 template<typename OutputIterator, typename Context> 373 template<typename OutputIterator, typename Context>
@@ -381,7 +403,7 @@ struct documentation_generator
381 if (!generate_tag_return(sink, func.return_documentation.full_text, context)) 403 if (!generate_tag_return(sink, func.return_documentation.full_text, context))
382 return false; 404 return false;
383 405
384 return true; 406 return generate_tag_example(sink, function_conversion(func), context);
385 } 407 }
386 408
387 template<typename OutputIterator, typename Context> 409 template<typename OutputIterator, typename Context>
@@ -397,7 +419,7 @@ struct documentation_generator
397 if (!generate_tag_return(sink, func.return_documentation.full_text, context)) 419 if (!generate_tag_return(sink, func.return_documentation.full_text, context))
398 return false; 420 return false;
399 421
400 return true; 422 return generate_tag_example(sink, function_conversion(func), context);
401 } 423 }
402 424
403 template<typename OutputIterator, typename Context> 425 template<typename OutputIterator, typename Context>
diff --git a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
index 25ac309..ff6c039 100644
--- a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
+++ b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
@@ -78,6 +78,7 @@ struct eolian_state_context {
78 78
79struct options_context { 79struct options_context {
80 bool want_beta; 80 bool want_beta;
81 std::string examples_dir;
81}; 82};
82 83
83} 84}
diff --git a/src/bin/eolian_mono/eolian_mono.cc b/src/bin/eolian_mono/eolian_mono.cc
index 0fcc63f..8f24f76 100644
--- a/src/bin/eolian_mono/eolian_mono.cc
+++ b/src/bin/eolian_mono/eolian_mono.cc
@@ -43,6 +43,7 @@ struct options_type
43 std::vector<std::string> include_dirs; 43 std::vector<std::string> include_dirs;
44 std::string in_file; 44 std::string in_file;
45 std::string out_file; 45 std::string out_file;
46 std::string examples_dir;
46 std::string dllimport; 47 std::string dllimport;
47 mutable Eolian_State* state; 48 mutable Eolian_State* state;
48 mutable Eolian_Unit const* unit; 49 mutable Eolian_Unit const* unit;
@@ -145,7 +146,8 @@ run(options_type const& opts)
145 146
146 auto context = context_add_tag(eolian_mono::indentation_context{0}, 147 auto context = context_add_tag(eolian_mono::indentation_context{0},
147 context_add_tag(eolian_mono::eolian_state_context{opts.state}, 148 context_add_tag(eolian_mono::eolian_state_context{opts.state},
148 context_add_tag(eolian_mono::options_context{opts.want_beta}, 149 context_add_tag(eolian_mono::options_context{opts.want_beta,
150 opts.examples_dir},
149 context_add_tag(eolian_mono::library_context{opts.dllimport, 151 context_add_tag(eolian_mono::library_context{opts.dllimport,
150 opts.v_major, 152 opts.v_major,
151 opts.v_minor, 153 opts.v_minor,
@@ -294,6 +296,7 @@ _usage(const char *progname)
294 << " -r, --recurse Recurse input directories loading .eo files." << std::endl 296 << " -r, --recurse Recurse input directories loading .eo files." << std::endl
295 << " -v, --version Print the version." << std::endl 297 << " -v, --version Print the version." << std::endl
296 << " -b, --beta Enable @beta methods." << std::endl 298 << " -b, --beta Enable @beta methods." << std::endl
299 << " -e, --example-dir <dir> Folder to search for example files." << std::endl
297 << " -h, --help Print this help." << std::endl; 300 << " -h, --help Print this help." << std::endl;
298 exit(EXIT_FAILURE); 301 exit(EXIT_FAILURE);
299} 302}
@@ -324,9 +327,10 @@ opts_get(int argc, char **argv)
324 { "vmin", required_argument, 0, 'm' }, 327 { "vmin", required_argument, 0, 'm' },
325 { "references", required_argument, 0, 'r'}, 328 { "references", required_argument, 0, 'r'},
326 { "beta", no_argument, 0, 'b'}, 329 { "beta", no_argument, 0, 'b'},
330 { "example-dir", required_argument, 0, 'e' },
327 { 0, 0, 0, 0 } 331 { 0, 0, 0, 0 }
328 }; 332 };
329 const char* options = "I:D:o:c:M:m:ar:vhb"; 333 const char* options = "I:D:o:c:M:m:ar:vhbe:";
330 334
331 int c, idx; 335 int c, idx;
332 while ( (c = getopt_long(argc, argv, options, long_options, &idx)) != -1) 336 while ( (c = getopt_long(argc, argv, options, long_options, &idx)) != -1)
@@ -382,6 +386,11 @@ opts_get(int argc, char **argv)
382 { 386 {
383 opts.want_beta = true; 387 opts.want_beta = true;
384 } 388 }
389 else if (c == 'e')
390 {
391 opts.examples_dir = optarg;
392 if (!opts.examples_dir.empty() && opts.examples_dir.back() != '/') opts.examples_dir += "/";
393 }
385 } 394 }
386 if (optind == argc-1) 395 if (optind == argc-1)
387 { 396 {
diff --git a/src/bindings/mono/meson.build b/src/bindings/mono/meson.build
index dc2c856..e7c5e00 100644
--- a/src/bindings/mono/meson.build
+++ b/src/bindings/mono/meson.build
@@ -127,6 +127,7 @@ foreach lib : mono_sublibs
127 command : [eolian_mono_gen, beta_option, '-I', meson.current_source_dir(), eolian_include_directories, 127 command : [eolian_mono_gen, beta_option, '-I', meson.current_source_dir(), eolian_include_directories,
128 '--dllimport', package_name, 128 '--dllimport', package_name,
129 '-o', join_paths(meson.current_build_dir(), mono_gen_file + '.cs'), 129 '-o', join_paths(meson.current_build_dir(), mono_gen_file + '.cs'),
130 '-e', get_option('mono-examples-dir'),
130 '@INPUT@']) 131 '@INPUT@'])
131 endif 132 endif
132 endforeach 133 endforeach