webmcp

view doc/autodoc-header.htmlpart @ 390:ed910089a0c5

Keep track of expanded sections in autodoc reference (and collapse sections on hash change)
author jbe
date Thu Dec 03 18:26:49 2015 +0100 (2015-12-03)
parents a7a335e2db93
children a932b94a8490
line source
1 <html>
2 <head>
3 <script type="text/javascript">
4 var expandedSections = {};
5 function toggleSection(ident) {
6 var element = document.getElementById('autodoc_details_' + ident);
7 if (element) {
8 if (expandedSections[ident]) {
9 element.style.display = 'none';
10 delete expandedSections[ident];
11 } else {
12 element.style.display = '';
13 expandedSections[ident] = true;
14 }
15 }
16 }
17 window.onload = window.onhashchange = function() {
18 for (var ident in expandedSections) toggleSection(ident);
19 var hash = window.location.hash;
20 if (hash) {
21 toggleSection(hash.replace(/^#/, ''));
22 }
23 };
24 </script>
25 <style>
26 body {
27 font-family: "Liberation Sans", sans-serif;
28 font-size: 11pt;
29 padding-bottom: 5ex;
30 }
31 .warning {
32 color: #ff0000;
33 }
34 h1, h2 {
35 font-family: "Liberation Serif", Georgia, serif;
36 }
37 h2 {
38 margin-bottom: 0.3ex;
39 }
40 p {
41 margin: 0px;
42 line-height: 130%;
43 }
44 tt, pre {
45 font-size: 10pt;
46 }
47 tt {
48 font-weight: bold;
49 white-space: nowrap;
50 }
51 .autodoc_entry {
52 margin-top: 1ex;
53 margin-bottom: 1ex;
54 }
55 .autodoc_comment_tail {
56 font-style: italic;
57 }
58 .autodoc_entry .short_synopsis {
59 cursor: pointer;
60 }
61 .autodoc_details {
62 padding-left: 1em;
63 padding-right: 1em;
64 border: 1px solid #777;
65 }
66 .autodoc_synopsis {
67 font-weight: bold;
68 }
69 .autodoc_synopsis .autodoc_comment_tail {
70 font-weight: normal;
71 color: #008000;
72 }
73 .autodoc_entry .autodoc_comment {
74 color: #400080;
75 }
76 .autodoc_source {
77 color: #505050;
78 }
79 </style>
80 <title>WebMCP 2.0.4 Documentation</title>
81 </head>
82 <body>
83 <h1>WebMCP 2.0.4 Documentation</h1>
84 <p>
85 WebMCP is a web development framework based on the Lua programming language (read more about Lua <a href="http://www.lua.org/about.html">here</a>).
86 </p>
87 <h2>Requirements</h2>
88 <p>
89 WebMCP has been developed on Linux and FreeBSD. Using it with Mac&nbsp;OS&nbsp;X is untested as of yet; Microsoft Windows is not supported. Beside the operating system, the only mandatory dependencies for WebMCP are the <a href="http://www.lua.org/">programming language Lua</a> version 5.2 or 5.3, the <a href="http://www.public-software-group.org/moonbridge">Moonbridge Network Server for Lua Applications</a> version 1.0.1 or higher, <a href="http://www.postgresql.org/">PostgreSQL</a> version 8.2 or higher, and a C compiler.
90 </p>
91 <h2>Installation</h2>
92 <p>
93 After downloading the tar.gz package, unpack it, enter the unpacked directory and type <tt>make</tt>. If you use Mac OS X or if you experience problems during compilation, you need to edit the <tt>Makefile.options</tt> file prior to compilation. The framework itself will be available in the <tt>framework/</tt> directory, while a demo application is available in the <tt>demo-app/</tt> directory. The <tt>framework.precompiled/</tt> and <tt>demo-app.precompiled/</tt> directories will contain a version with all Lua files being byte-code pre-compiled, which can be used instead. You may copy these directories (with <tt>cp -L</tt> to follow links) to any other place you like. Don't forget to setup a database, and make the <tt>tmp/</tt> directory of the application writable for the web server process. Good luck and have fun!
94 </p>
95 <h2>Configuration, pre-fork and post-fork initializers</h2>
96 <p>
97 The Moonbridge Network Server creates forks (i.e. clones) of the application server process in order to handle concurrent requests. Certain initializations may be performed before forking, other initializations must be performed after forking. The application's configuration files as well as its pre-fork initializers are executed before forking. The application's post-fork initializers are executed after forking. In particular, any libraries that open file or network handles during initialization must not be loaded before the server process is forked. Opening database connections must be performed after forking as well. Execution order is as follows:
98 </p>
99 <ol>
100 <li>
101 Loading all WebMCP libraries except the "multirand" library (multirand opens /dev/urandom and thus must not be loaded prior to forking)
102 </li>
103 <li>
104 Executing the selected configuration file: <tt>config/</tt><i>configuration_name</i><tt>.lua</tt>
105 </li>
106 <li>
107 Executing all pre-fork initializers (both those in the <tt>app/_prefork/</tt> and those in the <tt>app/</tt><i>application_name</i><tt>/_prefork/</tt> directory) until call of <tt>execute.inner()</tt> within each initializer
108 </li>
109 <li>
110 The Moonbridge Network Server forks the process (i.e. cloning the whole Lua machine)<br />
111 <span style="color: red">Note: no file handles or network connections must be opened prior to this point!</span>
112 </li>
113 <li>
114 Loading WebMCP's "multirand" library
115 </li>
116 <li>
117 Executing all post-fork initializers (both those in the <tt>app/_postfork/</tt> and those in the <tt>app/</tt><i>application_name</i><tt>/_postfork/</tt> directory) until call of <tt>execute.inner()</tt> within each initializer
118 </li>
119 <li>
120 For each request:
121 <ul>
122 <li>
123 Execution of all applicable filters until call of <tt>execute.inner()</tt> within each filter
124 </li>
125 <li>
126 Handling of the request by calling the appropriate view or action
127 </li>
128 <li>
129 Resuming execution of all filters in reverse order from that position where <tt>execute.inner()</tt> had been called
130 </li>
131 </ul>
132 </li>
133 <li>
134 Resuming execution of all post-fork initializers in reverse order from that position where <tt>execute.inner()</tt> had been called
135 </li>
136 <li>
137 Resuming execution of all pre-fork initializers in reverse order from that position where <tt>execute.inner()</tt> had been called
138 </li>
139 </ol>
140 </p>
141 <h2>Using the atom library</h2>
142 <p>
143 Lua itself has only very few built-in data types. The atom library gives support for extra data types. Currently the following extra data types are provided:
144 </p>
145 <ul>
146 <li>atom.fraction</li>
147 <li>atom.date</li>
148 <li>atom.time</li>
149 <li>atom.timestamp (date and time combined in one data type)</li>
150 </ul>
151 <p>
152 In addition the following pseudo-types are existent, corresponding to Lua's base types:
153 </p>
154 <ul>
155 <li>atom.boolean</li>
156 <li>atom.string</li>
157 <li>atom.integer</li>
158 <li>atom.number</li>
159 </ul>
160 <p>
161 Both atom.integer and atom.number refer to Lua's base type &ldquo;number&rdquo;.
162 </p>
163 <p>
164 New values of atom data types are created by either calling <tt>atom.<i>type</i>:load(string_representation)</tt> or by calling <tt>atom.<i>type</i>{...}</tt>, e.g. <tt>atom.date{year=1970, month=1, day=1}</tt>. You can dump any atom value as a string by calling <tt>atom.dump(value)</tt> and later reload it with <tt>atom.<i>type</i>:load(string)</tt>.
165 </p>
166 <h2>Using the Object-Relational Mapper &ldquo;mondelefant&rdquo;</h2>
167 <p>
168 The library &ldquo;mondelefant&rdquo; shipping with WebMCP can be used to access PostgreSQL databases. It also serves as an Object-Relational Mapper (ORM). The database connection is usually configured in the config file (e.g. in <tt>config/devel.lua</tt>):
169 </p>
170 <pre>
171 config.db = { engine="postgresql", dbname="webmcp_demo" }
172 config.db_trace = true</pre>
173 <p>
174 In addition to configuring the database, it must be opened within a post-fork initializer (e.g. in <tt>app/_postfork/01_database.lua</tt>):
175 </p>
176 <pre>
177 _G.db = assert(mondelefant.connect(config.db))
178 function mondelefant.class_prototype:get_db_conn() return db end</pre>
179 <p>
180 The parameters for <tt>mondelefant.connect</tt> are directly passed to PostgreSQL's client library libpq. See <a href="http://www.postgresql.org/docs/9.4/static/libpq-connect.html">PostgreSQL's documentation on PQconnect</a> for information about supported parameters.
181 </p>
182 <p>
183 To define a model to be used within a WebMCP application, create a file named with the name of the model and <tt>.lua</tt> as extension in the <tt>model/</tt> directory of your application. The most basic definition of a model (named &ldquo;movie&rdquo; in this example) is:
184 </p>
185 <pre>
186 Movie = mondelefant.new_class()
187 Movie.table = 'movie'</pre>
188 <p>
189 Note: Model classes are always written CamelCase, while the name of the file in <tt>model/</tt> is written lower_case.
190 </p>
191 <p>
192 To select objects from the database, the mondelefant library provides a selector framework:
193 </p>
194 <pre>
195 local s = Movie:new_selector()
196 s:add_where{ 'id = ?', param.get_id() }
197 s:single_object_mode() -- return single object instead of list
198 local movie = s:exec()</pre>
199 <p>
200 A short form of the above query would be:
201 </p>
202 <pre>
203 local movie = Movie:new_selector():add_where{ 'id = ?', param.get_id() }:single_object_mode():exec()</pre>
204 <p>
205 For more examples about how to use the model system, please take a look at the demo application.
206 </p>
207 <h2>The Model-View-Action (MVA) concept</h2>
208 <p>
209 As opposed to other web application frameworks, WebMCP does not use a Model-View-Controller (MVC) concept, but a Model-View-Action (MVA) concept.
210 </p>
211 <h3>Models</h3>
212 <p>
213 The models in MVA are like the models in MVC; they are used to access data stored in a relational database (PostgreSQL) in an object oriented way. They can also be used to provide methods for working with objects representing the database entries.
214 </p>
215 <h3>Views</h3>
216 <p>
217 The views in the MVA concept are different from the views in the MVC concept. As WebMCP has no controllers, the views are responsible for processing the GET/POST parameters from the webbrowser, fetching the data to be displayed, and creating the output by directly writing HTML to slots in a layout or by calling helper functions for the user interface.
218 </p>
219 <h3>Actions</h3>
220 <p>
221 Actions are similar to views, but supposed to change data in the database, hence only callable by HTTP POST requests. They are also responsible for processing the POST parameters from the webbrowser. They can modify the database, but instead of rendering a page to be displayed, they just return a status code. Depending on the status code there will be an internal forward or an HTTP 303 redirect to a view. When calling an action via a POST request, additional POST parameters, which are usually added by hidden form fields, determine the view to be displayed for each status code returned by the action.
222 </p>
223 <h2>Directory structure of a WebMCP application</h2>
224 <ul>
225 <li>
226 Base Directory
227 <ul>
228 <li>
229 <tt>app/</tt>
230 <ul>
231 <li>
232 <tt>_prefork/</tt>
233 <ul>
234 <li>
235 <tt>10_first_prefork_initializer.lua</tt>
236 </li>
237 <li>
238 <tt>30_third_prefork_initializer.lua</tt>
239 </li>
240 </ul>
241 </li>
242 <li>
243 <tt>_postfork/</tt>
244 <ul>
245 <li>
246 <tt>01_first_postfork_initializer.lua</tt>
247 </li>
248 <li>
249 <tt>03_third_postfork_initializer.lua</tt>
250 </li>
251 </ul>
252 </li>
253 <li>
254 <tt>main/</tt>
255 <ul>
256 <li>
257 <tt>_prefork/</tt>
258 <ul>
259 <li>
260 <tt>20_second_prefork_initializer.lua</tt>
261 </li>
262 </ul>
263 </li>
264 <li>
265 <tt>_postfork/</tt>
266 <ul>
267 <li>
268 <tt>02_second_postfork_initializer.lua</tt>
269 </li>
270 </ul>
271 </li>
272 <li>
273 <tt>_filter/</tt>
274 <ul>
275 <li>
276 <tt>10_first_filter.lua</tt>
277 </li>
278 <li>
279 <tt>30_third_filter.lua</tt>
280 </li>
281 <li>&hellip;</li>
282 </ul>
283 </li>
284 <li>
285 <tt>_filter_action/</tt>
286 <ul>
287 <li>
288 <tt>20_second_filter.lua</tt>
289 </li>
290 <li>&hellip;</li>
291 </ul>
292 </li>
293 <li>
294 <tt>_filter_view/</tt>
295 <ul>
296 <li>&hellip;</li>
297 </ul>
298 </li>
299 <li>
300 <tt>_layout/</tt>
301 <ul>
302 <li>&hellip;</li>
303 </ul>
304 </li>
305 <li>
306 <tt>index/</tt>
307 <ul>
308 <li>
309 <tt>_action/</tt>
310 <ul>
311 <li>
312 <i>action_name</i><tt>.lua</tt>
313 </li>
314 <li>
315 <i>another_action_name</i><tt>.lua</tt>
316 </li>
317 <li>&hellip;</li>
318 </ul>
319 </li>
320 <li>
321 <tt>index.lua</tt>
322 </li>
323 <li>
324 <i>other_view_name</i><tt>.lua</tt>
325 </li>
326 <li>&hellip;</li>
327 </ul>
328 </li>
329 <li>
330 <i>other_module_name</i><tt>/</tt>
331 <ul>
332 <li>&hellip;</li>
333 </ul>
334 </li>
335 </ul>
336 </li>
337 <li>
338 <i>other_application_name</i><tt>/</tt>
339 <ul>
340 <li>&hellip;</li>
341 </ul>
342 </li>
343 </ul>
344 </li>
345 <li>
346 <tt>config/</tt>
347 <ul>
348 <li>
349 <tt>development.lua</tt>
350 </li>
351 <li>
352 <tt>production.lua</tt>
353 <li>
354 <li>
355 <i>other_config_name</i><tt>.lua</tt>
356 </li>
357 <li>&hellip;</li>
358 </ul>
359 </li>
360 <li>
361 <tt>db/</tt>
362 <ul>
363 <li>
364 <tt>schema.sql</tt>
365 </li>
366 </ul>
367 </li>
368 <li>
369 <tt>locale/</tt>
370 <ul>
371 <li>
372 <tt>translations.de.lua</tt>
373 </li>
374 <li>
375 <tt>translations.en.lua</tt>
376 </li>
377 <li>
378 <tt>translations.</tt><i>languagecode</i><tt>.lua</tt>
379 </li>
380 <li>&hellip;</li>
381 </ul>
382 </li>
383 <li>
384 <tt>model/</tt>
385 <ul>
386 <li>
387 <i>model_name</i><tt>.lua</tt>
388 </li>
389 <li>
390 <i>another_model_name</i><tt>.lua</tt>
391 </li>
392 <li>&hellip;</li>
393 </ul>
394 </li>
395 <li>
396 <tt>static/</tt>
397 <ul>
398 <li>&hellip; (images, javascript, ...)</li>
399 </ul>
400 </li>
401 <li>
402 <tt>tmp/</tt> (writable by the web process)
403 </li>
404 </ul>
405 </li>
406 </ul>
407 <h2>Starting your application</h2>
408 <p>
409 Ensure that the <tt>moonbridge</tt> binary is within your system's search path and that the <tt>moonbridge_http.lua</tt> file is included in the LUA_PATH or linked into the framework's <tt>lib/</tt> directory (alternatively the MOONBR_LUA_PATH option might be set accordingly at compile-time of the Moonbridge Network Server). To start an application, call the <tt>mcp.lua</tt> executable (found in <tt>framework/bin/mcp.lua</tt>) with the following arguments:
410 </p>
411 <ol>
412 <li>
413 Path of the WebMCP framework directory, e.g. <tt>./framework</tt>
414 </li>
415 <li>
416 Path of your application's directory, e.g. <tt>./demo-app</tt>
417 </li>
418 <li>
419 Name of your applicaiton (usually <tt>main</tt>)
420 </li>
421 <li>
422 Name of configuration (e.g. <tt>devel</tt> to use config/devel.lua)
423 </li>
424 </ol>
425 <h2>Automatically generated reference for the WebMCP environment</h2>
426 <ul>

Impressum / About Us