Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 246 lines (192 sloc) 7.94 kB
21abc5b @klacke Initial revision
authored
1
2 <erl>
3
67a6c13 @klacke ""
authored
4
dbab7a3 @klacke ssi include with var expansion + docs
authored
5 box(Str) ->
6 {'div',[{class,"box"}],
f6dbbc9 @klacke added possibility to name the module in a .yaws file
authored
7 {pre, [], yaws_api:htmlize(Str)}}.
21abc5b @klacke Initial revision
authored
8
dbab7a3 @klacke ssi include with var expansion + docs
authored
9 tbox(T) ->
10 box(lists:flatten(io_lib:format("~p",[T]))).
21abc5b @klacke Initial revision
authored
11
12
dbab7a3 @klacke ssi include with var expansion + docs
authored
13 ssi(File) ->
14 {'div',[{class,"box"}],
15 {pre,[],
16 {ssi, File,[],[]}}}.
21abc5b @klacke Initial revision
authored
17
7811247 @vinoski whitespace cleanup
vinoski authored
18 out(A) ->
757eca1 @klacke ""
authored
19 [{ssi, "TAB.inc", "%%",[{"dynamic", "choosen"}]},
20 {ehtml,
21 [{'div', [{id, "entry"}],
0be3c7e @klacke untabified all of yaws
authored
22 [
23 {h1, [],"Generating Dynamic Content"},
24 {p,[], ["Yaws has very nice support for generating dynamic content on the fly. "
25 "We use embedded erlang code to generate the content. The Erlang code "
26 "is separated from the HTML code by ",
7811247 @vinoski whitespace cleanup
vinoski authored
27 {tt, [], "&lt;erl&gt;"},
0be3c7e @klacke untabified all of yaws
authored
28 " and ",
29 {tt, [], "\&lt;/erl&gt;"},
30 " markers. For example: "]},
7811247 @vinoski whitespace cleanup
vinoski authored
31
0be3c7e @klacke untabified all of yaws
authored
32 box("
dbab7a3 @klacke ssi include with var expansion + docs
authored
33 <html>
d69e4d8 @klacke ""
authored
34 <h1>Foobar</h1>
3b9e4a1 @klacke new ret vals from out/1
authored
35 \<erl>
7811247 @vinoski whitespace cleanup
vinoski authored
36
d69e4d8 @klacke ""
authored
37 out(Arg) ->
dbab7a3 @klacke ssi include with var expansion + docs
authored
38 {html, \"Funky Stuff\"}.
3b9e4a1 @klacke new ret vals from out/1
authored
39 \</erl>
7811247 @vinoski whitespace cleanup
vinoski authored
40
d69e4d8 @klacke ""
authored
41 <h1>Baz</h1>
7811247 @vinoski whitespace cleanup
vinoski authored
42
d69e4d8 @klacke ""
authored
43 </html>
dbab7a3 @klacke ssi include with var expansion + docs
authored
44 "),
7811247 @vinoski whitespace cleanup
vinoski authored
45
0be3c7e @klacke untabified all of yaws
authored
46 {p,[], ["Is a very small example where we have a HTML document with embedded "
47 "erlang code. A file which contains embedded erlang code must have the file "
48 "suffix ",
49 {tt, [], ".yaws"}]},
50 {br,[],[]},
7811247 @vinoski whitespace cleanup
vinoski authored
51
0be3c7e @klacke untabified all of yaws
authored
52 {p, [], "The embedded erlang code can return the different values which will "
53 " trigger the yaws webserver to do different things. We list some of the simple "
54 " return values here: "},
7811247 @vinoski whitespace cleanup
vinoski authored
55
0be3c7e @klacke untabified all of yaws
authored
56 {ul, [],
57 [{li,[],
58 [{p, [],
59 [{tt,[],"{html, DeepCharOrBinaryList}"},
60 " Which will make the value of ",
61 {tt, [],"DeepCharOrBinaryList"},
62 " be substituted into the HTML document."]}]},
63 {li,[],
64 {p,[],
65 [{tt,[],"{ehtml, ErlangTermStructure}"}]}}]},
7811247 @vinoski whitespace cleanup
vinoski authored
66
67 {p, [],
0be3c7e @klacke untabified all of yaws
authored
68 ["It is often more convenient to return "
69 "erlang terms which are then transformed to HTML instead "
70 "of returning plain HTML in string form using the ",
71 {tt,[], "html"}, " tag "]},
7811247 @vinoski whitespace cleanup
vinoski authored
72
73
0be3c7e @klacke untabified all of yaws
authored
74 {p,[],
75 ["Using the ehtml return value, we can return deep structured "
76 " erlang terms that correspond directly to HTML code. For example: "]},
7811247 @vinoski whitespace cleanup
vinoski authored
77
0be3c7e @klacke untabified all of yaws
authored
78 box("
bea8261 @klacke added log_wrap_size, configurable wrap size for all logs, fixed a bug…
authored
79 {table, [{bgcolor, \"tan\"}],
9608fa1 doc error
Claes Wikstrom authored
80 {tr, [],
e45a6e7 @klacke spelling fixes by ejonesca
authored
81 [{td, [{width, \"70%\"}], {p, [{class, \"foo\"}], \"Hi there\"}}]}}
dbab7a3 @klacke ssi include with var expansion + docs
authored
82 "),
7811247 @vinoski whitespace cleanup
vinoski authored
83
0be3c7e @klacke untabified all of yaws
authored
84 {p, [], "Corresponds to the following HTML code: "},
85 box("
dbab7a3 @klacke ssi include with var expansion + docs
authored
86 <table bgcolor=\"tan\">
87 <tr>
88 <td width=\"70%\">
89 <p class=\"foo\"> Hi there </p>
90 </td>
91 </tr>
92 </table>
93 "),
7811247 @vinoski whitespace cleanup
vinoski authored
94
0be3c7e @klacke untabified all of yaws
authored
95 {ul, [],
96 [{li,[],
97 {p,[],
98 [{tt,[], "{header, Header}"},
99 " If a " ,
7811247 @vinoski whitespace cleanup
vinoski authored
100 {tt, [], "header"},
0be3c7e @klacke untabified all of yaws
authored
101 " structure is returned, an additional header is inserted among the HTTP headers generated by yaws. "
102 "This is used to insert for example Set-Cookie headers. The ",
103 {tt,[], "Header"}, " variable must not be newline terminated."]}},
7811247 @vinoski whitespace cleanup
vinoski authored
104
0be3c7e @klacke untabified all of yaws
authored
105 {li,[],
106 {p,[],
107 [{tt,[], "{allheaders, Header}"},
108 " If an ",
109 {tt, [], "allheaders"},
110 " structure is returned, all previous headers that have been generated, including those "
111 "default hedaers generated by yaws itself are erased, and replaced by "
112 "the headers in ",
113 {tt, [], "Headers"},
114 ". The variable ",
7811247 @vinoski whitespace cleanup
vinoski authored
115 {tt,[], "Headers"},
0be3c7e @klacke untabified all of yaws
authored
116 " must be a list of ",
117 {tt, [], "{header, Str}"},
118 " tuples. The ",
7811247 @vinoski whitespace cleanup
vinoski authored
119 {tt, [], "Str"},
0be3c7e @klacke untabified all of yaws
authored
120 " must not be newline terminated. "]}},
7811247 @vinoski whitespace cleanup
vinoski authored
121
122
0be3c7e @klacke untabified all of yaws
authored
123 {li,[],
124 {p,[],
125 [{tt, [], "{status, StatusCodeInt} "},
126 "Is used to force yaws to return a different status code than the "
127 " default 200 code."]}},
7811247 @vinoski whitespace cleanup
vinoski authored
128
129
130
0be3c7e @klacke untabified all of yaws
authored
131 {li,[],
132 {p,[],
133 [{tt, [], "ok"}, " Do nothing."]}},
7811247 @vinoski whitespace cleanup
vinoski authored
134
135
0be3c7e @klacke untabified all of yaws
authored
136 {li,[],
137 {p,[],
7811247 @vinoski whitespace cleanup
vinoski authored
138 [{tt, [], "{content, MimeType, Content} "},
0be3c7e @klacke untabified all of yaws
authored
139 "Sets the mime type, that is "
140 "the Content-Type: header to be ", {tt, [], "MimeType"},
141 " The default value is of course \"text/html\", but applications that "
142 "generate i.e wml or pdf, must set the Content-Type. "
143 " A pdf generating application can for example return the "
144 "tuple ", {tt, [], " {content, \"application/pdf\", PdfContentData} "}]}},
7811247 @vinoski whitespace cleanup
vinoski authored
145
146
0be3c7e @klacke untabified all of yaws
authored
147 {li,[],
148 {p,[],
149 [{tt, [], "{redirect, URL} "}," a redirect is issued to the location in ",
150 {tt, [], " URL "}]}},
7811247 @vinoski whitespace cleanup
vinoski authored
151
0be3c7e @klacke untabified all of yaws
authored
152 {li,[],
153 {p,[],
154 [{tt, [], "{redirect_local, Path} "}," a redirect is issued to the local "
155 "server using the same method (http or https) as the incoming request "
156 " and the path part of the location header to the value in ", {tt, [], " Path "},"."]}},
7811247 @vinoski whitespace cleanup
vinoski authored
157
158
0be3c7e @klacke untabified all of yaws
authored
159 {li,[],
160 {p,[],
161 [{tt, [], "{'EXIT', normal}"}," which will terminate the "
162 " client connection in an uncontrolled way. "]}},
7811247 @vinoski whitespace cleanup
vinoski authored
163
0be3c7e @klacke untabified all of yaws
authored
164 {li,[],
165 {p,[],
166 [{tt, [], "{ssi, File, Delimiter, Bindings}"},
167 " Using this construct, we can deep inside a ehtml structure, "
7811247 @vinoski whitespace cleanup
vinoski authored
168 " return (ssi) Server Side Include content from a file. "
0be3c7e @klacke untabified all of yaws
authored
169 "This construct is further described in ",
170 {a, [{href, "ssi.yaws"}], "ssi.yaws"}, "."]}}
7811247 @vinoski whitespace cleanup
vinoski authored
171
172
0be3c7e @klacke untabified all of yaws
authored
173 ]},
7811247 @vinoski whitespace cleanup
vinoski authored
174
0be3c7e @klacke untabified all of yaws
authored
175 {p,[],["The embedded erlang code can also return a list of the "
176 " above values. For example the following value "]},
177 box("
639b7c2 @klacke ""
authored
178 [{status, 303},
179 {allheaders,
dbab7a3 @klacke ssi include with var expansion + docs
authored
180 [{header, [\"Location: \",\"http://www.funky.org/\"]},
181 {header, [\"Set-Cookie: \",\"namn=ruler;\"]}
639b7c2 @klacke ""
authored
182 ]},
dbab7a3 @klacke ssi include with var expansion + docs
authored
183 {html,\"<html> Redirected to funky.org </html>\"}
184 "),
0be3c7e @klacke untabified all of yaws
authored
185 {p,[],"Can be returned if we want to issue a redirect and set a cookie "
186 "at the same time."},
187 {p,[],["All possible return values from the out/1 function are documented in "
188 "the man page for ",
189 {a, [{href, "yman.yaws?page=yaws_api"}],
190 ["",
191 {tt, [], "yaws_api (5)"}]}]},
7811247 @vinoski whitespace cleanup
vinoski authored
192
0be3c7e @klacke untabified all of yaws
authored
193 {p,[],"It can also be instructive to look at the actual source "
194 "for the pages we are viewing at this very moment. Here are some of them"},
7811247 @vinoski whitespace cleanup
vinoski authored
195
0be3c7e @klacke untabified all of yaws
authored
196 {ul, [],
197 [
198 {li,[],
7811247 @vinoski whitespace cleanup
vinoski authored
199 [{p,[],
0be3c7e @klacke untabified all of yaws
authored
200 [{a, [{href, "index.yaws"}], "The top page, index.yaws"},
201 " and then the ",
202 {a, [{href, "code.yaws?file=/index.yaws"}], "corresponding source"}]}]},
7811247 @vinoski whitespace cleanup
vinoski authored
203
0be3c7e @klacke untabified all of yaws
authored
204 {li,[],
7811247 @vinoski whitespace cleanup
vinoski authored
205 [{p,[],
0be3c7e @klacke untabified all of yaws
authored
206 [{a, [{href, "dynamic.yaws"}], "This page, dynamic.yaws"},
207 " and then the ",
208 {a, [{href, "code.yaws?file=/dynamic.yaws"}], "corresponding source"}]}]}
209 ]},
7811247 @vinoski whitespace cleanup
vinoski authored
210
0be3c7e @klacke untabified all of yaws
authored
211 {h2,[],"The argument "},
212 {p,[],["The ", {tt, [], "out/1"}," function is supplied with a record argument. The "
213 "definition of that record is automatically included in the embedded erlang code "
214 "and the record definition is: "]},
215 ssi("ssi/dynamic.2"),
7811247 @vinoski whitespace cleanup
vinoski authored
216
0be3c7e @klacke untabified all of yaws
authored
217 {p,[], "And some of the refered records are defined as:"},
218 ssi("ssi/dynamic.3"),
219
220 {p, [], "Each chunk of erlang code will be compiled into a separate module. "
221 "The module names are automatically generated. If we have functions inside the "
222 "erlang chunks that we want to call from other chunks or modules, it is possible "
223 " to explicitly name the modue that will be used as in: "},
224
225 box("
f6dbbc9 @klacke added possibility to name the module in a .yaws file
authored
226 \<erl module=foobar>
227 out(A) ->
228 io:format('This is the foobar module',[]).
229
230 func() ->
231 i_am_exported_from_foobar.
232 \</erl>")
7811247 @vinoski whitespace cleanup
vinoski authored
233
f6dbbc9 @klacke added possibility to name the module in a .yaws file
authored
234
0be3c7e @klacke untabified all of yaws
authored
235 ]}]}].
dbab7a3 @klacke ssi include with var expansion + docs
authored
236
639b7c2 @klacke ""
authored
237
3b9e4a1 @klacke new ret vals from out/1
authored
238
67a6c13 @klacke ""
authored
239 </erl>
bea8261 @klacke added log_wrap_size, configurable wrap size for all logs, fixed a bug…
authored
240
241
242 <erl>
243 out(A) -> {ssi, "END2",[],[]}.
244 </erl>
245
Something went wrong with that request. Please try again.