. .


ST 4U 130: Using File Libraries

September 9, 2011 9:58:00.850

Today's Smalltalk 4 You continues the VA Smalltalk Seaside tutorial with File Libraries - a simple way to use external resources by including them in the image. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

File Library.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

In this section we'll make use of a File Library - something that allows you to use external resources (images, CSS, etc), while at the same time allowing you to keep everything contained within the image. You probably don't want to deploy that way; tools like Apache serve files quite well. It can be handy when you are in testing mode though, since it allows you to hand one file (plus the VM, of course) to someone else.

To start with, create a subclass of FileLibrary in our Application:

WAFileLibrary subclass: #BlogFileLibrary
  instanceVariableNames: ''
  classVariableNames: ''
  poolDictionaries: ''

Now we need to run some workspace code to import the file resources into the image (as methods in this class):

BlogFileLibrary addAllFilesIn: 'images'

Make sure that the path you give that (relative or full) points to the directory you want it to; it will import everything in there as a ByteArray. You'll end up with one method per file - if the file was called "why.png", then the method will be "whyPng".

Now, add BlogFileLibrary to your application's configuration - the same way you added Javascript libraries in this tutorial. The new class will appear in the list as a library.

Finally, go back to BlogServerView, and change the url reference line to:

html image url: BlogFileLibrary / #whyPng.

You can use any file library element that you have imported the same way. Now, let's ensure that the image shows up as it did before:


Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , , ,

[st4u130-iPhone.m4v ( Size: 3994088 )]

posted by James Robertson

 Share Tweet This