# Path: wiremaps/web/api.py
# class ApiResource(rend.Page):
#     """Web service for Wiremaps.
#     """
# 
#     addSlash = True
#     versions = [ "1.0", "1.1" ]        # Valid versions
#     docFactory = loaders.stan(T.html [ T.body [ T.p [ "Valid versions are:" ],
#                                    T.ul [ [ T.li[v] for v in versions ] ] ] ])
# 
#     def __init__(self, config, dbpool, collector):
#         self.config = config
#         self.dbpool = dbpool
#         self.collector = collector
#         rend.Page.__init__(self)
# 
#     def childFactory(self, ctx, version):
#         if version in ApiResource.versions:
#             version = tuple([int(i) for i in version.split(".")])
#             ctx.remember(version, IApiVersion)
#             return ApiVersionedResource(self.config, self.dbpool, self.collector)
#         return None


import os
from pkg_resources import resource_string, resource_filename
from twisted.python import util
from zope.interface import implements
from nevow import rend, loaders
from nevow import tags as T
from nevow import static, inevow
from wiremaps.web.api import ApiResource




class MainPage(rend.Page):

    docFactory = loaders.xmlstr(resource_string(__name__, "main.xhtml"))

    def __init__(self, config, dbpool, collector):
        self.config = config['web']
        self.dbpool = dbpool
        self.collector = collector
        rend.Page.__init__(self)

    def render_logo(self, ctx, data):
        if 'logo' in self.config and os.path.exists(self.config['logo']):
            return T.img(src="customlogo")
        return "To place your logo here, see the documentation"

    def child_customlogo(self, ctx):
        return static.File(self.config['logo'])

    def child_static(self, ctx):
        return static.File(resource_filename(__name__, "static"))

    def child_api(self, ctx):

# Path: wiremaps/web/api.py
# class ApiResource(rend.Page):
#     """Web service for Wiremaps.
#     """
# 
#     addSlash = True
#     versions = [ "1.0", "1.1" ]        # Valid versions
#     docFactory = loaders.stan(T.html [ T.body [ T.p [ "Valid versions are:" ],
#                                    T.ul [ [ T.li[v] for v in versions ] ] ] ])
# 
#     def __init__(self, config, dbpool, collector):
#         self.config = config
#         self.dbpool = dbpool
#         self.collector = collector
#         rend.Page.__init__(self)
# 
#     def childFactory(self, ctx, version):
#         if version in ApiResource.versions:
#             version = tuple([int(i) for i in version.split(".")])
#             ctx.remember(version, IApiVersion)
#             return ApiVersionedResource(self.config, self.dbpool, self.collector)
#         return None


# Path: wiremaps/web/site.py
import os
from pkg_resources import resource_string, resource_filename
from twisted.python import util
from zope.interface import implements
from nevow import rend, loaders
from nevow import tags as T
from nevow import static, inevow
from wiremaps.web.api import ApiResource





class MainPage(rend.Page):

    docFactory = loaders.xmlstr(resource_string(__name__, "main.xhtml"))

    def __init__(self, config, dbpool, collector):
        self.config = config['web']
        self.dbpool = dbpool
        self.collector = collector
        rend.Page.__init__(self)

    def render_logo(self, ctx, data):
        if 'logo' in self.config and os.path.exists(self.config['logo']):
            return T.img(src="customlogo")
        return "To place your logo here, see the documentation"

    def child_customlogo(self, ctx):
        return static.File(self.config['logo'])

    def child_static(self, ctx):
        return static.File(resource_filename(__name__, "static"))

    def child_api(self, ctx):

        return ApiResource(self.config, self.dbpool, self.collector)