Advanced META: IMG, A HREF

This document discusses how to use specify additional META information (often involving NewtonScript constructs) that can be used to customize books, and the IMG and A tags. Though eventually it may contain more introductory/tutorial information, currently it assumes at least some NewtonScript experience (via NTK or Newt Development Environment).

Adding META Slots and Values

Earlier, you saw how to use META to add extra Newton-specific slots to the book. In general, slot values are treated as literal string values, however, there are a few cases where the strings are evaluated (and this requires the NewtonScript preference to be set to Compile):

Note: certain names that conflict with the internal book implementation are skipped: VERSION, FLAGS, DATA, STYLES, CONTENTS, BROWSERS, TEMPLATES, RENDERING, _PACKAGE.

Book Scripts

You can include some additional scripts on books (and others described in the BookMaker docs), if you are careful that your NewtonScript methods do not cause errors. Here are some trivial examples:

InstallScript

<META NAME="InstallScript" CONTENT="func(bookFrame) begin Print('BookInstallScript); Print(bookFrame); end">

RemoveScript

<META NAME="RemoveScript" CONTENT="func(removeFrame) begin Print('BookRemoveScript); Print(removeFrame); end">

bookOKClose

<META NAME="SCRIPTS.bookOKClose" CONTENT="func() begin Print(&quot;yes, ok to close (return nil otherwise&quot;); true; end">

bookHideScript

<META NAME="SCRIPTS.bookHideScript" CONTENT="func() Print(&quot;I just closed&quot;)">

bookShowScript

<META NAME="SCRIPTS.bookShowScript" CONTENT="func() Print(&quot;I just opened&quot;)">

package.

Most of the book attributes related to a saved package can be set via regular META slots (described earlier). You can set several additional attributes in the package frame (the values are compiled expressions). Note: _package is also recognized, although _ is apparently an illegal char in META.

labels (symbol)
(default: nil = Unfiled). folder in Extras (on NOS 2.x). Note: it appears that you cannot use 'Help (this is automatic for help-size books), and perhaps other special folders. If folder does not exist, system places book in Unfiled.
compressed (boolean)
(default: nil). if true, Newton compresses the package on the store (the generated package and desktop .pkg are the usual size). Note: access time may be somewhat slower.

For example, this document uses:

<META NAME="package.labels" CONTENT="'Books">
<META NAME="package.compressed" CONTENT="true">

PREF.

