betahaus.viewcomponent
Project description
Reusable components in web pages make them a lot more fun and rewarding to write. The goal of this package is to make them easy to add, remove and change. While it’s usable in a regular webapp, it’s probably more interesting to use in something that others will extend or change, like a framework.
It’s written to be flexible and easy to adapt, rather than being the perfect solution to everything.
Basic example - adding a logo
First, create a method that returns an html tag. We also need to decorate this method. The va positional argument is a ViewAction - we can ignore that in this example.
from betahaus.viewcomponent import view_action @view_action('stuff', 'logo') def logo_tag(context, request, va): return '<img src="img.png" />'
When you run config.scan('your-apps-name') with this code present, it will create a ViewGroup with the name ‘stuff’, that has a ViewAction called ‘logo’.
The ViewGroup is an ordered dict-like Utility, that keeps track of ViewActions.
If you want to get the result of a ViewGroup, simply do this:
from betahaus.viewcomponent import render_view_group render_view_group(context, request, 'stuff')
Since there’s nothing else in this ViewGroup, only the logo tag will be returned.
To get the result of a single ViewAction only, you can call render_view_action:
from betahaus.viewcomponent import render_view_action render_view_action(context, request, 'stuff', 'logo')
Feedback and features
The source code of the package is really small, and it should be commented enough so it’s easy to pick up what to do with it. The package is still under development, but used on several production servers today.
If you have suggestions, criticism, feedback, ideas - please don’t hesitate to contact me or add an issue at GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for betahaus.viewcomponent-0.1b.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9417f4f9a61f01cebb950422e799a8b4252bb7efd8991f9b198625bc9f49dac |
|
MD5 | cd31d8ba247fd5a8c534f354dafeb779 |
|
BLAKE2b-256 | 39b3587c243c0f65336c272c708ccc0b1526ed794fe3598a123aa96ad3eea2ab |