Dynamic Web Development with Seaside

17.3.1Creating a File Library

Setting up a file library is easy. Here are the steps you need to follow.

  1. Put your static files in a directory. The location of the directory is not significant. From within the directory, the files can reference each other using their file names.
  2. Create a file library by subclassing WAFileLibrary. For the rest of this text we assume its name is MyFileLibrary.
  3. Add files to your file library. There are three ways to add files to your file library:
    • Programmatically.
    • Via the web interface.
    • By editing your MyFileLibrary directly in your image.

Adding files programmatically. You can add files programmatically by using the class side methods addAllFilesIn: and addFileAt: in MyFileLibrary. For example:

MyFileLibrary addAllFilesIn: '/path/to/directory'
MyFileLibrary addFileAt: '/path/to/background.png'

Adding files via the config interface. Open the config application at http://localhost:8080/config and click the “configure” link for file libraries as shown in Figure 121. This will show which file libraries are available.

Configuring file libraries through the web  interface: clicking on files - configure

Click the configure link for MyFileLibrary as shown in Figure 121 right.

File libraries

There you can add a file by uploading it (select the file, then click the Add button as shown by Figure 122).

 Adding file to MyLibrary

When you add a file to a file library, Seaside creates a method with the file contents. If you find that there is an unusually long wait after pressing the Add button, make sure that the system (Squeak/Pharo) isn’t waiting for you to type your initials to confirm that you want to create a new method.

Adding a file by editing the class. File libraries are just objects and “files” in the file library are just methods so you can always add and modify FileLibrary entries using your normal class browser but be sure to follow the method naming convention mentioned above. You’ll probably find it pretty inconvenient to edit images within the browser though.

Adding a file to a file library either programmatically or using the configuration interface defines a corresponding method in the file library class, with the file name determining the name of the method. The dot is removed and the first letter of the suffix is capitalized. For example, the file main.css becomes the method MyFileLibrary>>mainCss. This puts certain limitations on the allowed file names. For example, the main part of the file name may not be all digits.

Once your files have been imported into the file library they are maintained independently from the files on your computer’s file system. If you modify your files you will have to re-add them to the file library.

Once your files are stored in a FileLibrary they will be available to be served through Seaside.

Copyright © 21 April 2024 Stéphane Ducasse, Lukas Renggli, C. David Shaffer, Rick Zaccone
This book is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 license.

This book is published using Seaside, Magritte and the Pier book publishing engine.