1 | | (This is related to #1262, which is not a bug, so, it should be a wiki entry. However, I can't attach files because Akismet thinks I'm a spammer. Someone please attach here the file that's attached to #1262). |
2 | | |
3 | | === What is it? === |
4 | | |
5 | | * Attached is an adaptation of the port of RoR's JavascriptHelpers (http://pylonshq.com/project/pylons/browser/RailsHelpers) by Ben Bangert to Django tag library. |
6 | | |
7 | | * It also includes port of Eugene's LiveFilter?(dojo) to prototype (DelayedObserver in observer.js). |
8 | | |
9 | | === Usage === |
10 | | |
11 | | {{{ |
12 | | {% rails function_name (arg1,arg2,kwarg1=3,...) %} |
13 | | |
14 | | or |
15 | | |
16 | | {% rails function_name %} |
17 | | arg1,arg2, |
18 | | arg3, |
19 | | kwarg1=value1, |
20 | | kwarg2=value2, |
21 | | ... |
22 | | {% endrails %} |
23 | | }}} |
24 | | |
25 | | === Usage Examples === |
26 | | |
27 | | {{{ |
28 | | {% load railshelper %} |
29 | | |
30 | | {% rails link_to_function ("Greeing", "alert('Hello World')") %} |
31 | | |
32 | | {% rails link_to_remote %} |
33 | | "Delete this post", |
34 | | {'update':"posts",'url':"./destroy"} |
35 | | {% endrails %} |
36 | | |
37 | | {% rails observe_form %} |
38 | | "searchform", |
39 | | url='?format=ahah', |
40 | | update='results', |
41 | | delay=0.3, |
42 | | method='get', |
43 | | complete="SEL.setup('product_list');", |
44 | | {% endrails %} |
45 | | }}} |
46 | | |
47 | | === Issues === |
48 | | |
49 | | * Used exec to do the parameter parsing. So people may not like it, but this was the quickest way I could think of. External parameter is exec-ed only within a function argument: |
50 | | |
51 | | {{{ |
52 | | def argparser(*args, **kws): |
53 | | return args, kws |
54 | | exec("args, kws=argparser("+param+")") |
55 | | }}} |
56 | | |
57 | | I could not think of any malicious thing to do in function argument but probably there are many. Please let me know. |
58 | | |
59 | | * Easily modifiable to render passed parameter as django template. |
60 | | * Tested only "link_to_remote", "observe_form" in real web browser (IE, FF, Opera). |