forked from erlyaws/yaws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple.yaws
105 lines (72 loc) · 2.46 KB
/
simple.yaws
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
<erl>
out(A) ->
{ssi, "TAB.inc", "%%",[{"simple", "choosen"}]}.
</erl>
<div id="entry">
<h2>Hello world</h2>
<p>
The absolutely most simple example is a HTML file which doesn't contain
any embedded erlang code at all.
</p>
<p>
The file <a href="simple_ex1.yaws">simple_ex1.yaws</a> contains the following
HTML code.
</p>
<erl>
out(A) -> yaws_api:pre_ssi_files(A#arg.docroot, ["/simple_ex1.yaws"]).
</erl>
<p>
Since the file has the suffix <tt>.yaws</tt>, the file will be processed
by the Yaws dynamic compiler, but since no embeddded erlang code is found,
the data from the file will be delivered untouched.</p>
<h2> Hello world again </h2>
<p>
The file <a href="simple_ex2.yaws">simple_ex2.yaws</a> contains the following
HTML code.</p>
<erl>
out(A) -> yaws_api:pre_ssi_files(A#arg.docroot, ["/simple_ex2.yaws"]).
</erl>
<p>
The file has one very simple function which just returns a tuple
<tt>{ok, String} </tt></p>
<p>
The String will be substituted into the delivered HTML data instead of the
Erlang code.</p>
<h2> And yet again </h2>
<p>
The file <a href="simple_ex2.yaws">simple_ex2.yaws</a> returns
html embedded as a string. A tighter coupling to Erlang is
provided by a construct known as "ehtml".
As in <a href="simple_ex3.yaws">simple_ex3.yaws as ehtml</a>
</p>
<erl>
out(A) -> yaws_api:pre_ssi_files(A#arg.docroot, ["/simple_ex3.yaws"]).
</erl>
<h2>Print the #arg record</h2>
<p> When writing yaws code, all classic erlang libraries are available,
however, the module <tt>yaws_api</tt> which is included in the load path
for yaws modules contains an number of usefule functions, here is a small
example in <a href="simple_ex4.yaws">simple_ex4.yaws</a>
</p>
<erl>
out(A) -> yaws_api:pre_ssi_files(A#arg.docroot, ["/simple_ex4.yaws"]).
</erl>
<p>The above code illustrates two points:
<ul>
<li>
<p>
The function <tt>f/1</tt> which is available in the <tt>yaws_api</tt>
module. It's just a shortcut convenience to <tt>io_lib:format/2</tt>. The
<tt>yaws_api</tt> module contains many convenience functiond for yaws coders.</p></li>
<li>
<p>
The second point is a printout of the #arg record which is passed
to the <tt>out/1</tt> function. If you take the time to work with yaws,
the Arg passed to the out/1 functions will become very familiar.
It is the main mechanism which is used to pass data from the webserver to
the application. </p></li>
</ul>
</div>
<erl>
out(A) -> {ssi, "END2",[],[]}.
</erl>