Given a file path, returns a JSON structure suitable for bootstrap-treeview
    mock_os represents a faked filesystem generated from the playbook_treeview
    method.
    Credit: Mohammed Naser & David Moreau Simard

def generate_tree(root, paths, mock_os):
    """
    Given a file path, returns a JSON structure suitable for bootstrap-treeview
    mock_os represents a faked filesystem generated from the playbook_treeview
    method.
    Credit: Mohammed Naser & David Moreau Simard
    """
    tree = []
    dentries = mock_os.listdir(root)

    for d in dentries:
        full_path = mock_os.path.join(root, d)
        node = {
            'text': d,
            'href': '#%s' % d,
            'state': {
                'expanded': True
            }
        }

        if mock_os.path.isdir(full_path):
            node['nodes'] = generate_tree(full_path, paths, mock_os)
        else:
            node['icon'] = 'fa fa-file-code-o'
            node['href'] = '#'
            node['color'] = '#0088ce'
            node['dataAttr'] = {
                'toggle': 'modal',
                'target': '#file_modal',
                'load': paths[full_path] + '/'
            }
        tree.append(node)
    return tree