================
gocept.pagelet
================
Easier z3c.pagelet handling
.. contents::
Copyright (c) 2007-2016 gocept gmbh & co. kg
All Rights Reserved.
This software is subject to the provisions of the Zope Public License,
Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
FOR A PARTICULAR PURPOSE.
=========
Changes
=========
2.0 (2023-07-18)
================
- Drop support for Python 2.7, 3.5, 3.6.
- Add support for Python 3.9, 3.10, 3.11.
1.1 (2019-06-10)
================
- Claim support of Python 3.5, 3.6, 3.7, 3.8, PyPy and PyPy3.
- Use tox for testing.
1.0 (2016-04-06)
================
- Update `bootstrap.py` to a ``zc.buildout 2.3``.
- Use py.test as test runner.
- Declare the explicit support of Python 2.7.
No other Python versions are currently supported.
0.4 (2013-03-28)
================
- When registering a pagelet using ZCML which only has template, the name of
the template is rendered in the ``repr`` the generated class to have a
clue what is the purpose of this class when debugging.
- Updated tests to use Python's `doctest` instead of deprecated
`zope.testing.doctest`.
0.3 (2009-12-27)
================
- Using ``zope.browserpage`` and ``zope.browsermenu`` instead of
``zope.app.publisher``.
0.2 (2009-12-27)
================
- Allow arbitrary number of context elements for adaptation.
0.1 (2008-09-20)
================
- First public release.
==============
Contributors
==============
- Michael Howitz <mh at gocept dot com>
- Christian Theune <ct at gocept dot com>
=============================
Easy z3c.pagelet registration
=============================
The `<gocept:pagelet>` directive allows easier registration of
z3c.pagelets. It behaves quite like `<browser:page>`.
Setup
=====
We need some zcml setup:
>>> import sys
>>> from zope.configuration import xmlconfig
>>> import gocept.pagelet
>>> context = xmlconfig.file('meta.zcml', gocept.pagelet)
Template only
=============
It is possible to just use a template as pagelet. A class is not required:
>>> context = xmlconfig.string("""
... <configure
... xmlns:gocept="http://namespaces.gocept.com/zcml">
... <gocept:pagelet
... name="index.html"
... for="*"
... permission="zope.Public"
... template="test-template.pt"
... />
... </configure>
... """, context)
We should now have a page:
>>> import zope.component
>>> from zope.publisher.browser import TestRequest
>>> pagelet = zope.component.getMultiAdapter(
... (object, TestRequest()), name='index.html')
>>> pagelet
<gocept.pagelet.zcml.SimplePagelet from .../gocept/pagelet/test-template.pt object at 0x...>
>>> pagelet.__name__
u'index.html'
When we render the pagelet the test-template is used:
>>> pagelet.render()
u'Hello from the test template.\n'
Class only
==========
Of course it's also possible to register a class without a template. Create a
class and make it available in a module:
>>> from z3c.pagelet.browser import BrowserPagelet
>>> class MyPagelet(BrowserPagelet):
... """Custom pagelet"""
... def render(self):
... return u"Hello from the custom pagelet."""
Make it available under the fake package ``custom``:
>>> sys.modules['custom'] = type(
... 'Module', (),
... {'MyPagelet': MyPagelet})()
Make it available via ZCML:
>>> context = xmlconfig.string("""
... <configure
... xmlns:gocept="http://namespaces.gocept.com/zcml">
... <gocept:pagelet
... name="class.html"
... for="*"
... permission="zope.Public"
... class="custom.MyPagelet"
... />
... </configure>
... """, context)
Get the pagelet:
>>> pagelet = zope.component.getMultiAdapter(
... (object, TestRequest()), name='class.html')
>>> pagelet
<gocept.pagelet.zcml.MyPagelet object at 0x...>
>>> pagelet.render()
u'Hello from the custom pagelet.'
Class and template
==================
It's for course also possible to specify both class and template. So create
another pagelet class and register it:
>>> class MyPagelet2(BrowserPagelet):
... """Custom pagelet"""
... i_am_very_custom = True
>>> sys.modules['custom'] = type(
... 'Module', (),
... {'MyPagelet': MyPagelet2})()
Make it available via zcml:
>>> context = xmlconfig.string("""
... <configure
... xmlns:gocept="http://namespaces.gocept.com/zcml">
... <gocept:pagelet
... name="class-template.html"
... for="*"
... permission="zope.Public"
... class="custom.MyPagelet"
... template="test-template.pt"
... />
... </configure>
... """, context)
>>> pagelet = zope.component.getMultiAdapter(
... (object, TestRequest()), name='class-template.html')
>>> pagelet
<gocept.pagelet.zcml.MyPagelet2 object at 0x...>
>>> pagelet.render()
u'Hello from the test template.\n'
>>> pagelet.i_am_very_custom
True
Raw data
{
"_id": null,
"home_page": "https://github.com/gocept/gocept.pagelet",
"name": "gocept.pagelet",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "easy z3c.pagelet zope3 pagelet zope",
"author": "Christian Zagrodnick",
"author_email": "mail@gocept.com",
"download_url": "https://files.pythonhosted.org/packages/60/00/52f280d88249ea40e6fff0914df484520604e1a18074e65c809fe1e961be/gocept.pagelet-2.0.tar.gz",
"platform": null,
"description": "================\n gocept.pagelet\n================\n\nEasier z3c.pagelet handling\n\n.. contents::\n\n\nCopyright (c) 2007-2016 gocept gmbh & co. kg\nAll Rights Reserved.\n\nThis software is subject to the provisions of the Zope Public License,\nVersion 2.1 (ZPL). A copy of the ZPL should accompany this distribution.\nTHIS SOFTWARE IS PROVIDED \"AS IS\" AND ANY AND ALL EXPRESS OR IMPLIED\nWARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS\nFOR A PARTICULAR PURPOSE.\n\n\n=========\n Changes\n=========\n\n2.0 (2023-07-18)\n================\n\n- Drop support for Python 2.7, 3.5, 3.6.\n\n- Add support for Python 3.9, 3.10, 3.11.\n\n\n1.1 (2019-06-10)\n================\n\n- Claim support of Python 3.5, 3.6, 3.7, 3.8, PyPy and PyPy3.\n\n- Use tox for testing.\n\n\n1.0 (2016-04-06)\n================\n\n- Update `bootstrap.py` to a ``zc.buildout 2.3``.\n\n- Use py.test as test runner.\n\n- Declare the explicit support of Python 2.7.\n No other Python versions are currently supported.\n\n0.4 (2013-03-28)\n================\n\n- When registering a pagelet using ZCML which only has template, the name of\n the template is rendered in the ``repr`` the generated class to have a\n clue what is the purpose of this class when debugging.\n\n- Updated tests to use Python's `doctest` instead of deprecated\n `zope.testing.doctest`.\n\n\n0.3 (2009-12-27)\n================\n\n- Using ``zope.browserpage`` and ``zope.browsermenu`` instead of\n ``zope.app.publisher``.\n\n\n0.2 (2009-12-27)\n================\n\n- Allow arbitrary number of context elements for adaptation.\n\n0.1 (2008-09-20)\n================\n\n- First public release.\n\n\n==============\n Contributors\n==============\n\n- Michael Howitz <mh at gocept dot com>\n\n- Christian Theune <ct at gocept dot com>\n\n\n=============================\nEasy z3c.pagelet registration\n=============================\n\nThe `<gocept:pagelet>` directive allows easier registration of\nz3c.pagelets. It behaves quite like `<browser:page>`.\n\nSetup\n=====\n\nWe need some zcml setup:\n\n>>> import sys\n>>> from zope.configuration import xmlconfig\n>>> import gocept.pagelet\n>>> context = xmlconfig.file('meta.zcml', gocept.pagelet)\n\n\nTemplate only\n=============\n\nIt is possible to just use a template as pagelet. A class is not required:\n\n>>> context = xmlconfig.string(\"\"\"\n... <configure\n... xmlns:gocept=\"http://namespaces.gocept.com/zcml\">\n... <gocept:pagelet\n... name=\"index.html\"\n... for=\"*\"\n... permission=\"zope.Public\"\n... template=\"test-template.pt\"\n... />\n... </configure>\n... \"\"\", context)\n\nWe should now have a page:\n\n>>> import zope.component\n>>> from zope.publisher.browser import TestRequest\n>>> pagelet = zope.component.getMultiAdapter(\n... (object, TestRequest()), name='index.html')\n>>> pagelet\n<gocept.pagelet.zcml.SimplePagelet from .../gocept/pagelet/test-template.pt object at 0x...>\n>>> pagelet.__name__\nu'index.html'\n\nWhen we render the pagelet the test-template is used:\n\n>>> pagelet.render()\nu'Hello from the test template.\\n'\n\n\nClass only\n==========\n\nOf course it's also possible to register a class without a template. Create a\nclass and make it available in a module:\n\n\n>>> from z3c.pagelet.browser import BrowserPagelet\n>>> class MyPagelet(BrowserPagelet):\n... \"\"\"Custom pagelet\"\"\"\n... def render(self):\n... return u\"Hello from the custom pagelet.\"\"\"\n\nMake it available under the fake package ``custom``:\n\n>>> sys.modules['custom'] = type(\n... 'Module', (),\n... {'MyPagelet': MyPagelet})()\n\n\nMake it available via ZCML:\n\n>>> context = xmlconfig.string(\"\"\"\n... <configure\n... xmlns:gocept=\"http://namespaces.gocept.com/zcml\">\n... <gocept:pagelet\n... name=\"class.html\"\n... for=\"*\"\n... permission=\"zope.Public\"\n... class=\"custom.MyPagelet\"\n... />\n... </configure>\n... \"\"\", context)\n\nGet the pagelet:\n\n>>> pagelet = zope.component.getMultiAdapter(\n... (object, TestRequest()), name='class.html')\n>>> pagelet\n<gocept.pagelet.zcml.MyPagelet object at 0x...>\n>>> pagelet.render()\nu'Hello from the custom pagelet.'\n\n\n\nClass and template\n==================\n\nIt's for course also possible to specify both class and template. So create\nanother pagelet class and register it:\n\n>>> class MyPagelet2(BrowserPagelet):\n... \"\"\"Custom pagelet\"\"\"\n... i_am_very_custom = True\n>>> sys.modules['custom'] = type(\n... 'Module', (),\n... {'MyPagelet': MyPagelet2})()\n\n\nMake it available via zcml:\n\n>>> context = xmlconfig.string(\"\"\"\n... <configure\n... xmlns:gocept=\"http://namespaces.gocept.com/zcml\">\n... <gocept:pagelet\n... name=\"class-template.html\"\n... for=\"*\"\n... permission=\"zope.Public\"\n... class=\"custom.MyPagelet\"\n... template=\"test-template.pt\"\n... />\n... </configure>\n... \"\"\", context)\n\n>>> pagelet = zope.component.getMultiAdapter(\n... (object, TestRequest()), name='class-template.html')\n>>> pagelet\n<gocept.pagelet.zcml.MyPagelet2 object at 0x...>\n>>> pagelet.render()\nu'Hello from the test template.\\n'\n>>> pagelet.i_am_very_custom\nTrue\n",
"bugtrack_url": null,
"license": "ZPL 2.1",
"summary": "Easier z3c.pagelet handling",
"version": "2.0",
"project_urls": {
"Homepage": "https://github.com/gocept/gocept.pagelet"
},
"split_keywords": [
"easy",
"z3c.pagelet",
"zope3",
"pagelet",
"zope"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e819d6317f89b9c9fbcda6926a2d2ce5a6c93475e7bb93d19eef89095eda95a5",
"md5": "d84a0c8501f58f1f8652e7308fd7d3db",
"sha256": "7ef7da8967266e8028d4a9be61bfa778d1cfb7ccf18562a6059b49f928a549d6"
},
"downloads": -1,
"filename": "gocept.pagelet-2.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "d84a0c8501f58f1f8652e7308fd7d3db",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.7",
"size": 9659,
"upload_time": "2023-07-18T05:39:27",
"upload_time_iso_8601": "2023-07-18T05:39:27.774347Z",
"url": "https://files.pythonhosted.org/packages/e8/19/d6317f89b9c9fbcda6926a2d2ce5a6c93475e7bb93d19eef89095eda95a5/gocept.pagelet-2.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "600052f280d88249ea40e6fff0914df484520604e1a18074e65c809fe1e961be",
"md5": "0ed1fdd9fdd771b8dbe0df76ef495910",
"sha256": "9be6b40f948c6cdee4e5af91d5c707cc375142a327ecb6f610d9aa5315f0578d"
},
"downloads": -1,
"filename": "gocept.pagelet-2.0.tar.gz",
"has_sig": false,
"md5_digest": "0ed1fdd9fdd771b8dbe0df76ef495910",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 9213,
"upload_time": "2023-07-18T05:39:29",
"upload_time_iso_8601": "2023-07-18T05:39:29.351458Z",
"url": "https://files.pythonhosted.org/packages/60/00/52f280d88249ea40e6fff0914df484520604e1a18074e65c809fe1e961be/gocept.pagelet-2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-18 05:39:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gocept",
"github_project": "gocept.pagelet",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "gocept.pagelet"
}