A lot of little eye-candy fixes here and there on the documentation (as well as some...
[clinton/lisp-on-lines.git] / lisp-on-lines.lyx
1 #LyX 1.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 221
3 \textclass article
4 \language english
5 \inputencoding auto
6 \fontscheme default
7 \graphics default
8 \paperfontsize default
9 \papersize Default
10 \paperpackage a4
11 \use_geometry 0
12 \use_amsmath 0
13 \use_natbib 0
14 \use_numerical_citations 0
15 \paperorientation portrait
16 \secnumdepth 3
17 \tocdepth 3
18 \paragraph_separation indent
19 \defskip medskip
20 \quotes_language english
21 \quotes_times 2
22 \papercolumns 1
23 \papersides 1
24 \paperpagestyle default
25
26 \layout Title
27
28 LISP-ON-LINES
29 \layout Author
30
31 Drew Crapmsie, José Pablo Ezequiel
32 \begin_inset Quotes eld
33 \end_inset
34
35 Pupeno
36 \begin_inset Quotes erd
37 \end_inset
38
39 Fernández Silva
40 \layout Section
41
42 Components
43 \layout Description
44
45 Meta\SpecialChar ~
46 Model\SpecialChar ~
47 Protocol A Protocol for introspection on relational objects.
48 \layout Description
49
50 Mewa\SpecialChar ~
51 Presentations A Mewa-like
52 \begin_inset Foot
53 collapsed true
54
55 \layout Standard
56
57 http://www.adrian-lienhard.ch/files/mewa.pdf
58 \end_inset
59
60 layer for UncommonWeb
61 \begin_inset Foot
62 collapsed true
63
64 \layout Standard
65
66 http://common-lisp.net/project/ucw/
67 \end_inset
68
69 Presentations.
70 \layout Section
71
72 Description
73 \layout Standard
74
75 LISP-ON-LINES (LOL) is a framework for rapid development of complex data-driven
76 web appilcations.
77
78 \layout Section
79
80 Introduction:
81 \layout Section
82
83 Example:
84 \layout Standard
85
86 First we start with the data model.
87 The Meta Model Protocol (MMP) is used to provide information on the data
88 objects and how they relate to one another.
89 Its is currently implemented as a layer over CLSQL
90 \begin_inset Foot
91 collapsed true
92
93 \layout Standard
94
95 http://clsql.b9.com/
96 \end_inset
97
98 , although support is planned for other backends (CLOS, Elephant[4], whatever).
99 \layout Standard
100
101 The MMP shares its definition syntax with CLSQL's Object Oriented Data Definitio
102 n Language (OODDL)
103 \begin_inset Foot
104 collapsed true
105
106 \layout Standard
107
108 http://clsql.b9.com/manual/ref-ooddl.html
109 \begin_inset Note
110 collapsed true
111
112 \layout Standard
113
114 Shouldn't this footnote be a bibliographical entry ? or something like that
115 ?
116 \end_inset
117
118
119 \end_inset
120
121 .
122 The macro to define view-classes is named DEF-VIEW-CLASS/META, and takes
123 the same arguments as DEF-VIEW-CLASS from CLSQL.
124 For the purposes of this simple example, we will only need two functions
125 from the MMP beyond what CLSQL provides : LIST-SLOTS and LIST-SLOT-TYPES[5].
126 \layout Standard
127
128 We'll define a simple class to hold a user.
129 \layout LyX-Code
130
131 (def-view-class/meta user ()
132 \layout LyX-Code
133
134 ((userid :initarg :userid :accessor userid :type integer :db-kind :key)
135 \layout LyX-Code
136
137 (username :initarg :username :accessor username :type string :db-kind
138 :base)
139 \layout LyX-Code
140
141 (password :initarg :password :accessor password :type string :db-kind
142 :base)))
143 \layout Standard
144
145 and now we create a user:
146 \layout LyX-Code
147
148 (defparameter user (make-instance 'user :userid 1
149 \layout LyX-Code
150
151 :username "drewc"
152 \layout LyX-Code
153
154 :password "p@ssw0rd"))
155 \layout Standard
156
157 We can see the slots of users running:
158 \layout LyX-Code
159
160 (lisp-on-lines::list-slots user)
161 \layout Standard
162
163 which returns:
164 \layout LyX-Code
165
166 (USERID USERNAME PASSWORD)
167 \layout Standard
168
169 or the types with:
170 \layout LyX-Code
171
172 (lisp-on-lines::list-slot-types user)
173 \layout Standard
174
175 which returns:
176 \layout LyX-Code
177
178 ((USERID INTEGER) (USERNAME STRING) (PASSWORD STRING))
179 \layout Standard
180
181 We can run:
182 \layout LyX-Code
183
184 (lisp-on-lines::default-attributes user)
185 \layout Standard
186
187 which returns:
188 \layout LyX-Code
189
190 ((userid integer :label "User ID" :slot-name 'userid)
191 \layout LyX-Code
192
193 (username string :label "User name" :slot-name 'username)
194 \layout LyX-Code
195
196 (password string :label "Password" :slot-name 'password))
197 \layout Standard
198
199 fdsa
200 \layout LyX-Code
201
202 (set-default-attributes user)
203 \layout LyX-Code
204
205 \layout LyX-Code
206
207 \layout LyX-Code
208
209 ((userid integer :label "User ID" :slot-name 'userid)
210 \layout LyX-Code
211
212 (username string :label "User name" :slot-name 'username)
213 \layout LyX-Code
214
215 (password string :label "Password" :slot-name 'password))
216 \layout LyX-Code
217
218 \layout LyX-Code
219
220 (find-class-attributes user)
221 \layout LyX-Code
222
223 (USER (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)
224 \layout LyX-Code
225
226 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
227 \layout LyX-Code
228
229 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
230 \layout LyX-Code
231
232 COMMON-LISP:NIL)
233 \layout LyX-Code
234
235 LISP-ON-LINES> ;;;; note that the mewa functions (find-attribute, set-attribute
236 etc) can take either an instance, or a class-name as a symbol , ie :
237 \layout LyX-Code
238
239 ; No value
240 \layout LyX-Code
241
242 LISP-ON-LINES> (find-class-attributes 'user)
243 \layout LyX-Code
244
245 (USER (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)
246 \layout LyX-Code
247
248 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
249 \layout LyX-Code
250
251 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
252 \layout LyX-Code
253
254 COMMON-LISP:NIL)
255 \layout LyX-Code
256
257 LISP-ON-LINES> (find-class-attributes (make-instance 'user))
258 \layout LyX-Code
259
260 (USER (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)
261 \layout LyX-Code
262
263 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
264 \layout LyX-Code
265
266 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
267 \layout LyX-Code
268
269 COMMON-LISP:NIL)
270 \layout LyX-Code
271
272 LISP-ON-LINES>
273 \layout Standard
274
275 Using that information, we have enough to create an interface to the object.
276 UncommonWeb includes a powerful presentation system, but it is not quite
277 dynamic enough for our needs.
278 Mewa defines an approach to presentations that suits our purposes, but
279 the paper is written from a smalltalk point of view.
280 A mixture of the two , Mewa Presentations(MP), is described here.
281 \layout Standard
282
283 MP introduces to UCW the concept of attributes.
284 an attribute is essentially a named version of the defpresentation slot-like
285 arguments.
286 for example in :
287 \layout Standard
288
289 (defpresentation person-editor (object-presentation)
290 \layout Standard
291
292 ((string :label "First Name" :slot-name 'first-name :max-length 30)))
293 \layout Standard
294
295 the (string :label "First Name" ...) form is an attribute definiton.
296 Attributes are accessed through FIND-ATTIRIBUTES, and are composed at run
297 time (where the current system is done at compile time) to display the
298 object.
299 This allows a very flexible system of displaying objects which is reminiscent
300 of CSS.
301 I discovered this, rather than invent or design it, so there are some rough
302 edges, but its a good start.
303 \layout Standard
304
305 Its much easier to show this then to tell.
306 Lets present our user class.
307 Currently in UCW, you'd define a presentation as such :
308 \layout Standard
309
310 (defpresentation user-presentation (object-presentation)
311 \layout Standard
312
313 ((INTEGER :LABEL "USERID" :SLOT-NAME USERID)
314 \layout Standard
315
316 (STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
317 \layout Standard
318
319 (STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)))
320 \layout Standard
321
322 which could be presented using PRESENT-OBJECT :
323 \layout Standard
324
325 (present-object user :using 'user-presentation)
326 \layout Standard
327
328 The equiv approach using mewa presentations is actually longer and more
329 verbose(!) but it serves to demonstrate how the MP system works.
330 \layout Standard
331
332 Mewa Presentations adds a set of attributes to a class, keyed off the class
333 name.
334 Attributes are inherited, so if you define an attribute on T, you can use
335 it with any class.
336 \layout Standard
337
338 MP stores named attributes keyed on a class name.
339 to achieve the same functionality as the above using mp would look like
340 this :
341 \layout Standard
342
343 LISP-ON-LINES> (setf (find-attribute 'user :viewer) '(mewa-object-presentation
344 :attributes (userid username password) :global-properties (:editablep nil)))
345 \layout Standard
346
347 (:VIEWER MEWA-OBJECT-PRESENTATION
348 \layout Standard
349
350 :ATTRIBUTES
351 \layout Standard
352
353 (USERID USERNAME PASSWORD)
354 \layout Standard
355
356 :GLOBAL-PROPERTIES
357 \layout Standard
358
359 (:EDITABLEP NIL))
360 \layout Standard
361
362 LISP-ON-LINES> (setf (find-attribute 'user 'userid) '(INTEGER :LABEL "USERID"
363 :SLOT-NAME USERID))
364 \layout Standard
365
366 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
367 \layout Standard
368
369 LISP-ON-LINES> (setf (find-attribute 'user 'username) '(STRING :LABEL "USERNAME"
370 :SLOT-NAME USERNAME))
371 \layout Standard
372
373 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
374 \layout Standard
375
376 LISP-ON-LINES> (setf (find-attribute 'user 'password) '(STRING :LABEL "USERNAME"
377 :SLOT-NAME PASSWORD))
378 \layout Standard
379
380 (PASSWORD STRING :LABEL "USERNAME" :SLOT-NAME PASSWORD)
381 \layout Standard
382
383 LISP-ON-LINES> (find-class-attributes 'user)
384 \layout Standard
385
386 (USER (PASSWORD STRING :LABEL "PASSWORD" :SLOT-NAME PASSWORD)
387 \layout Standard
388
389 (USERNAME STRING :LABEL "USERNAME" :SLOT-NAME USERNAME)
390 \layout Standard
391
392 (USERID INTEGER :LABEL "USERID" :SLOT-NAME USERID)
393 \layout Standard
394
395 (:VIEWER MEWA-OBJECT-PRESENTATION
396 \layout Standard
397
398 :ATTRIBUTES
399 \layout Standard
400
401 (USERID USERNAME PASSWORD)
402 \layout Standard
403
404 :GLOBAL-PROPERTIES
405 \layout Standard
406
407 (:EDITABLEP NIL))
408 \layout Standard
409
410 COMMON-LISP:NIL)
411 \layout Standard
412
413 this is all turned into a UCW presentation at runtime using MAKE-PRESENTATION
414 :
415 \layout Standard
416
417 (defmethod render-on ((res response) (e presentations-index))
418 \layout Standard
419
420 "
421 \layout Standard
422
423 As you'll see, nothing is exported from the LISP-ON-LINES package.
424
425 \layout Standard
426
427 if you wish to use LOL in your own package (or in UCW-USER or whatever),
428 \layout Standard
429
430 you simply need to use the MEWA and META-MODEL packages"
431 \layout Standard
432
433 (<ucw:render-component :component (lisp-on-lines::make-presentation lisp-on-line
434 s::user :type :viewer)))
435 \layout Standard
436
437 SET-ATTRIBUTE can be used in place of (setf (find-attribute)) when you want
438 to "inherit" the properties of an existing attribute definition :
439 \layout Standard
440
441 LISP-ON-LINES> (set-attribute 'user 'password '(string :label "password:
442 (must be at leat 8 chars)"))
443 \layout Standard
444
445 (PASSWORD STRING
446 \layout Standard
447
448 :LABEL
449 \layout Standard
450
451 "password: (must be at leat 8 chars)"
452 \layout Standard
453
454 :SLOT-NAME
455 \layout Standard
456
457 PASSWORD)
458 \layout Standard
459
460 Now we want to create a presentation with which to edit the username.
461 we will use the existing attributes on a subclass of mewa-object-presetation
462 :
463 \layout Standard
464
465 LISP-ON-LINES> (defcomponent user-editor (mewa-object-presentation)
466 \layout Standard
467
468 ()
469 \layout Standard
470
471 (:default-initargs
472 \layout Standard
473
474 :attributes '((username :label "Enter your New Username") password)
475 \layout Standard
476
477 :global-properties '(:editablep t)))
478 \layout Standard
479
480 USER-EDITOR
481 \layout Standard
482
483 LISP-ON-LINES> (setf (find-attribute 'user :editor) '(user-editor))
484 \layout Standard
485
486 (:EDITOR USER-EDITOR)
487 \layout Standard
488
489 LISP-ON-LINES>
490 \layout Standard
491
492 which we then can display below our earlier example :
493 \layout Standard
494
495 (defmethod render-on ((res response) (e presentations-index))
496 \layout Standard
497
498 "
499 \layout Standard
500
501 As you'll see, nothing is exported from the LISP-ON-LINES package.
502
503 \layout Standard
504
505 if you wish to use LOL in your own package (or in UCW-USER or whatever),
506 \layout Standard
507
508 you simply need to use the MEWA and META-MODEL packages"
509 \layout Standard
510
511 (<ucw:render-component :component (lisp-on-lines::make-presentation lisp-on-line
512 s::user :type :viewer))
513 \layout Standard
514
515 (<ucw:render-component :component (lisp-on-lines::make-presentation lisp-on-line
516 s::user :type :editor)))
517 \layout Standard
518
519 that should give you some idea on how it works ..
520 ask me when you get confused :)
521 \the_end