Introduction

First off, this document is for the advanced characters. A working knowledge of python is required, as well as a cursory knowledge of iPhoto and WebExport. You should probably read the user's guide as well as the developer's guide.

Starting off, there are three phases to a WebExport: preflight, export, postflight. Preflight sets up the export directory for export. It copies in the template folder's contents, saves the attributes.kvf, properties.kvf and metadata.tdf files. Then the export phase comes in, uses whatever information given to it by the three files, and creates a bunch of HTML files. Then, it uses sys.stdout to relay image creation information to iPhoto. This looks like the example to the right.

The Export Process and Creating Images

exporter.py (std-out)

index width height style destination
0 200 150 fill images/thumb/image1.jpg
0 400 300 nice images/med/image1.jpg
0 0 0 nice images/full/image1.jpg
1 200 150 fill images/thumb/image1.jpg
1 400 300 nice images/med/image1.jpg
1 0 0 nice images/full/image1.jpg

The gray line on top is not in the actual output and is here merely for help identifying columns. The first three columns are easy, first is the index of the image starting at zero (0). Next is the target width and height. How to get there depends on if you have selected nice (default) or fill. nice makes the image (maintaining aspect and without clipping) as big as it can without overflowing the bounds (you can access the size of the produced image with the width(twidth,theight) and height(twidth,theight) commands). fill on the other hand, fits as much of the image as it can into the given rectangle, but will fill every pixel of the target area. This option is the fourth option of the image() function. The last column, the path, is simply the destination file relative to destination directory. It can include "../" paths.

The Beautiful Backend

The backend of WebExport, exporter.py, is a very clean and concise python document located here. You can check it out at your leasure, and feel free to come up with clever ways of using it. If you run it on its own, it does close to nothing. It loads various libraries, reads in the supporting files that are provided at preflight, and then returns. This is because it executes its arguments as commands evaluated by exec() For more information about exec() and eval() check out the python documentation.

Info.plist

The Info.plist

Basically exec() simply executes the given code, and eval() returns the value of what it executes. If not supplied with an Info.plist, WebExport executes the gen_galleries() command, which is generally what you want to do. If you want to only have a certain number of photos per gallery, pass in that number, like this: gen_galleries(10). If it does have an Info.plist, it runs every value in an array named "process" as a command. It does not have to be something boring like gen_galleries, you can also link to other files, process arbitrary files, and more! You can also put a similar array called "postprocess" in the Info.plist, which will execute after the images are created.

Backend Variables and Accessors

Backend Variables

type name description
bool is_photo On a photo or gallery
str title Image/Gallery Title
str _title Gallery title
str file Photo Filename
str author Image/Gallery Author
str _author Gallery author
str keywords Image keywords
str comment Image/gallery comment
str _comment Gallery comment
str rating 0-5 star photo rating
int p_index Current photo index
int p_count Total photo count
int g_index Current gallery index
range g_prange Range of photos associated with this gallery
int g_count Total gallery count
str gallery Always links to current gallery

You already know about many of these variables, like title. There are more variables like this, and they are enumerated here. These are accessible directly from anywhere. You can access any metadata by using the metadata(name,index) function, which takes the name of the column, and optionally the index of the photo you want to pull it from. To access site-wide attributes, you use the attribute(name) function, which only takes one argument. To access template properties, simply use property(name). These functions respond differently do bad things, like the lack of metadata, but for more information, check the exporter code out.

Conditionals

closeup.html

...
<if "has_next()">
<a href="<?next()?>">next</a><br/>
<else/>
next
</if>
<if "has_prev()">
<a href="<?prev()?>">prev</a><br/>
<else/>
prev
</if>
...

Conditionals are a very powerful tool, that allow you to execute all kinds of new functionality. In the developer's guide we talked about the how to link between closeup pages. Well, check this out:

Looking at <if "has_next()">, it seems like an HTML tag, but there is no such tag, so I've co-opted it for WebExport conditionals. Basically if the code, in this case has_next(), evaluates true, it processes the blocked-off code between <if> and </if>. You can also insert an <else/> which separates another chunk of code to be executed only if the conditional evaluates false. You could also pull some fancier tricks, like seeing if p_index is even or odd...

Some Useful Commands

These commands are accessible from anywhere in any python block in your template. They are also accessible in any process/postprocess commands in the Info.plist.

attribute(key)
returns The value for the key, "!NOATTR!" if it does not exist.
key The key from the website attributes file/editor
date(format="%a, %d %b %Y %H:%M:%S",index):
returns The formatted date associated with the photo.
format Python-style date formatting string.
index Index of the photo to pull date info from, defaults to p_index.
deb(str):
returns Nothing.
str String to be logged to stderr (only in debug mode)
image(maxw,maxh,destination="",style="nice",index=p_index):
returns A relative URL to the file produced
maxw Target width of the result image.
maxh Target height of the result image.
destination Relative path to prefix the file with. Can be anything, including ../and other interesting combinations. If the last character is a / it will put the result in a directory, if it is not, it will prefix the filename.
style Either "fill", which fills the entire given space, or "nice" (default) which fits the image nicely into the given space.
index Index of the image you are creating, defaults to the current image.
link_page(dest,template):
returns Link to destination page.
dest Destination path (full URL).
source Template path for process().
log(str):
returns Nothing.
str String to be logged to stderr (for error use)
metadata(key,index):
returns The metadata value for the key, throws error if it does not exist.
key The metadata key, title, author, comment, etc. Can be customized.
index Index of the photo, defaults to p_index.
process(code):
returns code processed for conditionals, evals, and execs. Used to process every scrap of template. Safe for recursive use.
code Code to be processed.
processFile(dest,source):
returns Nothing.
dest Destination filepath
source Source filepath for process():
property(key):
returns The value for the key, logs to stderr if it does not exist.
key The key from the template's Info.plist file