Magic Method ExercisesΒΆ
Exercise
In Recipe #1, add a dump(tag, filename)
function that generates output to a UTF-8 encoded file. (That is, it should be able to generate HTML pages that correctly display international characters.)
Exercise
The calls to dojo.require()
are hard coded inside the dijit
function, which in general is not a good idea. Make it so that the require JavaScript section is dynamically generated based on what tags you use.
Exercise
Add a load(filename)
function that converts an XML file to a hierarchy of Tag
objects. You should be able to process XML files like this:
<div>
<p>
This is a Button <button>Click me!</button>
</p>
<p>
This is a TextBox <textbox value="The cow jumped over the moon, and it exploded" />
</p>
<p>
This is a CheckBox <checkbox checked="checked" />
</p>
<p>
This is a DateTextBox <datetextbox value="1998-03-23" />
</p>
</div>
Exercise
Write a decorator for Django (or your web framework of choice) that allows you to do this:
@dijit("view.xml")
def view(request):
return dict(name=request['name'], place=request['place'])
Where view.xml
is an XML template file that specifies a Dijit interface.
Exercise
In Recipe #2, add a load(filename)
function that converts an XML file to a ContainerWrapper
object. You should be able to handle XML files like this
<VFrame>
<Button text="One" />
<Button text="Two" />
<Button text="Tree" />
<HFrame>
<Button text="Apple" />
<Button text="Banana" />
<Button text="Cranberry" />
</HFrame>
</HFrame>