import collections
import json
from .base_component import generate_class


def load_components(metadata_path,
                    namespace='default_namespace'):
    """Load React component metadata into a format Dash can parse.

    Usage: load_components('../../component-suites/lib/metadata.json')

    Keyword arguments:
    metadata_path -- a path to a JSON file created by
    [`react-docgen`](https://github.com/reactjs/react-docgen).

    Returns:
    components -- a list of component objects with keys
    `type`, `valid_kwargs`, and `setup`.
    """

    components = []

    # Start processing
    with open(metadata_path) as data_file:
        json_string = data_file.read()
        data = json\
            .JSONDecoder(object_pairs_hook=collections.OrderedDict)\
            .decode(json_string)

    # Iterate over each property name (which is a path to the component)
    for componentPath in data:
        componentData = data[componentPath]

        # Extract component name from path
        # e.g. src/components/MyControl.react.js
        # TODO Make more robust - some folks will write .jsx and others
        # will be on windows. Unfortunately react-docgen doesn't include
        # the name of the component atm.
        name = componentPath.split('/').pop().split('.')[0]
        component = generate_class(
            name,
            componentData['props'],
            componentData['description'],
            namespace
        )

        components.append(component)

    return components

@@ -67,16 +67,344 @@
 e_class%0A
+from .base_component import generate_class_file%0A%0A%0Adef _get_metadata(metadata_path):%0A    # Start processing%0A    with open(metadata_path) as data_file:%0A        json_string = data_file.read()%0A        data = json%5C%0A            .JSONDecoder(object_pairs_hook=collections.OrderedDict)%5C%0A            .decode(json_string)%0A    return data%0A
 %0A%0Adef lo
@@ -913,230 +913,42 @@
     
-# Start processing%0A    with open(metadata_path) as data_file:%0A        json_string = data_file.read()%0A        data = json%5C%0A            .JSONDecoder(object_pairs_hook=collections.OrderedDict)%5C%0A            .decode(json_string
+data = _get_metadata(metadata_path
 )%0A%0A 
@@ -1636,16 +1636,16 @@
 onent)%0A%0A
-
     retu
@@ -1658,8 +1658,1124 @@
 ponents%0A
+%0A%0Adef generate_classes(metadata_path,%0A                     namespace='default_namespace'):%0A    %22%22%22Load React component metadata into a format Dash can parse,%0A    then create python class files.%0A%0A    Usage: generate_classes('../../component-suites/lib/metadata.json')%0A%0A    Keyword arguments:%0A    metadata_path -- a path to a JSON file created by%0A    %5B%60react-docgen%60%5D(https://github.com/reactjs/react-docgen).%0A%0A    Returns:%0A    %22%22%22%0A%0A    data = _get_metadata(metadata_path)%0A%0A    # Iterate over each property name (which is a path to the component)%0A    for componentPath in data:%0A        componentData = data%5BcomponentPath%5D%0A%0A        # Extract component name from path%0A        # e.g. src/components/MyControl.react.js%0A        # TODO Make more robust - some folks will write .jsx and others%0A        # will be on windows. Unfortunately react-docgen doesn't include%0A        # the name of the component atm.%0A        name = componentPath.split('/').pop().split('.')%5B0%5D%0A        generate_class_file(%0A            name,%0A            componentData%5B'props'%5D,%0A            componentData%5B'description'%5D,%0A            namespace%0A        )%0A

Add generate_classes function.