webmcp

view doc/autodoc-header.htmlpart @ 79:3a6962b9121c

Anchor support for encode.url{...}, ui.link{...} and ui.paginate{...}
author jbe
date Wed Jun 27 18:57:53 2012 +0200 (2012-06-27)
parents 727a10edeb8d
children 6ab448e71d66
line source
1 <html>
2 <head>
3 <style>
4 body {
5 font-family: "Liberation Sans", sans-serif;
6 font-size: 11pt;
7 padding-bottom: 5ex;
8 }
9 .warning {
10 color: #ff0000;
11 }
12 h1, h2 {
13 font-family: "Liberation Serif", Georgia, serif;
14 }
15 h2 {
16 margin-bottom: 0.3ex;
17 }
18 p {
19 margin: 0px;
20 line-height: 130%;
21 }
22 tt, pre {
23 font-size: 10pt;
24 }
25 tt {
26 font-weight: bold;
27 white-space: nowrap;
28 }
29 .autodoc_entry {
30 margin-top: 1ex;
31 margin-bottom: 1ex;
32 }
33 .autodoc_comment_tail {
34 font-style: italic;
35 }
36 .autodoc_entry .short_synopsis {
37 cursor: pointer;
38 }
39 .autodoc_details {
40 padding-left: 1em;
41 padding-right: 1em;
42 border: 1px solid #777;
43 }
44 .autodoc_synopsis {
45 font-weight: bold;
46 }
47 .autodoc_synopsis .autodoc_comment_tail {
48 font-weight: normal;
49 color: #008000;
50 }
51 .autodoc_entry .autodoc_comment {
52 color: #400080;
53 }
54 .autodoc_source {
55 color: #505050;
56 }
57 </style>
58 <title>WebMCP 1.2.2 Documentation</title>
59 </head>
60 <body>
61 <h1>WebMCP 1.2.2 Documentation</h1>
62 <p>
63 WebMCP is a completely new web development framework, and has not been extensively tested yet. The API might change at any time, but in future releases there will be a list of all changes, which break downward compatibility.
64 </p>
65 <h2>Requirements</h2>
66 <p>
67 WebMCP has been developed on Linux and FreeBSD. Using it with Mac&nbsp;OS&nbsp;X is completely untested; Microsoft Windows is not supported. Beside the operating system, the only mandatory dependencies for WebMCP are the programming language <a href="http://www.lua.org/">Lua</a> version 5.1, <a href="http://www.postgresql.org/">PostgreSQL</a> version 8.2 or higher, a C compiler, and a Webserver like Lighttpd or Apache.
68 </p>
69 <h2>Installation</h2>
70 <p>
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. Use the files <tt>doc/lighttpd.sample.conf</tt> or <tt>doc/apache.sample.conf</tt> to setup your webserver appropriatly. 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!
72 </p>
73 <h2>Using the atom library</h2>
74 <p>
75 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:
76 </p>
77 <ul>
78 <li>atom.fraction</li>
79 <li>atom.date</li>
80 <li>atom.time</li>
81 <li>atom.timestamp (date and time combined in one data type)</li>
82 </ul>
83 <p>
84 In addition the following pseudo-types are existent, corresponding to Lua's base types:
85 </p>
86 <ul>
87 <li>atom.boolean</li>
88 <li>atom.string</li>
89 <li>atom.integer</li>
90 <li>atom.number</li>
91 </ul>
92 <p>
93 Both atom.integer and atom.number refer to Lua's base type &ldquo;number&rdquo;.
94 </p>
95 <p>
96 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>.
97 </p>
98 <h2>Using the Object-Relational Mapper &ldquo;mondelefant&rdquo;</h2>
99 <p>
100 The library &ldquo;mondelefant&rdquo; shipping with WebMCP can be used to access PostgreSQL databases. It also serves as an Object-Relational Mapper (ORM). Opening a connection to a database is usually done in a config file in the following way:
101 </p>
102 <pre>
103 db = assert( mondelefant.connect{ engine='postgresql', dbname='webmcp_demo' } )
104 at_exit(function()
105 db:close()
106 end)
107 function mondelefant.class_prototype:get_db_conn() return db end
109 function db:sql_tracer(command)
110 return function(error_info)
111 local error_info = error_info or {}
112 trace.sql{ command = command, error_position = error_info.position }
113 end
114 end</pre>
115 <p>
116 Overwriting the <tt>sql_tracer</tt> method of the database handle is optional, but helpful for debugging. The parameters for <tt>mondelefant.connect</tt> are directly passed to PostgreSQL's client library libpq. See <a href="http://www.postgresql.org/docs/8.4/interactive/libpq-connect.html">PostgreSQL's documentation on PQconnect</a> for information about supported parameters.
117 </p>
118 <p>
119 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:
120 </p>
121 <pre>
122 Movie = mondelefant.new_class()
123 Movie.table = 'movie'</pre>
124 <p>
125 Note: Model classes are always written CamelCase, while the name of the file in <tt>model/</tt> is written lower_case.
126 </p>
127 <p>
128 To select objects from the database, the mondelefant library provides a selector framework:
129 </p>
130 <pre>
131 local s = Movie:new_selector()
132 s:add_where{ 'id = ?', param.get_id() }
133 s:single_object_mode() -- return single object instead of list
134 local movie = s:exec()</pre>
135 <p>
136 A short form of the above query would be:
137 </p>
138 <pre>
139 local movie = Movie:new_selector():add_where{ 'id = ?', param.get_id() }:single_object_mode():exec()</pre>
140 <p>
141 For more examples about how to use the model system, please take a look at the demo application.
142 </p>
143 <h2>The Model-View-Action (MVA) concept</h2>
144 <p>
145 As opposed to other web application frameworks, WebMCP does not use a Model-View-Controller (MVC) concept, but a Model-View-Action (MVA) concept.
146 </p>
147 <h3>Models</h3>
148 <p>
149 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.
150 </p>
151 <h3>Views</h3>
152 <p>
153 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.
154 </p>
155 <h3>Actions</h3>
156 <p>
157 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.
158 </p>
159 <h2>Directory structure of a WebMCP application</h2>
160 <ul>
161 <li>
162 Base Directory
163 <ul>
164 <li>
165 <tt>app/</tt>
166 <ul>
167 <li>
168 <tt>main/</tt>
169 <ul>
170 <li>
171 <tt>_filter/</tt>
172 <ul>
173 <li>
174 <tt>10_first_filter.lua</tt>
175 <li>
176 </li>
177 <tt>30_third_filter.lua</tt>
178 </li>
179 <li>&hellip;</li>
180 </ul>
181 </li>
182 <li>
183 <tt>_filter_action/</tt>
184 <ul>
185 <li>
186 <tt>20_second_filter.lua</tt>
187 </li>
188 <li>&hellip;</li>
189 </ul>
190 </li>
191 <li>
192 <tt>_filter_view/</tt>
193 <ul>
194 <li>&hellip;</li>
195 </ul>
196 </li>
197 <li>
198 <tt>_layout/</tt>
199 <ul>
200 <li>&hellip;</li>
201 </ul>
202 </li>
203 <li>
204 <tt>index/</tt>
205 <ul>
206 <li>
207 <tt>_action/</tt>
208 <ul>
209 <li>
210 <i>action_name</i><tt>.lua</tt>
211 </li>
212 <li>
213 <i>another_action_name</i><tt>.lua</tt>
214 </li>
215 <li>&hellip;</li>
216 </ul>
217 </li>
218 <li>
219 <tt>index.lua</tt>
220 </li>
221 <li>
222 <i>other_view_name</i><tt>.lua</tt>
223 </li>
224 <li>&hellip;</li>
225 </ul>
226 </li>
227 <li>
228 <i>other_module_name</i><tt>/</tt>
229 <ul>
230 <li>&hellip;</li>
231 </ul>
232 </li>
233 </ul>
234 </li>
235 <li>
236 <i>other_application_name</i><tt>/</tt>
237 <ul>
238 <li>&hellip;</li>
239 </ul>
240 </li>
241 </ul>
242 </li>
243 <li>
244 <tt>config/</tt>
245 <ul>
246 <li>
247 <tt>development.lua</tt>
248 </li>
249 <li>
250 <tt>production.lua</tt>
251 <li>
252 <li>
253 <i>other_config_name</i><tt>.lua</tt>
254 </li>
255 <li>&hellip;</li>
256 </ul>
257 </li>
258 <li>
259 <tt>db/</tt>
260 <ul>
261 <li>
262 <tt>schema.sql</tt>
263 </li>
264 </ul>
265 </li>
266 <li>
267 <tt>locale/</tt>
268 <ul>
269 <li>
270 <tt>translations.de.lua</tt>
271 </li>
272 <li>
273 <tt>translations.en.lua</tt>
274 </li>
275 <li>
276 <tt>translations.</tt><i>languagecode</i><tt>.lua</tt>
277 </li>
278 <li>&hellip;</li>
279 </ul>
280 </li>
281 <li>
282 <tt>model/</tt>
283 <ul>
284 <li>
285 <i>model_name</i><tt>.lua</tt>
286 </li>
287 <li>
288 <i>another_model_name</i><tt>.lua</tt>
289 </li>
290 <li>&hellip;</li>
291 </ul>
292 </li>
293 <li>
294 <tt>static/</tt>
295 <ul>
296 <li>&hellip; (images, javascript, ...)</li>
297 </ul>
298 </li>
299 <li>
300 <tt>tmp/</tt> (writable by the web process)
301 </li>
302 </ul>
303 </li>
304 </ul>
305 <h2>Automatically generated reference for the WebMCP environment</h2>
306 <ul>

Impressum / About Us