An HTML document can temporarily customize Prefs for tags via META. Any local or default preferences are restored when book processing is complete. This mechanism will definitely change when HTML Styles are standardized. For example, <META NAME="pref.H1" CONTENT="{align: 2, font: {family: 'espy, face: 2, size: 24}}">. The content frame can contain some/all of the following slots (same fields as in user Prefs; those that you don't specify would be defaulted to Prefs, and then to built-in):

missing
\"missing ^0\", /* a string pattern for Hx. need \ for embedded string quotes */
above
0, /* indent: an integer, or symbol 'top */
left
0, /* indent: an integer */
below
0, /* indent: an integer */
split
'true, /* boolean (true,nil), or tag symbol, e.g., 'P */
align
0, /* integer (0=left,1=right,2=center,3=justify) */
font
{family: 'espy, face: 1, size: 18}, /* font frame spec or coded-integer */
family
'espy /* symbol: 'espy, 'newYork, 'geneva, 'casual (NOS 2.x only), 'monaco (if installed) */
face
1, /* integer: 0=plain,1=Bold, 2=Italic, 3=BoldItalic,4=Underline */
size
18, /* integer: usually between 9-18 */

Note: though not recommended (since it's non-standard), you can specify specific page breaks for individual tags via attribute ABOVE=TOP, e.g., <P ABOVE=TOP>this is top of page

DATA.

To add Newton-specific values, user prototypes and methods, use META elements that begin with "DATA.", for example (from bodyagt.htm):

<META NAME="data.inboxIcon" CONTENT="@336">
<META NAME="data.beep" CONTENT="func(a1,a2,a3,a4) PlaySound(@102)">

Note: the "data.slot" is similar to regular NewtonScript path syntax, but only works for one level currently (to include more nesting, add your own frame in one META element).

At define-time, the expression is evaluated in a special context that includes:

  1. the data frame itself: earlier DATA. values you may have set.
  2. the current book: book slots such as TITLE and ISBN
  3. NewtDevEnv plug-ins: (optional) useful constants that are are not normally defined in the Newton itself, e.g., platform functions, proto symbols, viewFlags, etc.

Note: this additional context is useful only for non-method expressions (if an expression starts with "func(", no constant substitution is done as in NTK; "constants" would be undefined variables at run-time unless you have defined them yourself in DATA). [More explanation/examples needed; perhaps could borrow NewtDevEnv's :DefConst mechanism?]

The value from this expression is added to a special frame that is stored (permanently) with the book -- this frame can be accessed at run-time inside your methods or externally via the NewtonScript expression: :BookData().

At run-time, a method is invoked in the :BookData() context. This means that the only information available inside the method at this point is the data frame itself (other values you set via DATA.) and any local parameters passed by HREF or SUBMIT.

In Newt's Cape, DATA. objects are used primarily to "shadow", i.e., override, URLs. This permits the same HTML file to have one behavior in a desktop version and another behavior on the Newton. In other words, if a URL is found in DATA. in the Newton version, it takes precedence over the normal URL interpretation. This occurs in three places currently:

  1. IMG SRC -- image source
  2. A HREF -- anchor destinations
  3. FORM ACTION -- form dispatch

Each of these situations allows other forms of shadowing as well. Some examples:

IMG

Newt's Cape checks/interprets a URL for IMG (tag description) with the following precedence:

1. DATA.<URL> = string

If found in DATA, a string value is used instead of the current URL -- and interpretation proceeds to the next steps. This provides a simple mechanism in case you want to remap URLs for some reason, perhaps from multiple desktop directories, to a single Newton soup.

For example (note: enclosing &quot; since string literal is compiled as Newton expression):

<META NAME="DATA.otherdir/othername" CONTENT="&quot;bitmaps/fooicon.gif&quot;">
...
<IMG SRC="otherdir/othername">

2. DATA.<URL> = bitmap/PICT

A bitmap or picture object is used. This would normally be used to access built-in (ROM) objects. For example:

<META NAME="data.inboxIcon" CONTENT="@336">
...
<IMG SRC="inboxIcon">

For animated graphics (examples), the bitmap frame can contain the additional slots:

pics [array]
bitmap frames
delays [array]
delays between frames in milliseconds. array must be same length as pics.
loops [integer/nil]
(optional) number of times to cycle animation (0 or nil means forever)

3. soupName/objName

Finally, the URL is interpreted directly as a reference to a local soup whose name is the "directory", with an entry whose name (or title) slot is the "filename". If the soup entry bitmap or icon slot does not contain a bitmap or PICT object, either the ALT text or the "no picture" icon is displayed. For example: <IMG SRC="bitmaps/nwscpicn.gif" ALT="Newt's Cape Icon">

HREF

When you tap on a link, Newt's Cape checks/interprets a URL for HREF (tag description), with the following precedence:

1. DATA.<URL> = string

A string value is used instead of the current URL -- and interpretation proceeds to the next steps. A simple use of such mapping is when the original desktop filename is quite long (or not unique across directories) and you would like to map this to a Newton ISBN. For example,

<META NAME="DATA.somedir/averylongfilename" CONTENT="&quot;long37.htm&quot;">
...
<A HREF="somedir/averylongfilename">a link</A>

If you would like to combine several separate HTML files, we would recommend that you use LINK REL=Includes to combine books and let Newt's Cape do the HREF mapping for you (also, see later discussion of Credits kludge). But, you can do something like this yourself. For example, here are two hypothetical files: "file1.htm" and "file2.htm":

<-- file1.htm -->
<HTML>
...
<META NAME="DATA.file2.htm" CONTENT="&quot;#file2&quot;">
...
<H1><A NAME="file1">First File</A></H1>
...
<A HREF="file2.htm">a link to file2</A>
...
<-- no </HTML> -->

<-- file2.htm -->
<-- no <HTML> -->
...
<META NAME="DATA.file1.htm" CONTENT="&quot;#file1&quot;">
...
<H1><A NAME="file2">Second File</A></H1>
...
<A HREF="file1.htm">a link to file1</A>
...
</HTML>

2. DATA.<URL> = method

The HREF code invokes your method with four parameters:

  1. x: local Newton screen coordinate(integer)
  2. y (ditto); with x,y maybe you could do some image-map-like processing?
  3. href: the URL(string)
  4. obj: the current "child view" object (frame). obj.item.data refers to text string or bitmap/picture object just tapped.

3. GetRoot().<URL> = application

If the URL refers to a Newton application symbol, the application is sent the :toggle() message (which either opens or closes the application). If you know something about the API of the application, you can provide an alternate message and parameters, in two styles: e.g., HREF="appSymbol/msg?param1,param2,param3", or HREF="appSymbol/msg?slot1=val1&slot2=val2" or HREF="function/param1,...". You can also invoke a global function. See below for brief examples, and exprlink.htm for more explanation and examples. Examples from some built-in apps:

Extras (1.x)

Extras (2.x)

Fixed Buttons

Other Built-in Objects

Extras (2.1)

Method, Function Examples

4. mailto:, http:

If the URL begins with "mailto:", a mail message is posted via the default mail client to the user's Outbox. mailto: supplies the destination address, the subject is the book's TITLE (or ?subject= parameter), and the user can edit the default message body: "hi, I saw this cool document in Newt's Cape".

If the URL begins with "news:", it is passed to URLcop if it is installed, or Newt's Paper (if it and NIE are installed).

If the URL begins with http: on 2.x (with NIE installed), a URL is requested via the internet. Otherwise, Newt's Cape posts an email message. The default destination address (unless set via Proxy) is the WebMail service, and the message body contains commands to fetch the HTML source for a single URL. After sending this message and receiving a reply, Newt's Cape will display the Inbox button and you can select the document to process. Not exactly a real-time web browser, but who's in a hurry?

5. dir1/dir2/isbn#name

Finally, Newt's Cape will attempt to interpret the URL as a local book reference. If there is an ISBN (and a book with that isbn is installed), Newt's Cape opens the book. It then goes to the NAME following # (if any) in the now current book. (It ignores any directories in the path).

If the current book contains a BASE, Newt's Cape will process the request as a complete http: URL (as just described).

LINK

LINK, especially its REL attribute, was described earlier. When combining books, Newt's Cape checks to see if the last page begins with an object named "Credits". If so, it assumes that this page can be removed from each included book (and that you will include a new Credits page at the end of the new document). This is the convention we have used to build Newt's Cape book collections. You can typically force a page break by using H1 (setting above to Top).

The size of a new combined book should be somewhat smaller than the sum of the original books. In addition to eliminating the last pages, the books share new code for following links and adding navigation buttons (though not for form objects). LINK also merges META information and copies FORM data (ACTIONs should be unique across books).

For More Info

This document (in all its formats) is © 1995-2007. Steve Weyer, Greg Simon. All Rights Reserved Worldwide

Version 2.1. Last updated: Dec 2000