{ "info": { "author": "Malthe Borch, Stefan Eletzhofer and the Zope Community", "author_email": "zope-dev@zope.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Zope3", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP" ], "description": "HTML layout engine\n==================\n\nThis package implements a page rendering model based on a static HTML\ndocument that is made dynamic from the outside by mapping content\nprovider definitions to locations in the HTML document tree. This is\ncalled a \"layout\".\n\nThe component architecture is utilized to provide extension points\nthat allow wide application. Two-phase rendering is supported using\nthe ``zope.contentprovider`` rendering scheme (update/render).\n\nStatic resources, as referenced by the HTML document (images,\nstylesheets and javascript files) are included carbon copy and\npublished as browser resources (see ``zope.app.publisher.browser``).\n\nBenefits:\n\n* No template language required\n* Support for two-phase rendering\n* Integrates with creative workflow\n* Flexible extension points\n\nWalk-through\n============\n\nLayouts and regions\n-------------------\n\nLet's begin by instantiating a layout. We'll do this manually for the\nsake of this demonstration; usually this is done using the included\nZCML-directive .\n\n >>> from z3c.layout.model import Layout\n \n >>> layout = Layout(\n ... \"test\", \"%s/templates/default/index.html\" % test_path, \"test\")\n\nRegister resource directory.\n \n >>> import zope.configuration.config as config\n >>> context = config.ConfigurationMachine()\n \n >>> from zope.app.publisher.browser import resourcemeta\n >>> resourcemeta.resourceDirectory(\n ... context, \"test\", \"%s/templates/default\" % test_path)\n >>> context.execute_actions()\n \nLayouts are made dynamic by defining one or more regions. They are\nmapped to HTML locations using an xpath-expression and an insertion\nmode, which is one of \"replace\", \"append\", \"prepend\", \"before\" or\n\"after\".\n\nRegions can specify the name of a content provider directly or it may\nrely on adaptation to yield a content provider component. We'll\ninvestigate both of these approaches:\n\n >>> from z3c.layout.model import Region\n\nFirst we define a title region where we directly specify the name of a\ncontent provider.\n\n >>> title = Region(\"title\", \".//title\", title=u\"Title\", provider=\"title\")\n\nThen a content region where we leave it the content provider to\ncomponent adaptation.\n \n >>> content = Region(\"content\", \".//div\", \"Content\")\n\nTo register them with the layout we simply add them.\n\n >>> layout.regions.add(title)\n >>> layout.regions.add(content)\n\nLet's define a context class.\n \n >>> class MockContext(object):\n ... interface.implements(interface.Interface)\n\nWe need to provide a general adapter that can provide content\nproviders for regions that do not specify them directly. As an\nexample, we'll define an adapter that simply tries to lookup a content\nprovider with the same name as the region.\n\n >>> from z3c.layout.interfaces import IContentProviderFactory\n\n >>> class EponymousContentProviderFactory(object):\n ... interface.implements(IContentProviderFactory)\n ...\n ... def __init__(self, region):\n ... self.region = region\n ...\n ... def __call__(self, context, request, view):\n ... name = self.region.name\n ... return component.getMultiAdapter(\n ... (view.context, request, view), IContentProvider, name)\n\n >>> from z3c.layout.interfaces import IRegion\n \n >>> component.provideAdapter(\n ... EponymousContentProviderFactory, (IRegion,))\n \nRendering\n---------\n\nBefore we can render the layout, we need to register content providers\nfor the two regions. We'll use a mock class for demonstration.\n\n >>> from zope.contentprovider.interfaces import IContentProvider\n \n >>> class MockContentProvider(object):\n ... interface.implements(IContentProvider)\n ... \n ... __name__ = u\"\"\n ...\n ... def __init__(self, *args):\n ... pass\n ...\n ... def update(self):\n ... pass\n ...\n ... def render(self):\n ... return self.__name__\n ...\n ... def __repr__(self):\n ... return \"\" % self.__name__\n \n >>> from zope.publisher.interfaces.browser import IBrowserRequest\n >>> from zope.publisher.interfaces.browser import IBrowserView\n\n >>> component.provideAdapter(\n ... MockContentProvider, (MockContext, IBrowserRequest, IBrowserView),\n ... name=\"title\")\n\n >>> component.provideAdapter(\n ... MockContentProvider, (MockContext, IBrowserRequest, IBrowserView),\n ... name=\"content\")\n\nLet's instantiate the layout browser-view. We must define a context\nand set up a request.\n\n >>> from zope.publisher.browser import TestRequest\n \n >>> context = MockContext()\n >>> request = TestRequest()\n\nWe need to have the request be annotatable.\n\n >>> from zope.annotation.attribute import AttributeAnnotations\n >>> component.provideAdapter(\n ... AttributeAnnotations, (TestRequest,))\n \nThe view expects the context to adapt to ``ILayout``.\n \n >>> from z3c.layout.interfaces import ILayout\n >>> component.provideAdapter(\n ... lambda context: layout, (MockContext,), ILayout)\n\n >>> from z3c.layout.browser.layout import LayoutView\n >>> view = LayoutView(context, request)\n\nVerify that the layout view is able to get to these providers.\n \n >>> view.mapping\n {'content':\n (, ),\n 'title':\n (, )}\n\nNow for the actual output.\n\n >>> print view()\n \n \n \n \n title\n \n \n
content
\n \n \n\nTransforms\n----------\n\nTo support special cases where you need to use Python to transform the\nstatic HTML document at compile time, one or more transforms may be\ndefined.\n\n >>> from z3c.layout.model import Transform\n\nLet's add a transform that adds a language setting to the -tag.\n\n >>> def set_language(node):\n ... node.attrib[\"lang\"] = \"en\"\n \n >>> layout.transforms.add(\n ... Transform(set_language))\n\n >>> layout.parse().getroot().attrib[\"lang\"]\n 'en'\n\nAnd another transform that assigns a class to the -tag.\n\n >>> def set_class(node, value):\n ... node.attrib[\"class\"] = value\n \n >>> layout.transforms.add(\n ... Transform(lambda body: set_class(body, \"front-page\"), \".//body\"))\n\n >>> layout.parse().xpath('.//body')[0].attrib[\"class\"]\n 'front-page'", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "zope3 layout HTML", "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "z3c.layout", "package_url": "https://pypi.org/project/z3c.layout/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/z3c.layout/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/z3c.layout/0.2/", "requires_dist": null, "requires_python": null, "summary": "HTML layout engine", "version": "0.2" }, "last_serial": 802045, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "52ac44b7eac5c763c0379c762138ab9b", "sha256": "4e4e616e501f75ad631e8adc2779e59b75273d7ac9840d10b1225c1f8141bd37" }, "downloads": -1, "filename": "z3c.layout-0.1.tar.gz", "has_sig": false, "md5_digest": "52ac44b7eac5c763c0379c762138ab9b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12051, "upload_time": "2008-07-30T15:58:19", "url": "https://files.pythonhosted.org/packages/d1/aa/ee7c2672c5187823840fe2344ae54f56124281d848531060dbd78c0e1325/z3c.layout-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "85a649bbabeb2dc165a531ca38a55661", "sha256": "0d7f1a71f2e92a71f2b02b77bf08eb69a1d1c5d28c3d7541f7f531310efa6e90" }, "downloads": -1, "filename": "z3c.layout-0.2.tar.gz", "has_sig": false, "md5_digest": "85a649bbabeb2dc165a531ca38a55661", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11627, "upload_time": "2008-08-04T02:17:17", "url": "https://files.pythonhosted.org/packages/88/fd/fc9361bf3add7e3eb3c4f56b42f52a41a0d260a5dd465f9a54f0697ed6ee/z3c.layout-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "85a649bbabeb2dc165a531ca38a55661", "sha256": "0d7f1a71f2e92a71f2b02b77bf08eb69a1d1c5d28c3d7541f7f531310efa6e90" }, "downloads": -1, "filename": "z3c.layout-0.2.tar.gz", "has_sig": false, "md5_digest": "85a649bbabeb2dc165a531ca38a55661", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11627, "upload_time": "2008-08-04T02:17:17", "url": "https://files.pythonhosted.org/packages/88/fd/fc9361bf3add7e3eb3c4f56b42f52a41a0d260a5dd465f9a54f0697ed6ee/z3c.layout-0.2.tar.gz" } ] }