diff --git a/tutos/8.0/manual/application.wiki b/tutos/8.0/manual/application.wiki new file mode 100644 index 00000000..cc12891e --- /dev/null +++ b/tutos/8.0/manual/application.wiki @@ -0,0 +1,1170 @@ +<> + +In this chapter, we will write a [[site:graffiti/|collaborative +drawing application]]. It is a client/server web application +displaying an area where users can draw using the mouse, and see what +other users are drawing at the same time and in real-time. + +This tutorial is a good starting point if you want a step-by-step +introduction to Eliom programming. + +<> + +<<|outline target="documentation">> + +==@@id="basics"@@ Basics== + +If not already done, install Eliom first: +{{{ +opam install ocsipersist-sqlite eliom ocsigen-ppx-rpc +}}} + +To get started, we recommend using <>, a program which +creates scaffolds for Eliom projects. The following command creates a +very simple project called {{{graffiti}}} in the directory +{{{graffiti}}}: + +<> + +===My first page=== + +<> + +Our web application consists of a single page for now. Let's start by +creating a very basic page. We define the service that will implement +this page by the following declaration: + +< + Lwt.return + (html + (head (title (txt "Page title")) []) + (body [h1 [txt "Graffiti"]]))) +>> + +Annotations {{{%server}}} tells the compiler that the code is going to be executed +on the server (see later). + +Replace the content of file {{{graffiti.eliom}}} by the above lines and run: + +<> + +This will compile your application and run {{{ocsigenserver}}}. + +Your page is now available at URL [[http://localhost:8080/graff|{{{http://localhost:8080/graff}}}]]. + + +<> allows to +create new entry points to your web site, called //services//. In +general, services are attached to a URL and generate a web page. +Services are represented by OCaml values, through which you must +register a function that will generate a page. + +The {{{~path}}} parameter corresponds to the URL where you want to +attach your service. It is a list of strings. The value +<> corresponds to the URL +<>. <> corresponds to +the URL <> (that is: the default page of the +directory <>). + +>> + +< + + + + +}}} + +{{{}}} asks the server to load Eliom module +{{{graffiti.cma}}}, containing the Eliom application, +at startup and attach it to this host (and site). + +Extensions {{{}}} (staticmod) and {{{}}} +are called successively: +* If they exist, files from the directory <> will be served, +* Otherwise, Server will try to generate pages with Eliom + ({{{}}}), +* Otherwise it will generate a 404 (Not found) error (default). + +>> + +<>, +which is implemented using the <> +library. The module defines a construction function for each HTML +tag. + +//Note that it is also possible to use the usual HTML syntax directly + in OCaml, cf. <>.// + +The TyXML library (and thus <>) is very strict and compels you to respect +HTML standard (with some limitations). For example if you write: + +<> + +You will get an error message similar to the following, referring to +the end of line 2: + +{{{ +Error: This expression has type ([> `TXT ] as 'a) Html.elt + but an expression was expected of type + Html_types.head_content_fun Html.elt + Type 'a is not compatible with type Html_types.head_content_fun = + [ `Base + | `Command + | `Link + | `Meta + | `Noscript of [ `Link | `Meta | `Style ] + | `Script + | `Style ] + The second variant type does not allow tag(s) `TXT +}}} + +where <> +is the type of content allowed inside {{{}}} ({{{}}}, +{{{}}}, {{{}}}, {{{}}}, etc.). Notice that +{{{`TXT}}} (i.e. raw text) is not included in this polymorphic +variant type, which means that {{{}}} cannot contain raw text. + +Most functions take as parameter the list representing its contents. +See other examples below. Each of them take an optional {{{?a}}} +parameter for optional HTML attributes. +Mandatory HTML attributes correspond to mandatory OCaml parameters. +See below for examples. + +<<| +**Another example:** In HTML, some tags cannot be empty. For example +{{{}}}must contain at least one row. To enforce this, function +<> +takes two parameters: the first one is the first row, while +the second one is a list containing all the other rows (same thing for +{{{}}}, {{{}}}, {{{