webmcp

annotate doc/autodoc-header.htmlpart @ 349:8cf6d927d074

Fixed commas in autodoc comments
author jbe
date Thu Mar 26 12:25:19 2015 +0100 (2015-03-26)
parents 1fbdccf4f8e9
children 785ff282af16
rev   line source
jbe/bsw@0 1 <html>
jbe/bsw@0 2 <head>
jbe/bsw@0 3 <style>
jbe/bsw@0 4 body {
jbe/bsw@0 5 font-family: "Liberation Sans", sans-serif;
jbe/bsw@0 6 font-size: 11pt;
jbe/bsw@0 7 padding-bottom: 5ex;
jbe/bsw@0 8 }
jbe/bsw@0 9 .warning {
jbe/bsw@0 10 color: #ff0000;
jbe/bsw@0 11 }
jbe/bsw@0 12 h1, h2 {
jbe/bsw@0 13 font-family: "Liberation Serif", Georgia, serif;
jbe/bsw@0 14 }
jbe/bsw@0 15 h2 {
jbe/bsw@0 16 margin-bottom: 0.3ex;
jbe/bsw@0 17 }
jbe/bsw@0 18 p {
jbe/bsw@0 19 margin: 0px;
jbe/bsw@0 20 line-height: 130%;
jbe/bsw@0 21 }
jbe/bsw@0 22 tt, pre {
jbe/bsw@0 23 font-size: 10pt;
jbe/bsw@0 24 }
jbe/bsw@0 25 tt {
jbe/bsw@0 26 font-weight: bold;
jbe/bsw@0 27 white-space: nowrap;
jbe/bsw@0 28 }
jbe/bsw@0 29 .autodoc_entry {
jbe/bsw@0 30 margin-top: 1ex;
jbe/bsw@0 31 margin-bottom: 1ex;
jbe/bsw@0 32 }
jbe/bsw@0 33 .autodoc_comment_tail {
jbe/bsw@0 34 font-style: italic;
jbe/bsw@0 35 }
jbe/bsw@0 36 .autodoc_entry .short_synopsis {
jbe/bsw@0 37 cursor: pointer;
jbe/bsw@0 38 }
jbe/bsw@0 39 .autodoc_details {
jbe/bsw@0 40 padding-left: 1em;
jbe/bsw@0 41 padding-right: 1em;
jbe/bsw@0 42 border: 1px solid #777;
jbe/bsw@0 43 }
jbe/bsw@0 44 .autodoc_synopsis {
jbe/bsw@0 45 font-weight: bold;
jbe/bsw@0 46 }
jbe/bsw@0 47 .autodoc_synopsis .autodoc_comment_tail {
jbe/bsw@0 48 font-weight: normal;
jbe/bsw@0 49 color: #008000;
jbe/bsw@0 50 }
jbe/bsw@0 51 .autodoc_entry .autodoc_comment {
jbe/bsw@0 52 color: #400080;
jbe/bsw@0 53 }
jbe/bsw@0 54 .autodoc_source {
jbe/bsw@0 55 color: #505050;
jbe/bsw@0 56 }
jbe/bsw@0 57 </style>
jbe@278 58 <title>WebMCP 2.0.0 Documentation</title>
jbe/bsw@0 59 </head>
jbe/bsw@0 60 <body>
jbe@278 61 <h1>WebMCP 2.0.0 Documentation</h1>
jbe/bsw@0 62 <p>
jbe@278 63 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>).
jbe/bsw@0 64 </p>
jbe/bsw@0 65 <h2>Requirements</h2>
jbe/bsw@0 66 <p>
jbe@278 67 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.3, the <a href="http://www.public-software-group.org/moonbridge">Moonbridge Network Server for Lua Applications</a> version 0.4.0 or higher, <a href="http://www.postgresql.org/">PostgreSQL</a> version 8.2 or higher, and a C compiler.
jbe/bsw@0 68 </p>
jbe/bsw@0 69 <h2>Installation</h2>
jbe/bsw@0 70 <p>
jbe@278 71 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!
jbe@278 72 </p>
jbe@278 73 <h2>Configuration, pre-fork and post-fork initializers</h2>
jbe@278 74 <p>
jbe@278 75 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:
jbe@278 76 </p>
jbe@278 77 <ol>
jbe@278 78 <li>
jbe@278 79 Loading all WebMCP libraries except the "multirand" library (multirand opens /dev/urandom and thus must not be loaded prior to forking)
jbe@278 80 </li>
jbe@278 81 <li>
jbe@278 82 Executing the selected configuration file: <tt>config/</tt><i>configuration_name</i><tt>.lua</tt>
jbe@278 83 </li>
jbe@278 84 <li>
jbe@278 85 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
jbe@278 86 </li>
jbe@278 87 <li>
jbe@278 88 The Moonbridge Network Server forks the process (i.e. cloning the whole Lua machine)<br />
jbe@278 89 <span style="color: red">Note: no file handles or network connections must be opened prior to this point!</span>
jbe@278 90 </li>
jbe@278 91 <li>
jbe@281 92 Loading WebMCP's "multirand" library
jbe@281 93 </li>
jbe@281 94 <li>
jbe@278 95 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
jbe@278 96 </li>
jbe@278 97 <li>
jbe@278 98 For each request:
jbe@278 99 <ul>
jbe@278 100 <li>
jbe@278 101 Execution of all applicable filters until call of <tt>execute.inner()</tt> within each filter
jbe@278 102 </li>
jbe@278 103 <li>
jbe@278 104 Handling of the request by calling the appropriate view or action
jbe@278 105 </li>
jbe@278 106 <li>
jbe@278 107 Resuming execution of all filters in reverse order from that position where <tt>execute.inner()</tt> had been called
jbe@278 108 </li>
jbe@278 109 </ul>
jbe@278 110 </li>
jbe@278 111 <li>
jbe@278 112 Resuming execution of all post-fork initializers in reverse order from that position where <tt>execute.inner()</tt> had been called
jbe@278 113 </li>
jbe@278 114 <li>
jbe@278 115 Resuming execution of all pre-fork initializers in reverse order from that position where <tt>execute.inner()</tt> had been called
jbe@278 116 </li>
jbe@278 117 </ol>
jbe/bsw@0 118 </p>
jbe/bsw@0 119 <h2>Using the atom library</h2>
jbe/bsw@0 120 <p>
jbe/bsw@0 121 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:
jbe/bsw@0 122 </p>
jbe/bsw@0 123 <ul>
jbe/bsw@0 124 <li>atom.fraction</li>
jbe/bsw@0 125 <li>atom.date</li>
jbe/bsw@0 126 <li>atom.time</li>
jbe/bsw@0 127 <li>atom.timestamp (date and time combined in one data type)</li>
jbe/bsw@0 128 </ul>
jbe/bsw@0 129 <p>
jbe/bsw@0 130 In addition the following pseudo-types are existent, corresponding to Lua's base types:
jbe/bsw@0 131 </p>
jbe/bsw@0 132 <ul>
jbe/bsw@0 133 <li>atom.boolean</li>
jbe/bsw@0 134 <li>atom.string</li>
jbe/bsw@0 135 <li>atom.integer</li>
jbe/bsw@0 136 <li>atom.number</li>
jbe/bsw@0 137 </ul>
jbe/bsw@0 138 <p>
jbe/bsw@0 139 Both atom.integer and atom.number refer to Lua's base type &ldquo;number&rdquo;.
jbe/bsw@0 140 </p>
jbe/bsw@0 141 <p>
jbe/bsw@0 142 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>.
jbe/bsw@0 143 </p>
jbe/bsw@0 144 <h2>Using the Object-Relational Mapper &ldquo;mondelefant&rdquo;</h2>
jbe/bsw@0 145 <p>
jbe@278 146 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>):
jbe@278 147 </p>
jbe@278 148 <pre>
jbe@278 149 config.db = { engine="postgresql", dbname="webmcp_demo" }
jbe@278 150 config.db_trace = true</pre>
jbe@278 151 <p>
jbe@278 152 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>):
jbe/bsw@0 153 </p>
jbe/bsw@0 154 <pre>
jbe@278 155 _G.db = assert(mondelefant.connect(config.db))
jbe@295 156 function mondelefant.class_prototype:get_db_conn() return db end</pre>
jbe/bsw@0 157 <p>
jbe@295 158 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.
jbe/bsw@0 159 </p>
jbe/bsw@0 160 <p>
jbe/bsw@0 161 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:
jbe/bsw@0 162 </p>
jbe/bsw@0 163 <pre>
jbe/bsw@0 164 Movie = mondelefant.new_class()
jbe/bsw@0 165 Movie.table = 'movie'</pre>
jbe/bsw@0 166 <p>
jbe/bsw@0 167 Note: Model classes are always written CamelCase, while the name of the file in <tt>model/</tt> is written lower_case.
jbe/bsw@0 168 </p>
jbe/bsw@0 169 <p>
jbe/bsw@0 170 To select objects from the database, the mondelefant library provides a selector framework:
jbe/bsw@0 171 </p>
jbe/bsw@0 172 <pre>
jbe/bsw@0 173 local s = Movie:new_selector()
jbe/bsw@0 174 s:add_where{ 'id = ?', param.get_id() }
jbe/bsw@0 175 s:single_object_mode() -- return single object instead of list
jbe/bsw@0 176 local movie = s:exec()</pre>
jbe/bsw@0 177 <p>
jbe/bsw@0 178 A short form of the above query would be:
jbe/bsw@0 179 </p>
jbe/bsw@0 180 <pre>
jbe/bsw@0 181 local movie = Movie:new_selector():add_where{ 'id = ?', param.get_id() }:single_object_mode():exec()</pre>
jbe/bsw@0 182 <p>
jbe/bsw@0 183 For more examples about how to use the model system, please take a look at the demo application.
jbe/bsw@0 184 </p>
jbe/bsw@0 185 <h2>The Model-View-Action (MVA) concept</h2>
jbe/bsw@0 186 <p>
jbe/bsw@0 187 As opposed to other web application frameworks, WebMCP does not use a Model-View-Controller (MVC) concept, but a Model-View-Action (MVA) concept.
jbe/bsw@0 188 </p>
jbe/bsw@0 189 <h3>Models</h3>
jbe/bsw@0 190 <p>
jbe/bsw@0 191 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.
jbe/bsw@0 192 </p>
jbe/bsw@0 193 <h3>Views</h3>
jbe/bsw@0 194 <p>
jbe/bsw@0 195 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.
jbe/bsw@0 196 </p>
jbe/bsw@0 197 <h3>Actions</h3>
jbe/bsw@0 198 <p>
jbe/bsw@0 199 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.
jbe/bsw@0 200 </p>
jbe/bsw@0 201 <h2>Directory structure of a WebMCP application</h2>
jbe/bsw@0 202 <ul>
jbe/bsw@0 203 <li>
jbe/bsw@0 204 Base Directory
jbe/bsw@0 205 <ul>
jbe/bsw@0 206 <li>
jbe/bsw@0 207 <tt>app/</tt>
jbe/bsw@0 208 <ul>
jbe/bsw@0 209 <li>
jbe@278 210 <tt>_prefork/</tt>
jbe@278 211 <ul>
jbe@278 212 <li>
jbe@278 213 <tt>10_first_prefork_initializer.lua</tt>
jbe@278 214 </li>
jbe@278 215 <li>
jbe@278 216 <tt>30_third_prefork_initializer.lua</tt>
jbe@278 217 </li>
jbe@278 218 </ul>
jbe@278 219 </li>
jbe@278 220 <li>
jbe@278 221 <tt>_postfork/</tt>
jbe@278 222 <ul>
jbe@278 223 <li>
jbe@278 224 <tt>01_first_postfork_initializer.lua</tt>
jbe@278 225 </li>
jbe@278 226 <li>
jbe@278 227 <tt>03_third_postfork_initializer.lua</tt>
jbe@278 228 </li>
jbe@278 229 </ul>
jbe@278 230 </li>
jbe@278 231 <li>
jbe/bsw@0 232 <tt>main/</tt>
jbe/bsw@0 233 <ul>
jbe/bsw@0 234 <li>
jbe@278 235 <tt>_prefork/</tt>
jbe@278 236 <ul>
jbe@278 237 <li>
jbe@278 238 <tt>20_second_prefork_initializer.lua</tt>
jbe@278 239 </li>
jbe@278 240 </ul>
jbe@278 241 </li>
jbe@278 242 <li>
jbe@278 243 <tt>_postfork/</tt>
jbe@278 244 <ul>
jbe@278 245 <li>
jbe@278 246 <tt>02_second_postfork_initializer.lua</tt>
jbe@278 247 </li>
jbe@278 248 </ul>
jbe@278 249 </li>
jbe@278 250 <li>
jbe/bsw@0 251 <tt>_filter/</tt>
jbe/bsw@0 252 <ul>
jbe/bsw@0 253 <li>
jbe/bsw@0 254 <tt>10_first_filter.lua</tt>
jbe@278 255 </li>
jbe/bsw@0 256 <li>
jbe/bsw@0 257 <tt>30_third_filter.lua</tt>
jbe/bsw@0 258 </li>
jbe/bsw@0 259 <li>&hellip;</li>
jbe/bsw@0 260 </ul>
jbe/bsw@0 261 </li>
jbe/bsw@0 262 <li>
jbe/bsw@0 263 <tt>_filter_action/</tt>
jbe/bsw@0 264 <ul>
jbe/bsw@0 265 <li>
jbe/bsw@0 266 <tt>20_second_filter.lua</tt>
jbe/bsw@0 267 </li>
jbe/bsw@0 268 <li>&hellip;</li>
jbe/bsw@0 269 </ul>
jbe/bsw@0 270 </li>
jbe/bsw@0 271 <li>
jbe/bsw@0 272 <tt>_filter_view/</tt>
jbe/bsw@0 273 <ul>
jbe/bsw@0 274 <li>&hellip;</li>
jbe/bsw@0 275 </ul>
jbe/bsw@0 276 </li>
jbe/bsw@0 277 <li>
jbe/bsw@0 278 <tt>_layout/</tt>
jbe/bsw@0 279 <ul>
jbe/bsw@0 280 <li>&hellip;</li>
jbe/bsw@0 281 </ul>
jbe/bsw@0 282 </li>
jbe/bsw@0 283 <li>
jbe/bsw@0 284 <tt>index/</tt>
jbe/bsw@0 285 <ul>
jbe/bsw@0 286 <li>
jbe/bsw@0 287 <tt>_action/</tt>
jbe/bsw@0 288 <ul>
jbe/bsw@0 289 <li>
jbe/bsw@0 290 <i>action_name</i><tt>.lua</tt>
jbe/bsw@0 291 </li>
jbe/bsw@0 292 <li>
jbe/bsw@0 293 <i>another_action_name</i><tt>.lua</tt>
jbe/bsw@0 294 </li>
jbe/bsw@0 295 <li>&hellip;</li>
jbe/bsw@0 296 </ul>
jbe/bsw@0 297 </li>
jbe/bsw@0 298 <li>
jbe/bsw@0 299 <tt>index.lua</tt>
jbe/bsw@0 300 </li>
jbe/bsw@0 301 <li>
jbe/bsw@0 302 <i>other_view_name</i><tt>.lua</tt>
jbe/bsw@0 303 </li>
jbe/bsw@0 304 <li>&hellip;</li>
jbe/bsw@0 305 </ul>
jbe/bsw@0 306 </li>
jbe/bsw@0 307 <li>
jbe/bsw@0 308 <i>other_module_name</i><tt>/</tt>
jbe/bsw@0 309 <ul>
jbe/bsw@0 310 <li>&hellip;</li>
jbe/bsw@0 311 </ul>
jbe/bsw@0 312 </li>
jbe/bsw@0 313 </ul>
jbe/bsw@0 314 </li>
jbe/bsw@0 315 <li>
jbe/bsw@0 316 <i>other_application_name</i><tt>/</tt>
jbe/bsw@0 317 <ul>
jbe/bsw@0 318 <li>&hellip;</li>
jbe/bsw@0 319 </ul>
jbe/bsw@0 320 </li>
jbe/bsw@0 321 </ul>
jbe/bsw@0 322 </li>
jbe/bsw@0 323 <li>
jbe/bsw@0 324 <tt>config/</tt>
jbe/bsw@0 325 <ul>
jbe/bsw@0 326 <li>
jbe/bsw@0 327 <tt>development.lua</tt>
jbe/bsw@0 328 </li>
jbe/bsw@0 329 <li>
jbe/bsw@0 330 <tt>production.lua</tt>
jbe/bsw@0 331 <li>
jbe/bsw@0 332 <li>
jbe/bsw@0 333 <i>other_config_name</i><tt>.lua</tt>
jbe/bsw@0 334 </li>
jbe/bsw@0 335 <li>&hellip;</li>
jbe/bsw@0 336 </ul>
jbe/bsw@0 337 </li>
jbe/bsw@0 338 <li>
jbe/bsw@0 339 <tt>db/</tt>
jbe/bsw@0 340 <ul>
jbe/bsw@0 341 <li>
jbe/bsw@0 342 <tt>schema.sql</tt>
jbe/bsw@0 343 </li>
jbe/bsw@0 344 </ul>
jbe/bsw@0 345 </li>
jbe/bsw@0 346 <li>
jbe/bsw@0 347 <tt>locale/</tt>
jbe/bsw@0 348 <ul>
jbe/bsw@0 349 <li>
jbe/bsw@0 350 <tt>translations.de.lua</tt>
jbe/bsw@0 351 </li>
jbe/bsw@0 352 <li>
jbe/bsw@0 353 <tt>translations.en.lua</tt>
jbe/bsw@0 354 </li>
jbe/bsw@0 355 <li>
jbe/bsw@0 356 <tt>translations.</tt><i>languagecode</i><tt>.lua</tt>
jbe/bsw@0 357 </li>
jbe/bsw@0 358 <li>&hellip;</li>
jbe/bsw@0 359 </ul>
jbe/bsw@0 360 </li>
jbe/bsw@0 361 <li>
jbe/bsw@0 362 <tt>model/</tt>
jbe/bsw@0 363 <ul>
jbe/bsw@0 364 <li>
jbe/bsw@0 365 <i>model_name</i><tt>.lua</tt>
jbe/bsw@0 366 </li>
jbe/bsw@0 367 <li>
jbe/bsw@0 368 <i>another_model_name</i><tt>.lua</tt>
jbe/bsw@0 369 </li>
jbe/bsw@0 370 <li>&hellip;</li>
jbe/bsw@0 371 </ul>
jbe/bsw@0 372 </li>
jbe/bsw@0 373 <li>
jbe/bsw@0 374 <tt>static/</tt>
jbe/bsw@0 375 <ul>
jbe/bsw@0 376 <li>&hellip; (images, javascript, ...)</li>
jbe/bsw@0 377 </ul>
jbe/bsw@0 378 </li>
jbe/bsw@0 379 <li>
jbe/bsw@0 380 <tt>tmp/</tt> (writable by the web process)
jbe/bsw@0 381 </li>
jbe/bsw@0 382 </ul>
jbe/bsw@0 383 </li>
jbe/bsw@0 384 </ul>
jbe@278 385 <h2>Starting your application</h2>
jbe@278 386 <p>
jbe@278 387 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:
jbe@278 388 </p>
jbe@278 389 <ol>
jbe@278 390 <li>
jbe@278 391 Path of the WebMCP framework directory, e.g. <tt>./framework</tt>
jbe@278 392 </li>
jbe@278 393 <li>
jbe@278 394 Path of your application's directory, e.g. <tt>./demo-app</tt>
jbe@278 395 </li>
jbe@278 396 <li>
jbe@278 397 Name of your applicaiton (usually <tt>main</tt>)
jbe@278 398 </li>
jbe@278 399 <li>
jbe@278 400 Name of configuration (e.g. <tt>devel</tt> to use config/devel.lua)
jbe@278 401 </li>
jbe@278 402 </ol>
jbe/bsw@0 403 <h2>Automatically generated reference for the WebMCP environment</h2>
jbe/bsw@0 404 <ul>

Impressum / About Us