Skip to content

Commit

Permalink
remove debug code, add links to source files
Browse files Browse the repository at this point in the history
  • Loading branch information
anandology committed Mar 8, 2010
1 parent fda545b commit 7870e6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 10 additions & 1 deletion 2010/03/jsdef/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ jsdef extension adds a new block `jsdef` to [templetor][1] syntax. The `jsdef` b
[1]: http://webpy.org/docs/0.3/templetor

This extension works only with the development branch of web.py.

<http://github.com/webpy/webpy>

## How to use
Expand All @@ -15,6 +16,8 @@ Tell web.py to use the extension.
import jsdef

render = web.template.render("templates", extensions=[jsdef.extension])

Include [jsdef.js](jsdef.js) in your site template.

And use `jsdef` in your templates.

Expand All @@ -38,4 +41,10 @@ And use `jsdef` in your templates.
// Above jsdef block has generated javascript for render_books function. Use it at the client.
document.getElementById("books").innerHTML = render_books(books);
}
</script>
</script>

## Caveats
This is just an attempt to drive JavaScript templating from Python. Features like multiple assignments, list slicing, list comprehensions won't work.

If you are using a python function inside the jsdef block, you need to provide the equivalent in JavaScript too. Some builtin functions are already provided by [jsdef.js](jsdef.js).

7 changes: 7 additions & 0 deletions 2010/03/jsdef/jsdef.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* JavaScript companion for jsdef templetor extension.
*
* For more details, see:
* http://github.com/anandology/notebook/tree/master/2010/03/jsdef/
*/

/**
* Python range function.
*
Expand Down
6 changes: 3 additions & 3 deletions 2010/03/jsdef/jsdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
document.getElementById("books").innerHTML = render_books(books);
}
</script>
For more details, see:
http://github.com/anandology/notebook/tree/master/2010/03/jsdef/
"""

__author__ = "Anand Chitipothu <anandology@gmail.com>"
Expand Down Expand Up @@ -178,9 +181,6 @@ def jsemit_JSDefNode(self, node, indent):
text += "</script>\n"
return text

render = web.template.render("templates/", extensions=[extension])
print render.sample()

if __name__ == "__main__":
import doctest
doctest.testmod()

0 comments on commit 7870e6b

Please sign in to comment.