}
template<typename OutputIterator, typename Context>
- bool generate_tag_example(OutputIterator sink, std::string const& example, Context const& context) const
+ bool generate_tag_example(OutputIterator sink, std::string const& object_name, Context const& context) const
{
+ 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 + object_name + ".cs";
+ std::ifstream exfile(file_name);
+ // There is no example file for this class or method, just return
+ if (!exfile.good()) return true;
+ std::stringstream example_buff;
+ example_buff << 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 (!generate_escaped_content(sink, example, 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;
return as_generator("\n").generate(sink, attributes::unused, context);
}
template<typename OutputIterator, typename Context>
+ bool generate(OutputIterator sink, attributes::klass_def const& klass, Context const& context) const
+ {
+ if (!generate(sink, klass.documentation, context)) return false;
+
+ std::string klass_name = name_helpers::klass_full_concrete_or_interface_name(klass);
+ return generate_tag_example(sink, klass_name, context);
+ }
+
+ template<typename OutputIterator, typename Context>
bool generate(OutputIterator sink, attributes::property_def const& prop, Context const& context) const
{
if (!generate(sink, prop.documentation, context))
else if (prop.getter.is_engaged())
text = prop.getter->return_documentation.full_text;
// If there are no docs at all, do not generate <value> tag
- else return true;
+ if (!text.empty())
+ if (!generate_tag_value(sink, text, context)) return false;
- return generate_tag_value(sink, text, context);
+ std::string managed_name = name_helpers::klass_full_concrete_or_interface_name(prop.klass);
+ managed_name += "." + name_helpers::property_managed_name(prop);
+ return generate_tag_example(sink, managed_name, context);
}
template<typename OutputIterator, typename Context>
if (!generate_tag_return(sink, func.return_documentation.full_text, context))
return false;
- return true;
+ return generate_tag_example(sink, function_conversion(func), context);
}
template<typename OutputIterator, typename Context>
if (!generate_tag_return(sink, func.return_documentation.full_text, context))
return false;
- return true;
+ return generate_tag_example(sink, function_conversion(func), context);
}
template<typename OutputIterator, typename Context>
std::vector<std::string> include_dirs;
std::string in_file;
std::string out_file;
+ std::string examples_dir;
std::string dllimport;
mutable Eolian_State* state;
mutable Eolian_Unit const* unit;
auto context = context_add_tag(eolian_mono::indentation_context{0},
context_add_tag(eolian_mono::eolian_state_context{opts.state},
- context_add_tag(eolian_mono::options_context{opts.want_beta},
+ context_add_tag(eolian_mono::options_context{opts.want_beta,
+ opts.examples_dir},
context_add_tag(eolian_mono::library_context{opts.dllimport,
opts.v_major,
opts.v_minor,
<< " -r, --recurse Recurse input directories loading .eo files." << std::endl
<< " -v, --version Print the version." << std::endl
<< " -b, --beta Enable @beta methods." << std::endl
+ << " -e, --example-dir <dir> Folder to search for example files." << std::endl
<< " -h, --help Print this help." << std::endl;
exit(EXIT_FAILURE);
}
{ "vmin", required_argument, 0, 'm' },
{ "references", required_argument, 0, 'r'},
{ "beta", no_argument, 0, 'b'},
+ { "example-dir", required_argument, 0, 'e' },
{ 0, 0, 0, 0 }
};
- const char* options = "I:D:o:c:M:m:ar:vhb";
+ const char* options = "I:D:o:c:M:m:ar:vhbe:";
int c, idx;
while ( (c = getopt_long(argc, argv, options, long_options, &idx)) != -1)
{
opts.want_beta = true;
}
+ else if (c == 'e')
+ {
+ opts.examples_dir = optarg;
+ if (!opts.examples_dir.empty() && opts.examples_dir.back() != '/') opts.examples_dir += "/";
+ }
}
if (optind == argc-1)
{