# Path: nudge/automagic/scribes/default.py
# class DefaultGenerator(object):
#     extension = 'txt'
#     template = get_template('default.txt')
# 
#     def __init__(self, dir='/tmp', filename='autogenerated_output'):
#         self.dir = dir
#         if not os.path.exists(dir):
#             os.makedirs(dir)
#         self.filename = filename
#         self.output_file = self._filepath(self.filename)
#         self.ensure_output_file()
# 
#     def _filepath(self, filename, subdir=None, extension=None):
#         dir = self.dir 
#         if subdir:
#             dir += '/' + subdir
#         if not os.path.exists(dir):
#             os.makedirs(dir)
#         extension = extension or self.extension
#         full_path = os.path.join(dir,'%s.%s' % (filename, extension))
#         return full_path
# 
#     def ensure_output_file(self, overwrite=False):
#         if not os.path.exists(self.output_file):
#             return True
#         if overwrite:
#             os.remove(self.output_file)
#             return True
#         raise Exception("This filename already exists.  Please remove it.")
# 
#     def generate(self, project):
#         data = self._prepare_data(Dict(project))
#         self._render_and_write(self.template, data, self.output_file)
# 
#     def _render_and_write(self, template, data, filename):
#         result = template.render(data)
#         file = open(filename, 'wr')
#         file.write(result)
#         file.close()
#         
# 
#     def _prepare_data(self, project):
#         return {'project':project}
# 
# def get_template(filename=None):
#     assert filename, "I need a filename, smartypants"
#     text=None
#     filepath = os.path.join(template_dir, filename)
#     assert os.path.exists(filepath), "The template file doesn't exist"
#     text = open(filepath, "r").read()
#     assert text, "How about some text"
#     return template_env.get_template(filename)
# 
# Path: nudge/utils.py
# class Dict(dict):
#     def __getattr__(self, attr):
#         return self.get(attr, None)
#     __setattr__= dict.__setitem__
#     __delattr__= dict.__delitem__
# 
# def skyline_text(string):
#     def fix_spaces(match):
#         result = ''
#         for group in match.groups():
#             result += '_' + group[len(group)-1]
#         return result
#     return title_case.sub(fix_spaces, string).lower().strip()


import os
from nudge.automagic.scribes.default import DefaultGenerator, get_template
from nudge.utils import Dict, skyline_text
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA



'''
    Sphinx does one index page, then a page for each method...
'''
class SphinxDocGenerator(DefaultGenerator):
    extension = 'rst'
    index_template = get_template('sphinx_index.txt')
    endpoint_template = get_template('sphinx_endpoint.txt')
    conf_template = get_template('sphinx_conf.txt')

    def _prepare_data(self, project):
        endpoints = {}
        sections = {}
        for section in project.sections:
            section_name = skyline_text(section.name)
            section_default = Dict({'name': section.name,
                                    'dir':section_name,
                                    'endpoints':[]})
            current_section = sections.setdefault(section_name, 
                                                  section_default)
            for ep in section.endpoints:

# Path: nudge/automagic/scribes/default.py
# class DefaultGenerator(object):
#     extension = 'txt'
#     template = get_template('default.txt')
# 
#     def __init__(self, dir='/tmp', filename='autogenerated_output'):
#         self.dir = dir
#         if not os.path.exists(dir):
#             os.makedirs(dir)
#         self.filename = filename
#         self.output_file = self._filepath(self.filename)
#         self.ensure_output_file()
# 
#     def _filepath(self, filename, subdir=None, extension=None):
#         dir = self.dir 
#         if subdir:
#             dir += '/' + subdir
#         if not os.path.exists(dir):
#             os.makedirs(dir)
#         extension = extension or self.extension
#         full_path = os.path.join(dir,'%s.%s' % (filename, extension))
#         return full_path
# 
#     def ensure_output_file(self, overwrite=False):
#         if not os.path.exists(self.output_file):
#             return True
#         if overwrite:
#             os.remove(self.output_file)
#             return True
#         raise Exception("This filename already exists.  Please remove it.")
# 
#     def generate(self, project):
#         data = self._prepare_data(Dict(project))
#         self._render_and_write(self.template, data, self.output_file)
# 
#     def _render_and_write(self, template, data, filename):
#         result = template.render(data)
#         file = open(filename, 'wr')
#         file.write(result)
#         file.close()
#         
# 
#     def _prepare_data(self, project):
#         return {'project':project}
# 
# def get_template(filename=None):
#     assert filename, "I need a filename, smartypants"
#     text=None
#     filepath = os.path.join(template_dir, filename)
#     assert os.path.exists(filepath), "The template file doesn't exist"
#     text = open(filepath, "r").read()
#     assert text, "How about some text"
#     return template_env.get_template(filename)
# 
# Path: nudge/utils.py
# class Dict(dict):
#     def __getattr__(self, attr):
#         return self.get(attr, None)
#     __setattr__= dict.__setitem__
#     __delattr__= dict.__delitem__
# 
# def skyline_text(string):
#     def fix_spaces(match):
#         result = ''
#         for group in match.groups():
#             result += '_' + group[len(group)-1]
#         return result
#     return title_case.sub(fix_spaces, string).lower().strip()


# Path: nudge/automagic/scribes/sphinx_docs.py
import os
from nudge.automagic.scribes.default import DefaultGenerator, get_template
from nudge.utils import Dict, skyline_text

# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA



'''
    Sphinx does one index page, then a page for each method...
'''
class SphinxDocGenerator(DefaultGenerator):
    extension = 'rst'
    index_template = get_template('sphinx_index.txt')
    endpoint_template = get_template('sphinx_endpoint.txt')
    conf_template = get_template('sphinx_conf.txt')

    def _prepare_data(self, project):
        endpoints = {}
        sections = {}
        for section in project.sections:
            section_name = skyline_text(section.name)
            section_default = Dict({'name': section.name,
                                    'dir':section_name,
                                    'endpoints':[]})
            current_section = sections.setdefault(section_name, 
                                                  section_default)
            for ep in section.endpoints:

                name = skyline_text(ep.name)