work in progress: layout management: repurpose layout instance; provide page (top-level view) that in turn invokes a top-level layout view
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2785 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
2bd4149058
commit
ba8a12110b
6 changed files with 54 additions and 75 deletions
|
@ -19,24 +19,26 @@ Browser Views
|
|||
>>> from zope.traversing.adapters import DefaultTraversable
|
||||
>>> component.provideAdapter(DefaultTraversable, (Interface,))
|
||||
|
||||
>>> from cybertools.composer.layout.browser.layout import PageLayout
|
||||
>>> pageLayout = PageLayout()
|
||||
>>> pageLayoutInstance = LayoutInstance(pageLayout)
|
||||
|
||||
>>> from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
|
||||
>>> #pageLayout = Layout()
|
||||
>>> #pageLayout.renderer = ViewPageTemplateFile('browser/main.pt').macros['page']
|
||||
|
||||
>>> bodyLayout = Layout()
|
||||
>>> bodyLayout.renderer = ViewPageTemplateFile('browser/liquid/body.pt').macros['body']
|
||||
>>> LayoutInstance(bodyLayout).registerFor('page.body')
|
||||
>>> bodyLayout.registerFor('page.body')
|
||||
|
||||
>>> standardRenderers = ViewPageTemplateFile('browser/standard.pt').macros
|
||||
>>> footerLayout = Layout()
|
||||
>>> standardRenderers = ViewPageTemplateFile('browser/standard.pt').macros
|
||||
>>> footerLayout.renderer = standardRenderers['footer']
|
||||
>>> LayoutInstance(footerLayout).registerFor('body.footer')
|
||||
>>> footerLayout.registerFor('body.footer')
|
||||
|
||||
>>> from cybertools.composer.layout.browser.view import Page
|
||||
>>> from zope.publisher.browser import TestRequest
|
||||
>>> page = Page(pageLayoutInstance, TestRequest())
|
||||
>>> #instance = LayoutInstance(None)
|
||||
>>> #instance.template = pageLayout
|
||||
>>> #page = Page(instance, TestRequest())
|
||||
>>> page = Page(None, TestRequest())
|
||||
|
||||
>>> page()
|
||||
u'<!DOCTYPE ...>...<html ...>...</html>...
|
||||
|
|
|
@ -49,22 +49,23 @@ class Layout(Template):
|
|||
|
||||
implements(ILayout)
|
||||
|
||||
name = u''
|
||||
name = ''
|
||||
manager = None
|
||||
renderer = None
|
||||
|
||||
def registerFor(self, regionName):
|
||||
manager = component.getUtility(ILayoutManager)
|
||||
manager.register(self, regionName)
|
||||
|
||||
|
||||
class LayoutInstance(object):
|
||||
|
||||
implements(ILayoutInstance)
|
||||
|
||||
def __init__(self, template, context=None):
|
||||
self.template = template
|
||||
self.context = context
|
||||
template = None
|
||||
|
||||
def registerFor(self, regionName):
|
||||
manager = component.getUtility(ILayoutManager)
|
||||
manager.register(self, regionName)
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
|
||||
@property
|
||||
def renderer(self):
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
#
|
||||
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Specialized browser layouts.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
|
||||
from cybertools.composer.layout.base import Layout
|
||||
|
||||
|
||||
class PageLayout(Layout):
|
||||
|
||||
name = u'page'
|
||||
|
||||
@property
|
||||
def renderer(self):
|
||||
return ViewPageTemplateFile('main.pt').macros['page']
|
||||
|
|
@ -27,6 +27,7 @@ from zope.interface import Interface, implements
|
|||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
|
||||
from cybertools.composer.layout.base import Layout, LayoutInstance
|
||||
from cybertools.composer.layout.interfaces import ILayoutManager
|
||||
|
||||
|
||||
|
@ -47,13 +48,32 @@ class BaseView(object):
|
|||
return self.template(self)
|
||||
|
||||
|
||||
class Page(BaseView):
|
||||
|
||||
def __call__(self):
|
||||
layout = Layout()
|
||||
layout.renderer = ViewPageTemplateFile('main.pt').macros['page']
|
||||
instance = LayoutInstance(self.context)
|
||||
instance.template = layout
|
||||
view = LayoutView(instance, self.request, name='page')
|
||||
view.body = view.layouts['body'][0]
|
||||
return view.template(view)
|
||||
|
||||
|
||||
class LayoutView(BaseView):
|
||||
|
||||
name = 'base'
|
||||
|
||||
@Lazy
|
||||
def client(self):
|
||||
return self.context.context
|
||||
|
||||
@Lazy
|
||||
def renderer(self):
|
||||
return self.context.renderer
|
||||
renderer = self.context.renderer
|
||||
if renderer is None:
|
||||
raise ValueError('No renderer found for %r.' % self.context)
|
||||
return renderer
|
||||
|
||||
@Lazy
|
||||
def layouts(self):
|
||||
|
@ -68,14 +88,7 @@ class LayoutView(BaseView):
|
|||
return manager.regions.get('.'.join((self.name, key)))
|
||||
|
||||
|
||||
class Page(LayoutView):
|
||||
|
||||
name = 'page'
|
||||
|
||||
#@Lazy
|
||||
def body(self):
|
||||
return self.layouts['body'][0]()
|
||||
|
||||
# subview providers
|
||||
|
||||
class ViewLayouts(object):
|
||||
|
||||
|
@ -87,8 +100,13 @@ class ViewLayouts(object):
|
|||
region = view.getRegion(key)
|
||||
if region is None:
|
||||
return []
|
||||
return [LayoutView(layout, view.request, name=key)
|
||||
for layout in region.layouts]
|
||||
subviews = []
|
||||
for layout in region.layouts:
|
||||
instance = LayoutInstance(view.client)
|
||||
instance.template = layout
|
||||
instance.view = view
|
||||
subviews.append(LayoutView(instance, view.request, name=key))
|
||||
return subviews
|
||||
|
||||
|
||||
class ViewResources(object):
|
||||
|
|
|
@ -38,7 +38,7 @@ class ILayoutManager(Interface):
|
|||
"""
|
||||
|
||||
def register(layout, regionName):
|
||||
""" Register the layout instance given for the region specified.
|
||||
""" Register the layout given for the region specified.
|
||||
"""
|
||||
|
||||
|
||||
|
@ -66,6 +66,10 @@ class ILayout(ITemplate):
|
|||
|
||||
renderer = Attribute(u'An object responsible for rendering the layout.')
|
||||
|
||||
def registerFor(regionName):
|
||||
""" Register the layout for the region specified.
|
||||
"""
|
||||
|
||||
|
||||
class ILayoutComponent(IComponent):
|
||||
""" May be used for data entry or display.
|
||||
|
@ -96,15 +100,6 @@ class ILayoutInstance(IInstance):
|
|||
|
||||
renderer = Attribute(u'An object responsible for rendering the layout.')
|
||||
|
||||
componentAttributes = Attribute(u'A mapping``{componentName: value, ...}`` '
|
||||
u'specifying the parameter values entered for the components. '
|
||||
u'If a component is a layout the value is a corresponding '
|
||||
u'layout instance.')
|
||||
|
||||
def registerFor(regionName):
|
||||
""" Register the layout instance for the region specified.
|
||||
"""
|
||||
|
||||
|
||||
class IRegion(Interface):
|
||||
""" A part of a layout "canvas" that may be filled with layout objects.
|
||||
|
@ -118,4 +113,4 @@ class IRegion(Interface):
|
|||
value_type=schema.ASCIILine(),
|
||||
required=False,)
|
||||
|
||||
layouts = Attribute(u'The layout instances currently assigned to this region.')
|
||||
layouts = Attribute(u'The layouts currently assigned to this region.')
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#
|
||||
|
||||
"""
|
||||
Region class(es) + default regions registry.
|
||||
Region implementation.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue