| 257 | } |
| 258 | |
| 259 | std::string FunctionDoc::ToGoogleDocString() const |
| 260 | { |
| 261 | // Example Gooele style: |
| 262 | // http://www.sphinx-doc.org/en/1.5/ext/example_google.html |
| 263 | |
| 264 | std::ostringstream rc; |
| 265 | std::string indent = " "; |
| 266 | |
| 267 | // Function signature to be parsed by Sphinx |
| 268 | rc << name_ << "("; |
| 269 | for (size_t i = 0; i < argument_docs_.size(); ++i) |
| 270 | { |
| 271 | const ArgumentDoc& argument_doc = argument_docs_[i]; |
| 272 | rc << argument_doc.name_; |
| 273 | if (argument_doc.default_ != "") |
| 274 | { |
| 275 | rc << "=" << argument_doc.default_; |
| 276 | } |
| 277 | if (i != argument_docs_.size() - 1) |
| 278 | { |
| 279 | rc << ", "; |
| 280 | } |
| 281 | } |
| 282 | rc << ")" << std::endl; |
| 283 | |
| 284 | // Summary line, strictly speaking this shall be at the very front. However |
| 285 | // from a compiled Python module we need the function signature hints in |
| 286 | // front for Sphinx parsing and PyCharm autocomplete |
| 287 | if (summary_ != "") |
| 288 | { |
| 289 | rc << std::endl; |
| 290 | rc << summary_ << std::endl; |
| 291 | } |
| 292 | |
| 293 | // Arguments |
| 294 | if (argument_docs_.size() != 0 && !(argument_docs_.size() == 1 && argument_docs_[0].name_ == "self")) |
| 295 | { |
| 296 | rc << std::endl; |
| 297 | rc << "Args:" << std::endl; |
| 298 | for (const ArgumentDoc& argument_doc : argument_docs_) |
| 299 | { |
| 300 | if (argument_doc.name_ == "self") |
| 301 | { |
| 302 | continue; |
| 303 | } |
| 304 | rc << indent << argument_doc.name_ << " (" << argument_doc.type_; |
| 305 | if (argument_doc.default_ != "") |
| 306 | { |
| 307 | rc << ", optional"; |
| 308 | } |
| 309 | if (argument_doc.default_ != "" && argument_doc.long_default_ == "") |
| 310 | { |
| 311 | rc << ", default=" << argument_doc.default_; |
| 312 | } |
| 313 | rc << ")"; |
| 314 | if (argument_doc.body_ != "") |
| 315 | { |
| 316 | rc << ": " << argument_doc.body_; |
no test coverage detected