Exemplo n.º 1
0
 def beforeRender(self, ctx):
     """
     Call the C{beforeRender} implementations on L{MantissaLivePage} and
     L{_FragmentWrapperMixin}.
     """
     MantissaLivePage.beforeRender(self, ctx)
     return _FragmentWrapperMixin.beforeRender(self, ctx)
Exemplo n.º 2
0
    def __init__(self, webapp, fragment, pageComponents, username):
        """
        Top-level container for Mantissa application views.

        @param webapp: a C{PrivateApplication}.
        @param fragment: The C{Element} or C{Fragment} to display as content.
        @param pageComponents a C{_PageComponent}.

        This page draws its HTML from the 'shell' template in the preferred
        theme for the store.  If loaded in a browser that does not support
        Athena, the page provided by the 'athena-unsupported' template will be
        displayed instead.

        @see: L{PrivateApplication.preferredTheme}
        """
        userStore = webapp.store
        siteStore = userStore.parent

        MantissaLivePage.__init__(self,
                                  ISiteURLGenerator(siteStore),
                                  getattr(fragment, 'iface', None),
                                  fragment,
                                  jsModuleRoot=None,
                                  docFactory=webapp.getDocFactory('shell'))
        _ShellRenderingMixin.__init__(self, webapp, pageComponents, username)
        _FragmentWrapperMixin.__init__(self, fragment, pageComponents)
        self.unsupportedBrowserLoader = (
            webapp.getDocFactory("athena-unsupported"))
Exemplo n.º 3
0
 def beforeRender(self, ctx):
     """
     Call the C{beforeRender} implementations on L{MantissaLivePage} and
     L{_FragmentWrapperMixin}.
     """
     MantissaLivePage.beforeRender(self, ctx)
     return _FragmentWrapperMixin.beforeRender(self, ctx)
Exemplo n.º 4
0
    def __init__(self, webapp, fragment, pageComponents, username):
        """
        Top-level container for Mantissa application views.

        @param webapp: a C{PrivateApplication}.
        @param fragment: The C{Element} or C{Fragment} to display as content.
        @param pageComponents a C{_PageComponent}.

        This page draws its HTML from the 'shell' template in the preferred
        theme for the store.  If loaded in a browser that does not support
        Athena, the page provided by the 'athena-unsupported' template will be
        displayed instead.

        @see: L{PrivateApplication.preferredTheme}
        """
        userStore = webapp.store
        siteStore = userStore.parent

        MantissaLivePage.__init__(
            self, ISiteURLGenerator(siteStore),
            getattr(fragment, 'iface', None),
            fragment,
            jsModuleRoot=None,
            docFactory=webapp.getDocFactory('shell'))
        _ShellRenderingMixin.__init__(self, webapp, pageComponents, username)
        _FragmentWrapperMixin.__init__(self, fragment, pageComponents)
        self.unsupportedBrowserLoader = (webapp
                                         .getDocFactory("athena-unsupported"))
Exemplo n.º 5
0
    def test_getJSModuleURL(self):
        """
        L{MantissaLivePage.getJSModuleURL} should return a child of its
        C{_moduleRoot} attribute of the form::

            _moduleRoot/<SHA1 digest of module contents>/Package.ModuleName
        """
        module = 'Mantissa'
        url = URL(scheme='https', netloc='example.com', pathsegs=['foo'])
        page = MantissaLivePage(None)
        page._moduleRoot = url
        jsDir = FilePath(__file__).parent().parent().child("js")
        modulePath = jsDir.child(module).child("__init__.js")
        moduleContents = modulePath.open().read()
        expect = sha.new(moduleContents).hexdigest()
        self.assertEqual(page.getJSModuleURL(module),
                         url.child(expect).child(module))
Exemplo n.º 6
0
 def makeLivePage(self):
     """
     Create a MantissaLivePage instance for testing.
     """
     siteStore = Store(filesdir=self.mktemp())
     Mantissa().installSite(siteStore, self.hostname.decode('ascii'), u"",
                            False)
     return MantissaLivePage(ISiteURLGenerator(siteStore))
Exemplo n.º 7
0
    def test_getJSModuleURL(self):
        """
        L{MantissaLivePage.getJSModuleURL} should return a child of its
        C{_moduleRoot} attribute of the form::

            _moduleRoot/<SHA1 digest of module contents>/Package.ModuleName
        """
        module = 'Mantissa'
        url = URL(scheme='https', netloc='example.com', pathsegs=['foo'])
        page = MantissaLivePage(None)
        page._moduleRoot = url
        jsDir = FilePath(__file__).parent().parent().child("js")
        modulePath = jsDir.child(module).child("__init__.js")
        moduleContents = modulePath.open().read()
        expect = sha1(moduleContents).hexdigest()
        self.assertEqual(page.getJSModuleURL(module),
                         url.child(expect).child(module))
Exemplo n.º 8
0
 def test_beforeRenderSetsModuleRoot(self):
     """
     L{MantissaLivePage.beforeRender} should set I{_moduleRoot} to the
     C{__jsmodule__} child of the URL returned by the I{rootURL}
     method of the L{WebSite} it wraps.
     """
     receivedRequests = []
     root = URL(netloc='example.com', pathsegs=['a', 'b'])
     class FakeWebSite(object):
         def rootURL(self, request):
             receivedRequests.append(request)
             return root
     request = FakeRequest()
     page = MantissaLivePage(FakeWebSite())
     page.beforeRender(request)
     self.assertEqual(receivedRequests, [request])
     self.assertEqual(page._moduleRoot, root.child('__jsmodule__'))
Exemplo n.º 9
0
    def test_beforeRenderSetsModuleRoot(self):
        """
        L{MantissaLivePage.beforeRender} should set I{_moduleRoot} to the
        C{__jsmodule__} child of the URL returned by the I{rootURL}
        method of the L{WebSite} it wraps.
        """
        receivedRequests = []
        root = URL(netloc='example.com', pathsegs=['a', 'b'])

        class FakeWebSite(object):
            def rootURL(self, request):
                receivedRequests.append(request)
                return root

        request = FakeRequest()
        page = MantissaLivePage(FakeWebSite())
        page.beforeRender(request)
        self.assertEqual(receivedRequests, [request])
        self.assertEqual(page._moduleRoot, root.child('__jsmodule__'))
Exemplo n.º 10
0
        def _renderPage():
            page = MantissaLivePage(FakeWebSite())
            element = LiveElement(
                stan(tags.span(render=tags.directive('liveElement'))))
            element.setFragmentParent(page)
            element.jsClass = u'Mantissa.Test.Dummy.DummyWidget'
            page.docFactory = stan(
                [tags.span(render=tags.directive('liveglue')), element])

            ctx = WovenContext()
            req = FakeRequest(headers={'host': self.hostname})
            ctx.remember(req, IRequest)
            page.beforeRender(ctx)
            page.renderHTTP(ctx)
            page._messageDeliverer.close()
Exemplo n.º 11
0
        def _renderPage():
            page = MantissaLivePage(FakeWebSite())
            element = LiveElement(stan(tags.span(render=tags.directive('liveElement'))))
            element.setFragmentParent(page)
            element.jsClass = u'Mantissa.Test.Dummy.DummyWidget'
            page.docFactory = stan([tags.span(render=tags.directive('liveglue')), element])

            ctx = WovenContext()
            req = FakeRequest(headers={'host': self.hostname})
            ctx.remember(req, IRequest)
            page.beforeRender(ctx)
            page.renderHTTP(ctx)
            page._messageDeliverer.close()