GLOBAL INDEX  |  FRAMES  |  NO FRAMES
Library: printing
Overview
Helper functions for working with strings and easily formatting objects as HTML.
source: printing.js
examples
var person = { firstName: "Ben", lastName: "Bitfiddler" };
person.toString = function() {
  return this.firstName + " " + this.lastName;
}
print(person); // prints "Ben Bitfiddler"
Functions
print(thing1, thing2, etc)
HTML-aware printing. This function prints its arguments to the body of the page. Printing a string will cause it to show up as-is on the screen (even if it contains HTML tags or angle-brackets). Printing an HTML tag object will cause it to be rendered on the screen. Printing a normal Javascript object or array will cause it to be rendered in an easily-readable HTML format.
parameters
* thing1 any javascript type
* thing2 any javascript type
* etc ...
printp(thing1, thing2, etc)
Like print(...), but prints its arguments inside an HTML p (paragraph) tag.
parameters
* thing1 any javascript type
* thing2 any javascript type
* etc ...
printf(formatString, arg1, arg2, arg3)
Prints a string with any number of variables substituted in, as popularized by C's function of the same name. Some common substitutions:
  • %d - an integer
  • %f - a floating-point number
  • %b - a boolean
  • %s - a string

Each time one of these "slot" appears in your format string, the next argument is displayed according to the type of slot you specified.

AppJet supports Java's specification of printf, which has a ton of features, including selecting arguments out of order, formatting dates and times, and specifying how many characters wide each slot should be.

parameters
string formatString
* arg1
* arg2
* arg3 ...
examples
var x = 5;
printf("an integer: %d", x);
printf("Two strings: [%s] and [%s].", "string one", "string two");
sprintf(formatString, arg1, arg2, arg3)
Just like printf, but returns the string instead of printing it.
parameters
string formatString
* arg1
* arg2
* arg3 ...
examples
var result = sprintf("%f", Math.sqrt(2));
print("The square root of two, as a string, is: ", result);
supplant(data, str)
Replaces keys of data found in string with their corresponding values.

(Inspired by http://javascript.crockford.com/remedial.html)

parameters
object data dictionary of values
string str
returns
string str with keys of data replaced by their values
examples
var data = {name: "Aaron", age: 25, today: new Date()};
print(supplant(data, """

{name}'s age is {age} years, as of {today}.

"""));
html(text)
Used for printing un-escaped HTML, such as your own HTML tags.

Normally, printing a string will cause it to be translated so that it appears the same on the screen as it did in your code. If you're writing your own HTML, you don't want it to be processed this way. Wrapping a string in html(...) by-passes normal printing behavior, so that print(html(" -- html goes here ---")) will write the HTML directly to the page.

If you want to make use of print(...)'s machinery for translating things into HTML, you can call toHTML(...) on an object and use the result in your raw code.

parameters
string text the raw text
returns
object an object which, when printed, prints the raw html text
examples
print(html("""
<br />
<br />
<div><p>Here is some text inside a P inside a DIV.</p>
</div>
<br />
"""));
raw(text)

The raw() function is deprecated. Now use the html() function instead. (It does the same thing).

parameters
text
toHTML(x)
This function is used by print(...) to convert a string or object into nice-looking printable HTML. It may be useful in conjunction with raw(...) if you wish to work directly with HTML.

You can control how toHTML(...) (and therefore print(...)) behave on an object by giving that object a .toHTML() function.

parameters
* x any javascript variable
returns
string html-formatted string
link(url, optionalText)
Helper function for printing a link (A HREF tag).
parameters
string url an absolute or relative URL to link to
string optionalText? the text of the link, defaults to the url if absent
examples
print(link("http://appjet.com"));
image(url)
Helper function for printing an image (an IMG tag).
parameters
string url an absolute or relative URL to an image.
examples
print(image("http://i29.tinypic.com/vfwc60.gif"));
Generated by JsDoc Toolkit 1.3.3 on Thu, 03 Jul 2008 01:27:43 GMT.