diff options
Diffstat (limited to 'test/examples/www')
| -rw-r--r-- | test/examples/www/README | 10 | ||||
| -rw-r--r-- | test/examples/www/db.lua | 46 | ||||
| -rw-r--r-- | test/examples/www/staff.lua | 37 | ||||
| -rw-r--r-- | test/examples/www/template.html | 29 |
4 files changed, 122 insertions, 0 deletions
diff --git a/test/examples/www/README b/test/examples/www/README new file mode 100644 index 00000000..0c249a43 --- /dev/null +++ b/test/examples/www/README @@ -0,0 +1,10 @@ +This directory contains a database for a fake web site. +Standard web page for the persons listed in db.lua are +creared automatically from template.html with staff.lua. +(See http://www.cos.ufrj.br for a real web site was created in this way.) + +To run, type lua db.lua. + +This example is meant to show the power of gsub and Lua declarative constructs, +which have been combined here into a "mail-merge" application. + diff --git a/test/examples/www/db.lua b/test/examples/www/db.lua new file mode 100644 index 00000000..837afd29 --- /dev/null +++ b/test/examples/www/db.lua @@ -0,0 +1,46 @@ +dofile("staff.lua") + +global{ + ROOT='http://www.tecgraf.puc-rio.br', + EMAIL="|LOGIN|@tecgraf.puc-rio.br", + WWW="|ROOT|/~|LOGIN|", + webmast='|ROOT|/webmaster.html', + TECGRAF='<A HREF="http://www.tecgraf.puc-rio.br">TeCGraf</A>', + CS='<A HREF="http://www.inf.puc-rio.br">Computer Science Department</A>', + PUCRIO='<A HREF="http://www.puc-rio.br">PUC-Rio</A>', +} + +staff{ +DI="inf.puc-rio.br", + LOGIN="roberto", + NAME="Roberto Ierusalimschy", + TITLE="D.Sc., |PUCRIO|, 1990", + POSITION="Associate Professor, |CS|, |PUCRIO|", + AREAS="Programming Languages, Object Oriented Programming", + EMAIL="|LOGIN|@|DI|", + WWW="http://www.|DI|/~|LOGIN|", +} + +staff{ +PCG="http://www.graphics.cornell.edu", + LOGIN="celes", + NAME="Waldemar Celes", + TITLE="D.Sc., |PUCRIO|, 1995", + POSITION="Postdoctoral Associate at ".. +'<A HREF="|PCG|">Program of Computer Graphics</A>, '.. +'<A HREF="http://www.cornell.edu">Cornell University</A>', + WWW="|PCG|/~celes/", + AREAS="Image segmentation and 3D reconstruction; " +.."Physical simulation and educational software;" +.."Geometric modeling and topological data structures;" +.."Extension languages and customizable applications" +} + +staff{ + LOGIN="lhf", + NAME="Luiz Henrique de Figueiredo", + TITLE='D.Sc., <A HREF="http://www.impa.br">IMPA</A>, 1992', + POSITION='Visiting Research fellow at <A HREF="http://www.lncc.br">LNCC</A>; Consultant at |TECGRAF|', + AREAS="Geometric modeling; Software tools", + WWW="http://www2.lncc.br/~lhf/", +} diff --git a/test/examples/www/staff.lua b/test/examples/www/staff.lua new file mode 100644 index 00000000..7fa5b810 --- /dev/null +++ b/test/examples/www/staff.lua @@ -0,0 +1,37 @@ +$debug + +readfrom("template.html") +TEMPLATE=read(".*") +readfrom() + +PAT="|(%a%a*)|" + +GLOBAL={ + DATE=date("%d/%m/%Y %T"), +} + +function get(i) + if LOCAL[i] then return LOCAL[i] + elseif GLOBAL[i] then return GLOBAL[i] + else return "<BLINK>?"..i.."?</BLINK>" end +end + +function global(t) + local i,v=next(t,nil) + while i do + GLOBAL[i]=v + i,v=next(t,i) + end +end + +function staff(t) + LOCAL=t + if t.AREAS then t.AREAS=gsub(t.AREAS,"[;,] *","\n<LI>") end + local p,n=TEMPLATE + if t.WWW=="" then p=gsub(p,'<A HREF="|WWW|">|NAME|</A>',"|NAME|") end + repeat p,n=gsub(p,PAT,get) until n==0 + write(t.LOGIN,"\n") + writeto(t.LOGIN..".html") + write(p) + writeto() +end diff --git a/test/examples/www/template.html b/test/examples/www/template.html new file mode 100644 index 00000000..c8494b76 --- /dev/null +++ b/test/examples/www/template.html @@ -0,0 +1,29 @@ +<HTML> +<HEAD> +<TITLE> +Imaginary web site:Staff:|LOGIN| +</TITLE> +</HEAD> + +<BODY> +<H1><A HREF="|WWW|">|NAME|</A></H1> +<A HREF="mailto:|EMAIL|">|EMAIL|</A> +<P> + +|POSITION|<BR> +|TITLE|<P> + +<H2>Research areas</H2> +<UL> +<LI>|AREAS| +</UL> +<P> + +<HR> +Last update in |DATE| by +<A HREF="|webmast|">websmaster</A>. +<P> + +</BODY> + +</HTML> |
