/
RenderPlugin.txt
160 lines (134 loc) · 5.56 KB
/
RenderPlugin.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
%META:TOPICINFO{author="ProjectContributor" comment="autosave" date="1356278778" format="1.1" version="4"}%
---+!! %TOPIC%
%SHORTDESCRIPTION%
%TOC%
---++ Description
This plugin implements three simple REST handlers to get content from Foswiki.
For example, these can be used to easily replace a server-side INCLUDE with a
functional equivalent using an ajax call to one of these REST handlers.
This comes in handy to asynchronously load content in a tabbed interface,
loading subsequent content for a treeview, a menu widget, or tooltips.
You may also use it to just render a snippet of <nop>TopicMarkup
on the server and return a HTML preview back to the browser.
The REST handlers of this plugin have been designed to be rather generic.
So, besides some very basic parameter checking, most error handling is up
to the callback analysing the return value of the REST handler. The
main purpose is best described as being an intermediate transport device.
Compare this to other plugins that implement more specific REST handlers.
As such, they are rather tailored to one specific service and thus will be dealing with
error cases on the server side in much more detail.
The advantage of using this plugin's REST handler is that you don't have
to implement service backends using perl. Instead, you can write <nop>TopicFunctions
that contain the <nop>WikiApplication to be executed when it is called by an
appropriate ajax request. This basically is the client side equivalent of
a parametrized =INCLUDE=, as it is used on server side <nop>WikiApplications (see examples below).
---++ Syntax
The available REST handlers are:
| *Handler* | *Parameters* | *Description* |
| =expand= | =text= | expands common variables in the submitted =text= fragment |
| =render= | =text= | same as =expand= but also renders <nop>TopicMarkup converting it to HTML |
| =tag= | =name=, %BR% =param=, %BR% =<named-params>*=, %BR% =render= | this is a convenience function to expand one specific \
variable instead of having to build up a snippet of code that you want to =expand= or =render=; \
The =param= parameter specifies the default parameters to this tag; the =named-params= are additional \
named parameters; the =render= flag indicates if the result is to be expanded only \
or if it should be renderd into HTML; default is off, that is only expand common tags but don't interpret \
<nop>TopicMarkup |
| =template= | =name=, %BR% =expand=, %BR% =render= | this handler loads the template =name= and expands the macro \
given in =expand=; the =render= flag indicates whether the result is to be rendered in addition to common tags being interpreted |
---++ Usage
The REST handlers are called like this:
<verbatim>
%SCRIPTURLPATH{"rest"}%/RenderPlugin/render?text=%ENCODE{"This is _very_ cool."}%
</verbatim>
<verbatim>
%SCRIPTURLPATH{"rest"}%/RenderPlugin/tag?name=INCLUDE;param=Applications.RenderWebTagCloud;search=screenshot
</verbatim>
(equivalent to a =%<nop>INCLUDE{"Applications.RenderWebTagCloud" search="screenshot"}%=)
This can be schedule using jQuery like this:
<verbatim>
<div id="container"></div>
<literal>
<script>
jQuery(function($) {
$("#container").load("<url-to-rest-handler->");
});
</script>
</verbatim>
---++ Examples
---+++ Fetching a message
<verbatim>
%STARTSECTION{"message"}%
*Hello World!* :)
%ENDSECTION{"message"}%
</verbatim>
<input type="button" value="Get" onclick="getTheMessage()" />
<input type="button" value="Clear" onclick="clearTheMessage()" />
<div id="message" style="border:2px solid red;padding:5px;margin:10px;width:100px;background:yellow;display:none;">
</div>
<literal>
<script>
function getTheMessage() {
jQuery("#message").load(
"%SCRIPTURLPATH{"rest"}%/%TOPIC%/tag",
{
name: 'INCLUDE',
param: '%WEB%.%TOPIC%',
section: 'message',
render: true
},
function () {
jQuery(this).show()
});
}
function clearTheMessage() {
jQuery("#message").empty().hide();
}
</script>
</literal>
---+++ Previewing TML
<div class="foswikiPageForm">
<form>
<textarea id="mytext" name="text" rows="5" columns="80" style="width:100%"></textarea>
<input type="button" value="Preview" onclick="preview()" />
</form>
</div>
<div id="mypreview" style="border:1px solid #eee;padding:5px">
</div>
<literal>
<script>
function preview() {
var text = jQuery("#mytext").val();
jQuery("#mypreview").load("%SCRIPTURLPATH{"rest"}%/RenderPlugin/render",
{
'text': text,
'topic': '%WEB%.%TOPIC%'
}
);
}
</script>
</literal>
Okay, your turn to create an example calling SEARCH.
---++ Installation Instructions
%$INSTALL_INSTRUCTIONS%
---++ Plugin Info
<!--
One line description, required for extensions repository catalog.
* Set SHORTDESCRIPTION = Render <nop>WikiApplications asynchronously
-->
| Plugin Author: | Michael Daum |
| Copyright ©: | 2006-2014, Michael Daum http://michaeldaumconsulting.com |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order --> |
| 18 Mar 2014: | removed duplicate http header from =render= rest handler |
| 01 Nov 2013: | added support for =contenttype= url parameter |
| 10 Jan 2012: | some docu fixes |
| 12 May 2009: | added =template= handler |
| 24 Apr 2009: | converted to foswiki plugin |
| 07 Jan 2009: | added upload rest handler; \
fixes for foswiki and <nop>FastCGIContrib |
| 11 Jul 2008: | initial version |
| Dependencies: | %$DEPENDENCIES% |
| Plugin Home: | Foswiki:Extensions/%TOPIC% |
| Support: | Foswiki:Support/%TOPIC% |