{ "info": { "author": "Roger Ineichen and the Zope Community", "author_email": "zope3-dev@zope.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "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": "Macro viewlets are Zope 3 UI components. In particular they allow the developer\nto specify viewlets based on macros instead of entire templates.\n\n.. contents::\n\n==============\nMacro Provider\n==============\n\nThis package provides a ZCML directive which allows you to register a macro\ndefined in a template as a viewlet. Such a macro based viewlet acts 100% the\nsame as a other viewlets. It could be very handy if you want to write a layout\ntemplate in one page template and define selective parts as viewlets without\nadding any additional HTML. Let me show what this will look like:\n\nThe layout/master template can look like this::\n\n \n \n \n \n \n The title\n \n \n \n \n
\n content\n
\n \n \n \n\nThe tempalte above defines an ITitle provider which contains the definition\nfor a macro within itself. You have to define a viewlet manager within the\nzope.viewlet ZCMl directive which provides ITitle as a viewlet manager.\nAfter that, you can register the template above as a layout template wthin\nthe z3c:layout ZCML directive like this::\n\n \n\nThen you can register the macro viewlet for the ITitle viewlet manager\nlike this::\n\n \n\nAs you can see, the ZCML configuration directive above uses ``title`` as the\nmacro attribute and uses ITitle as the viewlet manager. This will use the\nfollowing part of the template.pt::\n\n Pagelet skin\n\nand registers it as a viewlet. This viewlet gets rendered in the ITitle\nprovider. As you can see, you can use a complete layout tempalte and use it\nas it is. And here it comes, you can offer an included viewlet manager\nrendering the viewlet which can be overriden for other contexts or views etc.\nYou also can register more than one viewlet for the ITitle viewlet manager.\nWhich of course makes no sense in our special title tag example.\n\nLet's show this in some tests. We'll start by creating a content object that\nis used as a view context later::\n\n >>> import zope.interface\n >>> import zope.component\n >>> from zope.publisher.interfaces.browser import IBrowserView\n >>> from zope.publisher.interfaces.browser import IDefaultBrowserLayer\n >>> class Content(object):\n ... zope.interface.implements(zope.interface.Interface)\n\n >>> content = Content()\n\nWe also create a temp dir for sample templates which will be defined later\nfor testing::\n\n >>> import os, tempfile\n >>> temp_dir = tempfile.mkdtemp()\n\nAnd we register a security checker for the MacroViewlet class::\n\n >>> from zope.configuration.xmlconfig import XMLConfig\n >>> import zope.app.component\n >>> import z3c.macroviewlet\n >>> XMLConfig('meta.zcml', zope.app.component)()\n >>> XMLConfig('configure.zcml', z3c.macroviewlet)()\n\n\nLayout template\n---------------\n\nWe define a template including a macro definition and using a provider::\n\n >>> path = os.path.join(temp_dir, 'template.pt')\n >>> open(path, 'w').write('''\n ... \n ... \n ... \n ... \n ... \n ... The title\n ... \n ... \n ... \n ... \n ... content\n ... \n ... \n ... ''')\n\nLet's register a view class using the view template::\n\n >>> import zope.interface\n >>> from zope.app.pagetemplate import viewpagetemplatefile\n >>> from zope.publisher.interfaces.browser import IBrowserView\n >>> class View(object):\n ... zope.interface.implements(IBrowserView)\n ... def __init__(self, context, request):\n ... self.context = context\n ... self.request = request\n ... def __call__(self):\n ... return viewpagetemplatefile.ViewPageTemplateFile(path)(self)\n\nLet's prepare the view::\n\n >>> from zope.publisher.browser import TestRequest\n >>> request = TestRequest()\n >>> view = View(content, request)\n\nLet's define the viewlet manager ``ITitle``::\n\n >>> from zope.viewlet.interfaces import IViewletManager\n >>> from zope.viewlet.manager import ViewletManager\n >>> class ITitle(IViewletManager):\n ... \"\"\"Viewlet manager located in the title tag.\"\"\"\n\n >>> title = ViewletManager('title', ITitle)\n\nLet's register the viewlet manager::\n\n >>> from zope.viewlet.interfaces import IViewletManager\n >>> manager = zope.component.provideAdapter(\n ... title,\n ... (zope.interface.Interface, TestRequest, IBrowserView),\n ... IViewletManager,\n ... name='ITitle')\n\n\nMacroViewlet\n------------\n\nBefore we register the macro viewlet, we check the rendered page without any\nregistered macro viewlet::\n\n >>> print view()\n \n \n \n \n \n content\n \n \n\nAs you can see there is no title rendered. Now we can define the macro\nviewlet...::\n\n >>> from zope.app.pagetemplate import viewpagetemplatefile\n >>> from z3c.macroviewlet import zcml\n >>> macroViewlet = zcml.MacroViewletFactory(path, 'title', 'text/html')\n\nand register them as adapter::\n\n >>> from zope.viewlet.interfaces import IViewlet\n >>> zope.component.provideAdapter(\n ... macroViewlet,\n ... (zope.interface.Interface, IDefaultBrowserLayer, IBrowserView,\n ... ITitle),\n ... IViewlet,\n ... name='title')\n\nNow we are ready to test it again::\n\n >>> print view()\n \n \n \n The title\n \n \n content\n \n \n\nAs you can see, the title gets rendered as a viewlet into the ITitle provider.\n\nCleanup\n-------\n\n >>> import shutil\n >>> shutil.rmtree(temp_dir)\n\n\n\n=======\nChanges\n=======\n\n1.1.0 (2010-07-14)\n------------------\n\n- Fixed tests to run with current package versions\n (``metaconfigure.registerType`` moved from ``zope.app.pagetemplate``\n to ``zope.browserpage``). Thus requiring ``zope.browserpage`` now.\n\n- No longer use depreacted ``zope.testing.doctest`` and\n ``zope.testing.doctestunit``.\n\n- Removed ZPKG and ZCML slugs.\n\n- Fixed RST formatting in README.\n\n\n\n1.0.0 (2007-09-21)\n------------------\n\n- Initial Release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://svn.zope.org/z3c.macroviewlet", "keywords": "zope3 template macro viewlet zpt pagetemplate", "license": "ZPL 2.1", "maintainer": null, "maintainer_email": null, "name": "z3c.macroviewlet", "package_url": "https://pypi.org/project/z3c.macroviewlet/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/z3c.macroviewlet/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://svn.zope.org/z3c.macroviewlet" }, "release_url": "https://pypi.org/project/z3c.macroviewlet/1.1.0/", "requires_dist": null, "requires_python": null, "summary": "Viewlets based on ZPT macros.", "version": "1.1.0" }, "last_serial": 802049, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "a5a29c456c6b8bad383f4d7dc60792b5", "sha256": "addb86c5b55bf7ef3bd4d8b29097fefd8b4d0db2335b37dd8c855f72a1f9ea44" }, "downloads": -1, "filename": "z3c.macroviewlet-1.0.0-py2.4.egg", "has_sig": false, "md5_digest": "a5a29c456c6b8bad383f4d7dc60792b5", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 15067, "upload_time": "2007-09-21T22:36:18", "url": "https://files.pythonhosted.org/packages/d6/54/b90d54e29611f65bbdaab7434eada7b815d31220669ea91443c46fea7b00/z3c.macroviewlet-1.0.0-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "ac24dadac2cf45e4493c65813cfabd97", "sha256": "25297a09c98ffd0ab06061ca8967632a902fa150cdf59c6a3c5d5618770312bb" }, "downloads": -1, "filename": "z3c.macroviewlet-1.0.0.tar.gz", "has_sig": false, "md5_digest": "ac24dadac2cf45e4493c65813cfabd97", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8796, "upload_time": "2007-09-21T22:36:10", "url": "https://files.pythonhosted.org/packages/18/14/5e1f0ade653add0ae2143b741142cd4a9d38eb2fcd3e2fd8a68757abf670/z3c.macroviewlet-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "da0363eb1d23c40e107eacb72244798b", "sha256": "4c450828a49385b18fe71009a2d14f06a31497048f0b05ab289dc488f870e145" }, "downloads": -1, "filename": "z3c.macroviewlet-1.1.0.tar.gz", "has_sig": false, "md5_digest": "da0363eb1d23c40e107eacb72244798b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8563, "upload_time": "2010-07-14T08:23:57", "url": "https://files.pythonhosted.org/packages/63/54/13054be548ff05cb18b0ef226965fde987ea5d70c225c6145d25986cf834/z3c.macroviewlet-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "da0363eb1d23c40e107eacb72244798b", "sha256": "4c450828a49385b18fe71009a2d14f06a31497048f0b05ab289dc488f870e145" }, "downloads": -1, "filename": "z3c.macroviewlet-1.1.0.tar.gz", "has_sig": false, "md5_digest": "da0363eb1d23c40e107eacb72244798b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8563, "upload_time": "2010-07-14T08:23:57", "url": "https://files.pythonhosted.org/packages/63/54/13054be548ff05cb18b0ef226965fde987ea5d70c225c6145d25986cf834/z3c.macroviewlet-1.1.0.tar.gz" } ] }