You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/vfs_pack.mld
+31-30Lines changed: 31 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,15 @@
1
1
{0 Vfs_pack web site compiler}
2
2
3
-
vfs_pack is a binary too that will compile your website to a ML site that
4
-
can ve used with {!Simple_httpd.Dir.add_vfs}. It will
3
+
The binary [vfs_pack], provided with [Simple_httpd], will compile your website to
4
+
a ML module of type {!Simple_httpd.Dir.VFS} that can be used with
5
+
{!Simple_httpd.Dir.add_vfs}. It will
5
6
6
-
- compile a directory structure to a list of Route (see {!Simple_httpd.Route},
7
-
- It can be configured to allow directory listing or redirection to `index.html`,
8
-
- Large files are not compiled into memory and may be installed in a separate
9
-
directory
10
-
- precompiled version of large file (with deflate a.k.a zlib) can be stored too.
11
-
- dynamic `.chaml` can be used to produce dynamic pages.
7
+
- compile a directory structure to a list of Route (see {!Simple_httpd.Route}),
8
+
- it can be configured to allow directory listing or redirection to [index.html],
9
+
- large files are not stored into memory but may be installed in a separate
10
+
directory,
11
+
- precompressed version of file (with deflate a.k.a zlib) can be stored too.
12
+
- dynamic [.chaml] can be used to produce dynamic pages.
12
13
13
14
Here is an example of `.chaml` included in the distribution:
14
15
@@ -30,49 +31,49 @@ Here is an example of `.chaml` included in the distribution:
30
31
<li> item 2 </li>
31
32
<li> item 3 </li>
32
33
<li> item 4 </li>
33
-
<li> views: <ML>
34
+
<li> views: <script type="ml">
34
35
let _ = echo (string_of_int count);;
35
36
let _ = echo (if count mod 2 = 0 then
36
37
<p>even (<ML> ^ string_of_int count ^ </ML>)</p>
37
38
else <p>odd</p>)
38
-
</ML>
39
+
</script>
39
40
</li>
40
41
</ul>
41
42
<a href="."> escape from this file </a>
42
43
<br/>
43
-
request: <ML>
44
+
request: <script type="ml">
44
45
let _ = printf "%a" Request.pp request
45
-
</ML>
46
+
</script>
46
47
</body>
47
48
</html>
48
49
]}
49
50
50
-
As you can see, some defect of php are avoided: no quote/double every where.
51
+
As you can see, some defect of php are avoided: no quote everywhere.
51
52
52
53
There are four ways to insert ocaml code:
53
54
54
-
- In all [<ML>...</ML>] or [<script type="ml">...</script>] sections
55
+
- In all [<script type="ml">...</script>] sections
55
56
correspond to OCaml code. In this code [Simple_httpd] is open, the value
56
57
[request :] {!Simple_httpd.Request.t} is accessible.
57
58
58
59
- OCaml sections which are not inside others are compiled as toplevel
59
60
expressions. You may define type, values, ... In these sections and you can
60
-
use [echo] and [printf] provided automatically by opening a module of type
61
-
{!Simple_httpd.Input.Output} if they are not "prelude" section.
61
+
use [echo] and [printf] provided because a module of type
62
+
{!Simple_httpd.Input.Output} is open if they are not "prelude" section.
62
63
63
64
- Some [<script type="ml/prelude">...</script>] section can be added inside
64
65
the [<head>] tag but before any other OCaml sections. they are executed
65
66
before any output is done to the server and may shadow two values [headers
66
-
:] {!Simple_httpd.Headers.t} initialy empty and [cookies :]
67
-
{!Simple_httpd.Cookies.t} that contain an initical
67
+
:] {!Simple_httpd.Headers.t} initially empty and [cookies :]
68
+
{!Simple_httpd.Cookies.t} that contain an initial
68
69
{!Simple_httpd.Headers.Cache_Control} or {!Simple_httpd.Headers.ETag}. For
69
70
instance, this allows to read and modify cookies or start a
70
71
{!Simple_httpd.Session}. Values defined in this section are part of a
71
72
`Prelude` module which is opened in the rest of the file.
72
73
73
-
- Some [<script type="ml/global">...</script>] section can alse be added inside
74
+
- Some [<script type="ml/global">...</script>] section can also be added inside
74
75
inside the [<head>] tag, they are placed at the top level of the generated ml
75
-
file. This is usefull for instance to extend the [Async.session_data] type.
76
+
file. This is useful for instance to extend the [Async.session_data] type.
76
77
Here is an example using session:
77
78
78
79
{[
@@ -104,7 +105,7 @@ There are four ways to insert ocaml code:
104
105
- Inside OCaml sections, html sections are interpreted as ocaml
105
106
strings.
106
107
107
-
- Nested OCaml are compiled as normal ocaml code with no modification.
108
+
- Nested OCaml sections are emitted as ocaml code with no modification.
108
109
For instance, in the above example,
109
110
110
111
{[
@@ -116,34 +117,34 @@ There are four ways to insert ocaml code:
116
117
</ML>
117
118
]}
118
119
119
-
is compiled as
120
+
is transformed to
120
121
121
122
{[
122
123
let _ = echo (if n mod 2 = 0 then
123
124
"<li>even (" ^ string_of_int n ^ ")</li>"
124
125
else "<li>odd</li>")
125
126
]}
126
127
127
-
Here is the documentation of the `vfs_pack` command line:
128
+
Here is the documentation of the [vfs_pack] command line:
128
129
129
130
{[
130
131
vfs-pack [opt]+
131
132
132
-
Builds an OCaml module containing a `Simple_httpd.Dir.Embedded_fs.t`
133
+
Builds an OCaml module containing a {!Simple_httpd.Dir.Embedded_fs.t}
133
134
virtual file system. This is useful to pack assets into an OCaml binary,
134
135
for example.
135
136
136
137
Each entry in the VFS can be added from the command line.
137
138
138
139
-v verbose mode
139
-
-o set output file
140
+
-o <file> set output file
140
141
--file <name,file> adds name=file to the VFS
141
142
--url <name,url> adds name=url to the VFS
142
-
--mirror <prefix,dir> copies directory dir into the VFS under prefix
143
-
--max-size <size>, max size to hold file in memory (default: infinite). Bigger filed are copie to the folder given by --desination. A compressed version .zlib is also produced.
144
-
--destination set the destination folder to use with mirror
145
-
--perm set the permission of created folder
146
-
-F <file> reads entries from the file, on per line written using this command line option syntax.
143
+
--mirror <prefix,dir> adds prefix=dir to the vfs, copying all files in directory dir
144
+
--max-size <size>, max size to hold file in memory (default: infinite). Bigger filed are copied to the folder given by --destination. A compressed version .zlib is also produced if it is at least 10% smaller.
145
+
--destination <dir> set the destination folder to use with mirror
146
+
--perm <int> set the permission of created folder
147
+
-F <file> reads entries from the file, written using this command line option syntax.
"-o", Arg.Set_string out, "<file> set output file";
274
255
"--file", Arg.String add_file, " <name,file> adds name=file to the VFS";
275
256
"--url", Arg.String add_url, " <name,url> adds name=url to the VFS";
276
-
"--mirror", Arg.String add_mirror, " <prefix,dir> copies directory dir into the VFS under prefix";
277
-
"--max-size", Arg.Set_int max_size, " <size>, max size to hold file in memory (default: infinite). Bigger filed are copie to the folder given by --desination. A compressed version .zlib is also produced.";
257
+
"--mirror", Arg.String add_mirror, " <prefix,dir> adds prefix=dir to the vfs, copying all files in directory dir";
258
+
"--max-size", Arg.Set_int max_size, " <size>, max size to hold file in memory (default: infinite). Bigger filed are copied to the folder given by --destination. A compressed version .zlib is also produced if it is at least 10% smaller.";
0 commit comments