|
20 | 20 | // TODO(nga): document it
|
21 | 21 | #![allow(missing_docs)]
|
22 | 22 |
|
23 |
| -mod markdown; |
| 23 | +pub(crate) mod markdown; |
24 | 24 |
|
25 | 25 | use std::collections::HashMap;
|
26 | 26 |
|
@@ -349,7 +349,7 @@ pub struct DocModule {
|
349 | 349 | }
|
350 | 350 |
|
351 | 351 | impl DocModule {
|
352 |
| - fn render_as_code(&self) -> String { |
| 352 | + pub(crate) fn render_as_code(&self) -> String { |
353 | 353 | let mut res = self
|
354 | 354 | .docs
|
355 | 355 | .as_ref()
|
@@ -425,7 +425,7 @@ impl DocFunction {
|
425 | 425 | }
|
426 | 426 | }
|
427 | 427 |
|
428 |
| - fn render_as_code(&self, name: &str) -> String { |
| 428 | + pub(crate) fn render_as_code(&self, name: &str) -> String { |
429 | 429 | let params: Vec<_> = self.params.iter().map(DocParam::render_as_code).collect();
|
430 | 430 | let spacer_len = if params.is_empty() {
|
431 | 431 | 0
|
@@ -453,6 +453,19 @@ impl DocFunction {
|
453 | 453 | format!("def {}{}{}:\n{} pass", name, params, ret, docstring)
|
454 | 454 | }
|
455 | 455 |
|
| 456 | + pub(crate) fn find_param_with_name(&self, param_name: &str) -> Option<&DocParam> { |
| 457 | + self.params.iter().find(|p| match p { |
| 458 | + DocParam::Arg { name, .. } |
| 459 | + | DocParam::Args { name, .. } |
| 460 | + | DocParam::Kwargs { name, .. } |
| 461 | + if name == param_name => |
| 462 | + { |
| 463 | + true |
| 464 | + } |
| 465 | + _ => false, |
| 466 | + }) |
| 467 | + } |
| 468 | + |
456 | 469 | /// Parses function documentation out of a docstring
|
457 | 470 | ///
|
458 | 471 | /// # Arguments
|
@@ -673,7 +686,7 @@ pub struct DocProperty {
|
673 | 686 | }
|
674 | 687 |
|
675 | 688 | impl DocProperty {
|
676 |
| - fn render_as_code(&self, name: &str) -> String { |
| 689 | + pub(crate) fn render_as_code(&self, name: &str) -> String { |
677 | 690 | match (
|
678 | 691 | &self.typ,
|
679 | 692 | self.docs.as_ref().map(DocString::render_as_quoted_code),
|
@@ -734,7 +747,7 @@ pub struct DocObject {
|
734 | 747 | }
|
735 | 748 |
|
736 | 749 | impl DocObject {
|
737 |
| - fn render_as_code(&self, name: &str) -> String { |
| 750 | + pub(crate) fn render_as_code(&self, name: &str) -> String { |
738 | 751 | let summary = self
|
739 | 752 | .docs
|
740 | 753 | .as_ref()
|
@@ -783,6 +796,55 @@ pub enum DocItem {
|
783 | 796 | Property(DocProperty),
|
784 | 797 | }
|
785 | 798 |
|
| 799 | +impl DocItem { |
| 800 | + /// Get the underlying [`DocString`] for this item, if it exists. |
| 801 | + pub fn get_doc_string(&self) -> Option<&DocString> { |
| 802 | + match self { |
| 803 | + DocItem::Module(m) => m.docs.as_ref(), |
| 804 | + DocItem::Object(o) => o.docs.as_ref(), |
| 805 | + DocItem::Function(f) => f.docs.as_ref(), |
| 806 | + DocItem::Property(p) => p.docs.as_ref(), |
| 807 | + } |
| 808 | + } |
| 809 | + |
| 810 | + /// Get the summary of the underlying [`DocString`] for this item, if it exists. |
| 811 | + pub fn get_doc_summary(&self) -> Option<&str> { |
| 812 | + self.get_doc_string().map(|ds| ds.summary.as_str()) |
| 813 | + } |
| 814 | +} |
| 815 | + |
| 816 | +impl DocMember { |
| 817 | + /// Get the underlying [`DocString`] for this item, if it exists. |
| 818 | + pub fn get_doc_string(&self) -> Option<&DocString> { |
| 819 | + match self { |
| 820 | + DocMember::Function(f) => f.docs.as_ref(), |
| 821 | + DocMember::Property(p) => p.docs.as_ref(), |
| 822 | + } |
| 823 | + } |
| 824 | + |
| 825 | + /// Get the summary of the underlying [`DocString`] for this item, if it exists. |
| 826 | + pub fn get_doc_summary(&self) -> Option<&str> { |
| 827 | + self.get_doc_string().map(|ds| ds.summary.as_str()) |
| 828 | + } |
| 829 | +} |
| 830 | + |
| 831 | +impl DocParam { |
| 832 | + /// Get the underlying [`DocString`] for this item, if it exists. |
| 833 | + pub fn get_doc_string(&self) -> Option<&DocString> { |
| 834 | + match self { |
| 835 | + DocParam::Arg { docs, .. } |
| 836 | + | DocParam::Args { docs, .. } |
| 837 | + | DocParam::Kwargs { docs, .. } => docs.as_ref(), |
| 838 | + _ => None, |
| 839 | + } |
| 840 | + } |
| 841 | + |
| 842 | + /// Get the summary of the underlying [`DocString`] for this item, if it exists. |
| 843 | + pub fn get_doc_summary(&self) -> Option<&str> { |
| 844 | + self.get_doc_string().map(|ds| ds.summary.as_str()) |
| 845 | + } |
| 846 | +} |
| 847 | + |
786 | 848 | /// The main structure that represents the documentation for a given symbol / module.
|
787 | 849 | #[derive(Debug, Clone, PartialEq, Serialize)]
|
788 | 850 | pub struct Doc {
|
|
0 commit comments