class WebApplication(spye.plugin): def __init__(self, parent): self.links = [] super(WebApplication, self).__init__(parent) def add_script(self, url, mimetype = "text/javascript"): self.links.append(html.script(type = mimetype, src = url)) def add_stylesheet(self, url, mimetype = "text/css", relation = "stylesheet", media = "all"): self.links.append(html.link(type = mimetype, rel = relation, href = url, media = media)) def construct(self, title, *content): v = Compiler(self) v.append_string('{"foo": "bar"}') # v.append_string('dict(foo = "bar")') v.append("function Q(id)\n{\n return $(js(id))\n};", "Shared code") v.append_class(controls.Control, "Control") v.append_class(controls.Accordion, "Accordion") v.append_class(controls.Button, "Button") v.append_class(controls.DatePicker, "DatePicker") v.append("$(document).ready(function() { %s });" % v.compile_method(self.ready, "Initialization code")) # v.append("$(document).ready(function() { %s; $('#button').click(function () {alert('foo');}) });" % v.compile_method(self.ready, "Initialization code")) init = html.script("""\n%s""" % v, type = "text/javascript") self.doc = html.Document(title, self.links, (init,) + content) def ready(self): pass def present(self): return str(self.doc)