summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2019-04-11 12:40:21 +0200
committerXavi Artigas <xavierartigas@yahoo.es>2019-04-12 18:13:29 +0200
commit8c45aca05ed30da51972ef3122a4f0d7e7a94933 (patch)
tree010f41771caae15be5f6937ac86a7780c8e02e80 /src/bin
parent37eee70d56aeff8649822cab62f736512cebf5d0 (diff)
mono-docs: Allow derived classes to have external examples
Summary: You can now have external example files for derived classes (Efl.Ui.Button.SetText) as well as for base classes (Efl.IText.SetText). If both files are present, both examples are embedded in the docs. The more examples the better! Examples for classes in-between the hierarchy (Efl.Ui.Widget.SetText) are not picked up. Might be worth examining in the future. Test Plan: Create example files for both `Efl.Ui.Button.AutorepeatEnabled.cs` and `Efl.Ui.IAutorepeat.AutorepeatEnabled.cs`. You should see both examples appearing in the docs. Reviewers: lauromoura, vitor.sousa Reviewed By: vitor.sousa Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8597
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/eolian_mono/eolian/mono/documentation.hh39
-rw-r--r--src/bin/eolian_mono/eolian/mono/generation_contexts.hh1
-rw-r--r--src/bin/eolian_mono/eolian/mono/klass.hh16
3 files changed, 45 insertions, 11 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/documentation.hh b/src/bin/eolian_mono/eolian/mono/documentation.hh
index d603e0bb99..1cea16e9e8 100644
--- a/src/bin/eolian_mono/eolian/mono/documentation.hh
+++ b/src/bin/eolian_mono/eolian/mono/documentation.hh
@@ -313,12 +313,12 @@ 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& object_name, Context const& context) const 316 bool generate_tag_example(OutputIterator sink, std::string const& full_object_name, Context const& context) const
317 { 317 {
318 auto options = efl::eolian::grammar::context_find_tag<options_context>(context); 318 auto options = efl::eolian::grammar::context_find_tag<options_context>(context);
319 // Example embedding not requested 319 // Example embedding not requested
320 if (options.examples_dir.empty()) return true; 320 if (options.examples_dir.empty()) return true;
321 std::string file_name = options.examples_dir + object_name + ".cs"; 321 std::string file_name = options.examples_dir + full_object_name + ".cs";
322 std::ifstream exfile(file_name); 322 std::ifstream exfile(file_name);
323 // There is no example file for this class or method, just return 323 // There is no example file for this class or method, just return
324 if (!exfile.good()) return true; 324 if (!exfile.good()) return true;
@@ -335,6 +335,24 @@ struct documentation_generator
335 return as_generator("\n").generate(sink, attributes::unused, context); 335 return as_generator("\n").generate(sink, attributes::unused, context);
336 } 336 }
337 337
338 template<typename OutputIterator, typename Context>
339 bool generate_all_tag_examples(OutputIterator sink, std::string const & full_class_name, std::string const& object_name, Context const& context) const
340 {
341 // Take example from derived class
342 auto derived_klass = efl::eolian::grammar::context_find_tag<class_context>(context);
343 std::string derived_full_name =
344 derived_klass.name.empty() ? object_name : derived_klass.name + "." + object_name;
345 std::string base_full_name =
346 full_class_name.empty() ? object_name : full_class_name + "." + object_name;
347 if (!derived_klass.name.empty())
348 {
349 if (!generate_tag_example(sink, derived_full_name, context)) return false;
350 }
351 if (derived_full_name.compare(base_full_name) == 0) return true;
352 // Take example from base class
353 return generate_tag_example(sink, base_full_name, context);
354 }
355
338 // Actual exported generators 356 // Actual exported generators
339 template<typename OutputIterator, typename Attribute, typename Context> 357 template<typename OutputIterator, typename Attribute, typename Context>
340 bool generate(OutputIterator sink, Attribute const& attr, Context const& context) const 358 bool generate(OutputIterator sink, Attribute const& attr, Context const& context) const
@@ -366,9 +384,10 @@ struct documentation_generator
366 if (!text.empty()) 384 if (!text.empty())
367 if (!generate_tag_value(sink, text, context)) return false; 385 if (!generate_tag_value(sink, text, context)) return false;
368 386
369 std::string managed_name = name_helpers::klass_full_concrete_or_interface_name(prop.klass); 387 return generate_all_tag_examples(sink,
370 managed_name += "." + name_helpers::property_managed_name(prop); 388 name_helpers::klass_full_concrete_or_interface_name(prop.klass),
371 return generate_tag_example(sink, managed_name, context); 389 name_helpers::property_managed_name(prop),
390 context);
372 } 391 }
373 392
374 template<typename OutputIterator, typename Context> 393 template<typename OutputIterator, typename Context>
@@ -404,7 +423,10 @@ struct documentation_generator
404 if (!generate_tag_return(sink, func.return_documentation.full_text, context)) 423 if (!generate_tag_return(sink, func.return_documentation.full_text, context))
405 return false; 424 return false;
406 425
407 return generate_tag_example(sink, function_conversion(func), context); 426 return generate_all_tag_examples(sink,
427 name_helpers::klass_full_concrete_or_interface_name(func.klass),
428 name_helpers::managed_method_name(func.klass.eolian_name, func.name),
429 context);
408 } 430 }
409 431
410 template<typename OutputIterator, typename Context> 432 template<typename OutputIterator, typename Context>
@@ -420,7 +442,10 @@ struct documentation_generator
420 if (!generate_tag_return(sink, func.return_documentation.full_text, context)) 442 if (!generate_tag_return(sink, func.return_documentation.full_text, context))
421 return false; 443 return false;
422 444
423 return generate_tag_example(sink, function_conversion(func), context); 445 return generate_all_tag_examples(sink,
446 name_helpers::klass_full_concrete_or_interface_name(func.klass),
447 name_helpers::managed_method_name(func.klass.eolian_name, func.name),
448 context);
424 } 449 }
425 450
426 template<typename OutputIterator, typename Context> 451 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 ff6c0391ba..dc72696342 100644
--- a/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
+++ b/src/bin/eolian_mono/eolian/mono/generation_contexts.hh
@@ -20,6 +20,7 @@ struct class_context
20 variables, 20 variables,
21 }; 21 };
22 wrapper_kind current_wrapper_kind; 22 wrapper_kind current_wrapper_kind;
23 std::string name;
23}; 24};
24 25
25struct indentation_context 26struct indentation_context
diff --git a/src/bin/eolian_mono/eolian/mono/klass.hh b/src/bin/eolian_mono/eolian/mono/klass.hh
index 87ad1bd5a7..4664446dbf 100644
--- a/src/bin/eolian_mono/eolian/mono/klass.hh
+++ b/src/bin/eolian_mono/eolian/mono/klass.hh
@@ -117,7 +117,9 @@ struct klass
117 // Interface class 117 // Interface class
118 if(class_type == "interface") 118 if(class_type == "interface")
119 { 119 {
120 auto iface_cxt = context_add_tag(class_context{class_context::interface}, context); 120 auto iface_cxt = context_add_tag(class_context{class_context::interface,
121 name_helpers::klass_full_concrete_or_interface_name(cls)},
122 context);
121 123
122 if(!as_generator(documentation).generate(sink, cls, iface_cxt)) 124 if(!as_generator(documentation).generate(sink, cls, iface_cxt))
123 return false; 125 return false;
@@ -195,7 +197,9 @@ struct klass
195 // Concrete class for interfaces, mixins, etc. 197 // Concrete class for interfaces, mixins, etc.
196 if(class_type != "class" && class_type != "abstract class") 198 if(class_type != "class" && class_type != "abstract class")
197 { 199 {
198 auto concrete_cxt = context_add_tag(class_context{class_context::concrete}, context); 200 auto concrete_cxt = context_add_tag(class_context{class_context::concrete,
201 name_helpers::klass_full_concrete_or_interface_name(cls)},
202 context);
199 auto concrete_name = name_helpers::klass_concrete_name(cls); 203 auto concrete_name = name_helpers::klass_concrete_name(cls);
200 auto interface_name = name_helpers::klass_interface_name(cls); 204 auto interface_name = name_helpers::klass_interface_name(cls);
201 205
@@ -277,7 +281,9 @@ struct klass
277 // Inheritable class 281 // Inheritable class
278 if(class_type == "class" || class_type == "abstract class") 282 if(class_type == "class" || class_type == "abstract class")
279 { 283 {
280 auto inherit_cxt = context_add_tag(class_context{class_context::inherit}, context); 284 auto inherit_cxt = context_add_tag(class_context{class_context::inherit,
285 name_helpers::klass_full_concrete_or_interface_name(cls)},
286 context);
281 287
282 // Class header 288 // Class header
283 if(!as_generator 289 if(!as_generator
@@ -351,7 +357,9 @@ struct klass
351 // Native Inherit class 357 // Native Inherit class
352 //if(class_type == "class") 358 //if(class_type == "class")
353 { 359 {
354 auto inative_cxt = context_add_tag(class_context{class_context::inherit_native}, context); 360 auto inative_cxt = context_add_tag(class_context{class_context::inherit_native,
361 name_helpers::klass_full_concrete_or_interface_name(cls)},
362 context);
355 auto native_inherit_name = name_helpers::klass_native_inherit_name(cls); 363 auto native_inherit_name = name_helpers::klass_native_inherit_name(cls);
356 auto inherit_name = name_helpers::klass_inherit_name(cls); 364 auto inherit_name = name_helpers::klass_inherit_name(cls);
357 std::string base_name; 365 std::string base_name;