links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Last updated at 1:56 am UTC on 15 September 2017
Used in Seaside. Is superseeded by WAFileMetadataLibrary.

What does FileLibrary do

It allows to serve static files directly from seaside without the need for a standalone server like Apache or to configure Kom. These files can reference each other (say a CSS references an image) and can be distrubuted the same way as normal Smalltalk code (Monticello, SqueakMap, ...).

Each file in a file library is represented by a method. The method name is created from the file name, the dot is removed and the first letter of the suffix in capitalized. This puts certain limitations to the allowed filenames. Eg. 'main.css' becomes #mainCss.

Like Script- and StyleLibraries FileLibraries can be added to an application so that they automatically include themselves in the document root. Implement #selectorsToInclude and return the selectors you whish to be added to the document root.

How to create a FileLibrary

1. Programmatically with
MyFileLibrary class >> #addAllFilesIn: / #addFileNamed:
. For example
MyFileLibrary addAllFilesIn: '/path/to/directory/with/files'
MyFileLibrary addFileNamed: '/path/to/background.png'
2. Via the web interface. Go to your /seaside/config application and there click configure for your "Files". Click "configure" behind MyFileLibrary. There you can add a file by uploading it (select the file, then click "Add")

Note that a "Files" can consist of several file libraries and can even have tradional script or style libraries.

How to integrate a FileLibrary into your application

Files from a FileLibrary are ingetrated the same way other static files are integrated. They have a constant path that is '/seaside///' so for example '/seaside/files/MyFileLibrary/background.png'. These can be conveniently generated by 'MyFileLibrary / #aSelector' where #aSelector is the name of the method representing that file. For example 'MyFileLibrary / #backgroundPng'.

How to get back the files in a FileLibrary

The contents of a file library can be written out to disk. Writing out a file library first makes a folder with the name of the file library in the folder of your Smallatlk image. Then a file for each file in the file library is created in this folder. Writing out to disk can happen in three ways
1. MyFileLibrary default deployFiles
2. Via the configuration interface of the file library. On the same page where you can add files to your file library there is also a button 'write to disk' which will write out all the files in this library.
3. Via the configuration interface of your application. In the section where you can add libraries to your application there is a a button 'write to disk' which will write out all the libraries of this application.


The following code uses WAFileLibrary to add a CSS file to a page.

 updateRoot: anHtmlRoot
	super updateRoot: anHtmlRoot.
	anHtmlRoot stylesheet 
		url: WAFileLibraryDemo / #mainCss

The folllowing code uses WAFileLibrary to display an image.

 renderContentOn: html
	html image
		url: WAFileLibraryDemo / #mainJpg

Trouble Shooting:

Earlier versions would create methods without a time stamp. You can fix this by recompiling these methods by adapting the following code

 SUAllTestLibrary basicNew in: [ :library |
	#(demologoGif headerGif backgroundGif demoGif logoGif menuGif) do: [ :each |
		library class
			addFileNamed: (library asFilename: each)
			contents: (library perform: each) ] ]