# Path: silhouette/apps.py
# class Silhouette(AppSettings, AppConfig):
#     name = "silhouette"
#     settings_module = "silhouette.settings"
#     settings_imports = ('LOADER',)
# 
# Path: silhouette/utils.py
# def normalize(name):
#     return re.sub('(((?<=[a-z])[A-Z1-9])|([A-Z1-9](?![A-Z1-9]|$)))', '_\\1', name).strip('_').lower()


import re
from django.forms.forms import BaseForm, BoundField
from django.forms.formsets import BaseFormSet
from django.template.loader import select_template
from .apps import Silhouette
from .utils import normalize



class DefaultLoader(object):

    def get_substitutes(self, obj, path, theme):
        if isinstance(obj, BaseForm):
            return {'path': path.strip("/"),
                    'theme': theme,
                    'form': normalize(type(obj).__name__)}
        elif isinstance(obj, BaseFormSet):
            return {'path': path.strip("/"),
                    'theme': theme,
                    'formset': normalize(type(obj).__name__)}
        elif isinstance(obj, BoundField):
            return {'path': path.strip("/"),
                    'theme': theme,
                    'form': normalize(type(obj.form).__name__),
                    'field': normalize(obj.name),
                    'widget': normalize(type(obj.field.widget).__name__)}
        raise ValueError("Object {} of type {} is not supported by {}".format(obj, type(obj), type(self)))

    def get_template(self, obj, template_type, path=None, theme=None, patterns=None):

# Path: silhouette/apps.py
# class Silhouette(AppSettings, AppConfig):
#     name = "silhouette"
#     settings_module = "silhouette.settings"
#     settings_imports = ('LOADER',)
# 
# Path: silhouette/utils.py
# def normalize(name):
#     return re.sub('(((?<=[a-z])[A-Z1-9])|([A-Z1-9](?![A-Z1-9]|$)))', '_\\1', name).strip('_').lower()


# Path: silhouette/loaders.py
import re
from django.forms.forms import BaseForm, BoundField
from django.forms.formsets import BaseFormSet
from django.template.loader import select_template
from .apps import Silhouette
from .utils import normalize




class DefaultLoader(object):

    def get_substitutes(self, obj, path, theme):
        if isinstance(obj, BaseForm):
            return {'path': path.strip("/"),
                    'theme': theme,
                    'form': normalize(type(obj).__name__)}
        elif isinstance(obj, BaseFormSet):
            return {'path': path.strip("/"),
                    'theme': theme,
                    'formset': normalize(type(obj).__name__)}
        elif isinstance(obj, BoundField):
            return {'path': path.strip("/"),
                    'theme': theme,
                    'form': normalize(type(obj.form).__name__),
                    'field': normalize(obj.name),
                    'widget': normalize(type(obj.field.widget).__name__)}
        raise ValueError("Object {} of type {} is not supported by {}".format(obj, type(obj), type(self)))

    def get_template(self, obj, template_type, path=None, theme=None, patterns=None):

        path = path or Silhouette.PATH