Browse files

Greatly expanded the documentation.

  • Loading branch information...
1 parent 8a33102 commit 15ecc2f26083cacf3cf10c82b0d7ab18eca53f26 @jjinux committed Mar 24, 2011
Showing with 36 additions and 2 deletions.
  1. +36 −2 pyteladventure/choice.py
View
38 pyteladventure/choice.py
@@ -2,14 +2,48 @@ class Choice(object):
"""This is a little DSL for choices.
+ It allows me to succinctly capture a choice that the user might select
+ such as "Press 9 in order to..."
+
+ label
+ This is a "friendly" name for the choice. It's used in the tests
+ so that I don't have to hardcode magical numbers.
+
+ digits
+ This is what the user has to actually type in on his phone.
+
+ view_callback
+ This callback is called when the list of options is being given to
+ the user. It should play or say something.
+
+ controller_callback
+ This callback is called when the user selects a given option.
+ Generally you should just redirect the user somewhere.
+
+ Example:
+
Choice(
label="root_menu",
digits="*2",
view_callback=lambda:
- render_template("play.xml", url=some_url),
- controller_block=lambda:
+ Markup(render_template("play.xml", url=some_url)),
+ controller_callback=lambda:
redirect(some_url))
+ Warning about Closures
+ ----------------------
+
+ Be careful about code like:
+
+ for i in xrange(10):
+ ...lambda: f(i)
+
+ The i will always be 9, even though you might expect each lambda to have
+ its own version of i. Try this instead:
+
+ for i in xrange(10):
+ ...lambda i=i: f(i)
+
"""
def __init__(self, label, digits, view_callback, controller_callback):

0 comments on commit 15ecc2f

Please sign in to comment.