Arc provides a large number of operations for generating HTML. The basic operations are gentag
to generate a standalone tag such as <img>
, and tag
to generate an open/close tag pair surrounding something. In addition, Arc provides special-purpose functions for common HTML operations.
Arc has many operations to support forms, as well as many table operations, as tables are its primary layout technique.
For example, the following code generates a simple page with text, formatting, and a link.
(whitepage (prn "Hello world!") (para) (link "Click here") (prn "for") (prbold "more stuff"))
The basic model is gentag
generates a stand-alone tag, tag
generates a begin/end tag pair surrounding something, and a variety of operations can be used for many tags.
A tag in Arc can be defined with a tag spec, which is a tag followed by attributes and values. The syntax is slightly different for gentag
and tag
. gentag
takes the tag, attributes and values as arguments, while tag
takes the tag spec as a single argument followed by body code that outputs the tag content to stdout. For example:
arc> (tostring (gentag p style "mystyle")) "<p style=\"mystyle\">" arc> (tostring (tag (p style "mystyle") (pr "Content.") (pr "More content"))) "<p style=\"mystyle\">Content.More content</p>"
Most of the HTML generation in Arc is stdout-based, rather than return-value-based. A typical HTML operation in Arc outputs a tag to stdout and executes body code which outputs the tag contents to stdout. The return value is generally not useful. This programming model fits well with Arc's web server, which expects content to be written to stdout in many cases. Note that this programming model is different from the standard functional programming model, but it has the advantage that the outputs from multiple functions can be collected and concatenated. For example,
arc> (tostring (underline (prn "hello") (prn "world"))) "<u>hello\nworld\n</u>"(In the examples, the code is wrapped in
tostring
to explicitly capture stdout for clarity, but tostring
normally wouldn't be used when implementing web pages.)
However, some HTML operations don't collect output from the body code, but use explicit arguments. For example,
arc> (tostring (row 1 2)) "<tr><td>1</td><td>2</td></tr>"Other HTML operations accept either a list of atom arguments, or body code that outputs to stdout, but not a mixture. For example,
arc> (tostring (td (pr "hi"))) "<td>hi</td>" arc> (tostring (td "hi")) "<td>hi</td>"Arc's HTML generation is relatively inflexible. Tags can only use attributes that are explicitly registered in the attributes table. The only exception is the
style
attribute; all tags support that attribute. Other attributes are ignored with a comment in the created HTML code. The following table shows the attributes supported by Arc:
<a class=string href=string id=sym onclick=string rel=string> <body alink=color bgcolor=color leftmargin=number link=color marginheight=number marginwidth=number topmargin=number vlink=color> <font color=color face=string size=number> <form action=string method=sym> <hr color=color> <img align=sym border=number height=number hspace=number src=string vspace=number width=number> <input name=string size=number type=sym value=escaped> <option selected=selected> <rss version=string> <select name=string> <span align=string class=string id=sym> <table bgcolor=color border=number cellpadding=number cellspacing=number width=string> <td align=sym bgcolor=color class=string colspan=number valign=sym width=number> <textarea cols=number name=string rows=number wrap=sym> <tr bgcolor=color>New tags do not need to be explicitly defined, but any desired attributes that are not listed above need to be defined using
attribute
. For instance to support the "class" attribute for img
:
arc> (attribute img class opstring) arc> (tostring (gentag img class "foo")) "<img class=\"foo\">"