Skip to content

Instantly share code, notes, and snippets.

@colwilson
Created January 13, 2013 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colwilson/4523031 to your computer and use it in GitHub Desktop.
Save colwilson/4523031 to your computer and use it in GitHub Desktop.
from nagare import presentation
class Counter(object):
def __init__(self):
self.val = 0
def increase(self):
self.val += 1
def decrease(self):
self.val -= 1
@presentation.render_for(Counter)
def render(counter, h, *args):
h << h.div('Value: ', counter.val)
h << h.a('++').action(counter.increase)
h << '|'
h << h.a('--').action(counter.decrease)
return h.root
@presentation.init_for(Counter, 'len(url) == 1 and url[0] == "Counter"')
def init(self, url, comp, http_method, request):
"""
Meaningful URLs are uses to initialize a component with the received URL.
Other than that application works the same as it used to do.
"""
value = request.params.get('value')
if value and value.isdigit():
self.val = int(value)
app = Counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment