{
"info": {
"author": "Robin Harms Oredsson",
"author_email": "robin@betahaus.net",
"bugtrack_url": null,
"classifiers": [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Pyramid",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content"
],
"description": ".. image:: https://travis-ci.org/robinharms/betahaus.viewcomponent.png?branch=master\r\n :target: https://travis-ci.org/robinharms/betahaus.viewcomponent\r\n\r\nbetahaus.viewcomponent README\r\n=============================\r\n\r\nReusable components in web pages make them a lot more fun and rewarding to write.\r\nThe goal of this package is to make them easy to add, remove and change.\r\nWhile it's usable in a regular webapp, it's probably more interesting to use\r\nin something that others will extend or change, like a framework.\r\n\r\nIt's written to be flexible and easy to adapt, rather than being the perfect solution to everything.\r\n\r\n\r\nBasic example - adding a logo\r\n-----------------------------\r\n\r\nFirst, create a method that returns an html tag.\r\nWe also need to decorate this method.\r\nThe va positional argument is a ViewAction - we can ignore that\r\nin this example.\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import view_action\r\n @view_action('stuff', 'logo')\r\n def logo_tag(context, request, va):\r\n return '
'\r\n\r\nWhen you run ``config.scan('your-apps-name')`` with this code present,\r\nit will create a ViewGroup with the name 'stuff', that has a ViewAction\r\ncalled 'logo'.\r\n\r\nYou may optionally use a directive of the config object.\r\nYou need to include ``betahaus.viewcomponent`` in that case.\r\n\r\n.. code-block:: python\r\n\r\n #Code in your package\r\n \r\n def logo_tag(context, request, va):\r\n return '
'\r\n \r\n def includeme(config):\r\n config.add_view_action(logo_tag, 'stuff', 'logo')\r\n\r\n\r\nThe ViewGroup is an ordered dict-like Utility, that keeps track of ViewActions.\r\n\r\nIf you want to get the result of a ViewGroup, simply do this:\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import render_view_group\r\n render_view_group(context, request, 'stuff')\r\n\r\nSince there's nothing else in this ViewGroup, only the logo tag will be returned.\r\n\r\nTo get the result of a single ViewAction only, you can call ``render_view_action``:\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import render_view_action\r\n render_view_action(context, request, 'stuff', 'logo')\r\n\r\n\r\nAnother example - building a menu\r\n---------------------------------\r\n\r\nSo you have a webapp, and you want a menu somewhere. And then package X, Y and Z\r\nworks as plugins, but how do they add to that menu of yours?\r\n(Read the Pyramid docs on how to create views)\r\n\r\nFirst, let's create minimal Python view code:\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import render_view_group\r\n from pyramid.view import view_config\r\n \r\n @view_config(renderer = 'some/template.pt')\r\n def main_template(context, request):\r\n return dict(render_view_group = render_view_group)\r\n \r\nAnd then the template:\r\n\r\n.. code-block:: html\r\n\r\n \r\n