skip to navigation
skip to content

Bumblebee 1.0a2

deliverance-like implementation that only works on html output(no theme file)


Bumblebee is a deliverance-like html transformation framwork implementation that only works on the output an html document.

It doesn’t use xslt so it isn’t as fast as what Diazo is; however, it accomplishes the very simple use-case of moving elements around on html output.


Because I almost never needed the full-fledge deliverance approach for what I wanted to do. In fact, it was usually an annoyance when all I wanted to do was move an element around on a page.

How-to Use

Configurating your transformations is done with a very xml syntax.



        <div id="#header"></div>
        <div id="content"></div>
        <div id="footer"></div>

Rules XML:

    <block if-content="#content">
        <after src="#header" dst="#footer" />

Running it through:

from bumblebee import transform
from repoze.xmliter.utils import getHTMLSerializer
from bumblebee.xml import convertRules

html = getHTMLSerializer(output)
rules = convertRules(rules_xml)
result = transform(html, rules)


For xml configuration that selects elements, you can use CSS selectors(default) or XPath.

To use XPath, just append ‘-path’ onto the node name:

<after src-xpath="/html/body/div[0]" src-xpath="/html/body/div[2]" />

arbitrary html

Use this to inject html into a page:

<after src-html="" dst="#foo">
    <div id="foobar">
        <h1>hello, world</h1>



Move an element before another element:

<before src="#foo" dst="#bar" />

Moves “#foo” before “#bar”


Move an element after another:

<after src="#foo" "#bar" />

Moves “#foo” after “#bar”


Remove an element from the dom:

<drop src="#foo" />


Replace an element with another:

<replace src="#foo" dst="#bar" />

Replaces “#dst” with “#src”


Add or remove classes from an element:

<class src="#foo" add="three four" remove="one two" />

Remove the classes “one” and “two” from “#foo” and add the classes “three” and “four”.


Change a tag:

<tag src="#foo" tag="p" />


Group rules together with a conditions:

<group if-content="#foo">
    <drop src="#bar" />

Performs some rules if “#foo” is in the document.



Performs actions if the selector is found in the document:

<after src="#foo" dst="#bar" if-content="#foo" />

not conditiion

Any condition can be negated for the opposite affect:

<drop src="#foo" if-not-content="#bar" />


Creating a Rule:

from bumblebee.rules import BaseDouble
class Append(BaseDouble):
    def __call__(self, root):
        src, dst, skip = self.process_nodes(root)
        if skip:
            return None
        dst = dst[0]
        for el in dst:
        return src

from bumblebee.xml import addTag
addTag('append', Append)

To use the rule, you would:

<append src="#foo" dst="#bar" />

Creating a Condition:

from bumblebee.conditions import BaseIf
class IfPath(BaseIf):
    def __init__(self, path, extras={}):
        super(IfPath, self).__init__(extras)
        self.path = path
    def __call__(self, root):
        req = self.extras['request']
        path = req['PATH_INFO']
        if self.path.startswith('/'):
            return path.startswith(self.path)
            return self.path in path
from bumblebee.xml import addCondition
addCondition('path', IfPath)

To use this condition, you would:

<drop src="#foo" if-path="/foo/bar" />


<drop src="#foo" if-not-path="/foo/bar" />


1.0a2 ~ (2011-09-22)

  • add support for arbitrary html
  • better support for adding new selectors, conditions, rules
  • better parsing
  • better handle extras parameters so that rules can be more easily cached
File Type Py Version Uploaded on Size (md5) Source 2011-09-22 18KB
  • Downloads (All Versions):
  • 1 downloads in the last day
  • 38 downloads in the last week
  • 221 downloads in the last month