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.

Every #images folder containing an image file that is actually referred to by an imageref() call results in a folder in the Web site at the same relative location, called images, and the image file is copied into this folder. Thus you can have many images folders throughout your site, though the simplest and most common situation is probably to have a single #images folder at the top level of your source folder, where all pages can see it, and thus a single images folder in the rendered site.

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"}) %>

Images Without imageref()

All of the above presumes that you’re calling imageref() to generate an <img> tag. But there are circumstances where you want to refer to an image within your site, without using an <img> tag. For example, you might do this from a JavaScript or CSS file.

In this case, you’re going to need to use some other strategy to get the image copied from the source folder into the Web site folder. There are two main strategies:

Next: Outline Renderers

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