image

RubyFrontier Documentation

Images and IMG Tags

On this page, I talk about how to do images in your Web pages. Images involve macros, and I haven’t formally discussed macros yet, but you don’t actually need to understand the details of macros in order to do images, and users are naturally anxious to start using images right away; hence this independent discussion.

Image Basics

To generate references to images within the site, you do two things, as follows:

  1. First, you have to have an image file. Place it in an #images folder in your source folder, in a location such that it will be found when the page table is built. (Personally, I usually just keep all images in a single top-level #images folder.)

  2. Second, in the page body or template, use the imageref() call in a macro. For example, you might say this:

    <%= imageref("myimage") %>
    

    If the image file’s simple name (without the extension) is myimage (for instance, it might be myimage.png), it will be located (in the #images folder) and copied out into the Web site folder. The macro call then returns an <img> tag whose src attribute is a relative URL from the page being built to the image file. The <img> tag will also have a height, width, and alt attribute.

All image files copied out in this way are placed, by default, in a folder at the top level of the Web site called images. To use a folder by a different name, set the value of the :imagefoldername scalar directive. There is no provision, at present, for writing out image files to any location other than a folder at the top level of the Web site (even though Frontier had the ability to do this).

Optional IMG Tag Attributes

An optional second parameter in the imageref() call is a hash of names and values that you can use to set additional attributes of the <img> tag that will be generated. You may supply as many as you like of the following:

So, for example, an imageref() call that includes some of these optional values might look like this:

    <%= imageref("myimage", {:border => "1", :alt => "A great image"}) %>
Next: Outline Renderers

This documentation prepared by Matt Neuburg, phd = matt at tidbits dot com (http://www.tidbits.com/matt/), using RubyFrontier.