📄 app.html
字号:
of <a href="#cssAttr">CSS Attributes</a> below). It will be passed to the<code>body</code> tag.</ol><p>After these four arguments, an arbitrary number of expressions may follow.They form the body of the resulting page, and are evaluated according to aspecial rule. <a name="tagRule">This rule</a> is slightly different from theevaluation of normal Lisp expressions:<p><ul><li>If an argument is an atom (a number or a symbol (string)), its value isprinted immediately.<li>Otherwise (a list), it is evaluated as a Lisp function (typically some formof print statement).</ul><p>Therefore, our source file might as well be written as:<p><pre><code>########################################################################(html 0 "Hello" "lib.css" NIL (prinl "Hello World!") )########################################################################</code></pre><p>The most typical print statements will be some HTML-tags:<p><pre><code>########################################################################(html 0 "Hello" "lib.css" NIL (<h1> NIL "Hello World!") (<br> "This is some text.") (ht:Prin "And this is a number: " (+ 1 2 3)) )########################################################################</code></pre><p><code><h1></code> and <code><br></code> are tag functions.<code><h1></code> takes a CSS attribute as its first argument.<p>Note the use of <code>ht:Prin</code> instead of <code>prin</code>.<code>ht:Prin</code> should be used for all direct printing in HTML pages,because it takes care to escape special characters.<p><hr><h3><a name="cssAttr">CSS Attributes</a></h3><p>The <a href="#htmlFoo"><code>html</code> function</a> above, and many of theHTML <a href="#tags">tag functions</a>, accept a CSS attribute specification.This may be either an atom, a cons pair, or a list of cons pairs. We demonstratethe effects with the <code><h1></code> tag function.<p>An atom (usually a symbol or a string) is taken as a CSS class name<p><pre><code>: (<h1> 'foo "Title")<h1 class="foo">Title</h1></code></pre><p>For a cons pair, the CAR is taken as an attribute name, and the CDR as theattribute's value<p><pre><code>: (<h1> '(id . bar) "Title")<h1 id="bar">Title</h1></code></pre><p>Consequently, a list of cons pairs gives a set of attribute-value pairs<p><pre><code>: (<h1> '((id . "abc") (lang . "de")) "Title")<h1 id="abc" lang="de">Title</h1></code></pre><p><hr><h3><a name="tags">Tag Functions</a></h3><p>All pre-defined XHTML tag functions can be found in "lib/xhtml.l". Werecommend to look at their sources, and to experiment a bit, by executing themat a Pico Lisp prompt, or by pressing the browser's "Reload" button afterediting the "project.l" file.<p>For a suitable Pico Lisp prompt, either execute (in a separate terminalwindow) the Pico Lisp Shell (<code>psh</code>) command (works only if theapplication server is running, and you did generate a <a href="#pw">".pw"file</a>)<p><pre><code>$ bin/psh 8080:</code></pre><p>or start the interpreter stand-alone, with "lib/xhtml.l" loaded<p><pre><code>$ ./p dbg.l lib/http.l lib/xhtml.l:</code></pre><p>Note that for all these tag functions the above <a href="#tagRule">tag bodyevaluation rule</a> applies.<h4><a name="simple">Simple Tags</a></h4><p>Most tag functions are simple and straightforward. Some of them just printtheir arguments<p><pre><code>: (<br> "Hello world")Hello world<br/>: (<em> "Hello world")<em>Hello world</em></code></pre><p>while most of them take a <a href="#cssAttr">CSS attribute specification</a>as their first argument (like the <code><h1></code> tag above)<p><pre><code>: (<div> 'main "Hello world")<div class="main">Hello world</div>: (<p> NIL "Hello world")<p>Hello world</p>: (<p> 'info "Hello world")<p class="info">Hello world</p></code></pre><p>All of these functions take an arbitrary number of arguments, and may nest toan arbitrary depth (as long as the resulting HTML is legal)<p><pre><code>: (<div> 'main (<h1> NIL "Head") (<p> NIL (<br> "Line 1") "Line" (<nbsp>) (+ 1 1) ) )<div class="main"><h1>Head</h1><p>Line 1<br/>Line 2</p></div></code></pre><h4><a name="lists">(Un)ordered Lists</a></h4><p>HTML-lists, implemented by the <code><ol></code> and<code><ul></code> tags, let you define hierarchical structures. You mightwant to paste the following code into your copy of "project.l":<p><pre><code>########################################################################(html 0 "Unordered List" "lib.css" NIL (<ul> NIL (<li> NIL "Item 1") (<li> NIL "Sublist 1" (<ul> NIL (<li> NIL "Item 1-1") (<li> NIL "Item 1-2") ) ) (<li> NIL "Item 2") (<li> NIL "Sublist 2" (<ul> NIL (<li> NIL "Item 2-1") (<li> NIL "Item 2-2") ) ) (<li> NIL "Item 3") ) )########################################################################</code></pre><p>Here, too, you can put arbitrary code into each node of that tree, includingother tag functions.<h4><a name="tables">Tables</a></h4><p>Like the hierarchical structures with the list functions, you can generatetwo-dimensional tables with the <code><table></code> and<code><row></code> functions.<p>The following example prints a table of numbers and their squares:<p><pre><code>########################################################################(html 0 "Table" "lib.css" NIL (<table> NIL NIL NIL (for (N 1 (>= 10 N) (inc N)) # A table with 10 rows (<row> NIL N (prin (* N N))) ) ) ) # and 2 columns########################################################################</code></pre><p>The first argument to <code><table></code> is the usual CSS attribute,the second an optional title ("caption"), and the third an optional listspecifying the column headers. In that list, you may supply a list for a eachcolumn, with a CSS attribute in its CAR, and a tag body in its CDR for thecontents of the column header.<p>The body of <code><table></code> contains calls to the<code><row></code> function. This function is special in that eachexpression in its body will go to a separate column of the table. If both forthe column header and the row function an CSS attribute is given, they will becombined by a space and passed to the HTML <code><td></code> tag. Thispermits distinct CSS specifications for each column and row.<p>As an extension of the above table example, let's pass some attributes forthe table itself (not recommended - better define such styles in a CSS file andthen just pass the class name to <code><table></code>), right-align bothcolumns, and print each row in an alternating red and blue color<p><pre><code>########################################################################(html 0 "Table" "lib.css" NIL (<table> '((width . "200px") (style . "border: dotted 1px;")) # table style "Square Numbers" # caption '((align "Number") (align "Square")) # 2 headers (for (N 1 (>= 10 N) (inc N)) # 10 rows (<row> (xchg '(red) '(blue)) # red or blue N # 2 columns (prin (* N N) ) ) ) ) )########################################################################</code></pre><p>If you wish to concatenate two or more cells in a table, so that a singlecell spans several columns, you can pass the symbol '<code>-</code>' for theadditional cell data to <code><row></code>. This will cause the data givento the left of the '<code>-</code>' symbols to expand to the right.<p>You can also directly specify table structures with the simple<code><th></code>, <code><tr></code> and <code><td></code> tagfunctions.<p>If you just need a two-dimensional arrangement of components, the evensimpler <code><grid></code> function might be convenient:<p><pre><code>########################################################################(html 0 "Grid" "lib.css" NIL (<grid> 3 "A" "B" "C" 123 456 789 ) )########################################################################</code></pre><p>It just takes a specification for the number of columns (here: 3) as itsfirst argument, and then a single expression for each cell. Instead of a number,you can also pass a list of CSS attributes. Then the length of that list willdetermine the number of columns. You can change the second line in the aboveexample to<p><pre><code> (<grid> '(NIL NIL right)</code></pre><p>Then the third column will be right aligned.<h4><a name="menus">Menus and Tabs</a></h4><p>The two most powerful tag functions are <code><menu></code> and<code><tab></code>. Used separately or in combination, they form anavigation framework with<p><ul><li>menu items which open and close submenus<li>submenu items which switch to different pages<li>tabs which switch to different subpages</ul><p>The following example is not very useful, because the URLs of all items linkto the same "project.l" page, but it should suffice to demonstrate thefunctionality:<p><pre><code>########################################################################(html 0 "Menu+Tab" "lib.css" NIL (<div> '(id . menu) (<menu> ("Item" "project.l") # Top level item (NIL (<hr>)) # Plain HTML (T "Submenu 1" # Submenu ("Subitem 1.1" "project.l") (T "Submenu 1.2" ("Subitem 1.2.1" "project.l") ("Subitem 1.2.2" "project.l") ("Subitem 1.2.3" "project.l") ) ("Subitem 1.3" "project.l") ) (T "Submenu 2" ("Subitem 2.1" "project.l") ("Subitem 2.2" "project.l") ) ) ) (<div> '(id . main) (<h1> NIL "Menu+Tab") (<tab> ("Tab1" (<h3> NIL "This is Tab 1") ) ("Tab2" (<h3> NIL "This is Tab 2") ) ("Tab3" (<h3> NIL "This is Tab 3") ) ) ) )########################################################################</code></pre><p><code><menu></code> takes a sequence of menu items. Each menu item is alist, with its CAR either<p><ul><li><code>NIL</code>: The entry is not an active menu item, and the rest of thelist may consist of arbitrary code (usually HTML tags).<li><code>T</code>: The second element is taken as a submenu name, and a clickon that name will open or close the corresponding submenu. The rest of the listrecursively specifies the submenu items (may nest to arbitrary depth).<li>Otherwise: The menu item specifies a direct action (instead of opening asubmenu), where the first list element gives the item's name, and the secondelement the corresponding URL.</ul><p><code><tab></code> takes a list of subpages. Each page is simply a tabname, followed by arbitrary code (typically HTML tags).<p>Note that only a single menu and a single tab may be active at the same time.<p><hr><h2><a name="forms">Interactive Forms</a></h2><p>In HTML, the only possibility for user input is via <code><form></code>and <code><input></code> elements, using the HTTP POST method tocommunicate with the server.<p>"lib/xhtml.l" defines a function called <code><post></code>, and acollection of input tag functions, which allow direct programming of HTML forms.We will supply only one simple example:<p><pre><code>########################################################################(html 0 "Simple Form" "lib.css" NIL (<post> NIL "project.l" (<field> 10 '*Text) (<submit> "Save") ) )########################################################################</code></pre><p>This associates a text input field with a global variable <code>*Text</code>.The field displays the current value of <code>*Text</code>, and pressing thesubmit button causes a reload of "project.l" with <code>*Text</code> set to anystring entered by the user.<p>An application program could then use that variable to do something useful,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -