def beforeRender(self, ctx): """ Call the C{beforeRender} implementations on L{MantissaLivePage} and L{_FragmentWrapperMixin}. """ MantissaLivePage.beforeRender(self, ctx) return _FragmentWrapperMixin.beforeRender(self, ctx)
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"))
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"))
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))
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))
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))
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__'))
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()
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()