vdom icon indicating copy to clipboard operation
vdom copied to clipboard

Attach documentation to generated Tag Classes

Open rgbkrk opened this issue 7 years ago • 2 comments

Since https://github.com/nteract/vdom/pull/14, we've started generating documentation on the fly for the component helpers. We could take this another step if we want, changing createComponent like this:

diff --git a/vdom/core.py b/vdom/core.py
index 113a39f..a8a2e57 100644
--- a/vdom/core.py
+++ b/vdom/core.py
@@ -78,7 +78,7 @@ def _flatten_children(*children, **kwargs):
         children = []
     return children

-def createComponent(tagName):
+def createComponent(tagName, doc=None):
     """Create a component for an HTML Tag

     Examples:
@@ -101,12 +101,15 @@ def createComponent(tagName):
                 'text/plain': '<{tagName} />'.format(tagName=tagName)
             }

-    Component.__doc__ = """A virtual DOM component for a {tagName} tag
-
-    >>> {tagName}()
-    <{tagName} />
-    """.format(tagName=tagName)
-
+    if doc:
+        Component.__doc__ = doc
+    else:
+        Component.__doc__ = """A virtual DOM component for a {tagName} tag
+
+        >>> {tagName}()
+        <{tagName} />
+        """.format(tagName=tagName)
+
     return Component

 def createElement(tagName):

then in our helpers writing:

figcaption = createComponent(
    'figcaption',
    """A virtual DOM component for <figcaption>. This tag represents a caption or a legend
associated with a figure or an illustration described by the rest of
the data of the <figure> element which is its immediate ancestor.

>>> figure(
...    img(src="http://bit.ly/storybot-vdom", alt="Storybot"),
...    figcaption('Fig1. Clickety clackety storybots')
... )
"""

Which would allow people to be able to explore the elements to figure out what's available to them.

help(figcaption)

We could even link straight to the MDN docs!

rgbkrk avatar Sep 29 '17 23:09 rgbkrk

We could even link straight to the MDN docs!

Cool!

willingc avatar Oct 09 '17 03:10 willingc

Given how much the code has changed since I wrote the above, the approach might be different but I think we can still provide full examples for each element type along with a link to the MDN docs.

rgbkrk avatar Oct 26 '17 21:10 rgbkrk