Created
January 13, 2013 08:50
-
-
Save colwilson/4523031 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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