17.3.1Creating a File Library
Setting up a file library is easy. Here are the steps you need to follow.
- 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.
- Create a file library by subclassing
WAFileLibrary. For the rest of this text we assume its name is
- Add files to your file library. There are three ways to add files to your file library:
- Via the web interface.
- By editing your
MyFileLibrarydirectly in your image.
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.
Click the configure link for
MyFileLibrary as shown in Figure 121 right.
There you can add a file by uploading it (select the file, then click the Add button as shown by Figure 122).
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.