Tweakers
From bemoko developer wiki
Overview
Tweakers allow you to tweak the content from sites before it is delivered to the device. It allows known device issues to be fixed as well as applying common functionality to all pages. Note that a tweaker is used in development mode to render debug information and error information to the screen. Tweakers can be applied based on context expressions so that you have fine control over when a tweaker should be applied and when it shouldn't
A Simple Tweaker
Tweakers are defined in the site configuration file, e.g to apply the tweaker to all devices that resolved as a "320" UI ...
<tweakers> <tweaker plugin="MySimpleTweaker" expr="ui.is('320')"/> </tweakers>
The following tweaker will add a piece of content to all the pages outputted from the site - so in this case it will appear on all devices that are 320px wide or greater.
class MySimpleTweaker extends AbstractTweakerPlugin { void tweakMarkup(Node node){ /* * Get the body node and only add the content if it exists */ def body=node.body[0] if (body.children().size()>0) { /* * Create a node for the content we want to add */ def myNode = (new NodeBuilder()).div (id:'wrapper') { span("This content was generated by MySimpleTweaker") } /* * Add all children of the body to this node - i.e. wrap myNode in the body children */ myNode.children().addAll(body.children()) /* * ... and then replace the children with this new node so that the markup is delivered to the device */ body.children().removeAll(body.children()) body.children().add(myNode) } } }
