[Seaside-dev] Re: [Seaside Commits] Seaside 2.9:
Seaside-FileSystem-lr.10.mcz
Julian Fitzell
jfitzell at gmail.com
Thu May 21 02:03:33 UTC 2009
This commit seems weird...?
On Wed, May 20, 2009 at 11:42 AM,
<squeak-dev-noreply at lists.squeakfoundation.org> wrote:
> Lukas Renggli uploaded a new version of Seaside-FileSystem to project Seaside 2.9:
> http://www.squeaksource.com/Seaside29/Seaside-FileSystem-lr.10.mcz
>
> ==================== Summary ====================
>
> Name: Seaside-FileSystem-lr.10
> Author: lr
> Time: 20 May 2009, 8:41:57 pm
> UUID: 66db219a-4325-4372-9701-baec6d271f76
> Ancestors: Seaside-FileSystem-lr.9
>
> - Added WARequestContext>>#respond: and use it whenever possible:
>
> self requestContext respond: [ :response |
> response
> contentType: WAMimeType textPlain;
> nextPutAll: 'Hello World' ]
>
> - This change reduces the code size (no temps need to be declared anymore) in most cases and simplifies request handling significantly. Credits go to Julian.
>
> ==================== Snapshot ====================
>
> SystemOrganization addCategory: #'Seaside-FileSystem'!
>
> WASystemConfiguration subclass: #WAExternalFileLibraryConfiguration
> instanceVariableNames: ''
> classVariableNames: ''
> poolDictionaries: ''
> category: 'Seaside-FileSystem'!
>
> ----- Method: WAExternalFileLibraryConfiguration>>describeOn: (in category 'attributes') -----
> describeOn: config
> (config string: #directory)
> label: 'Directory';
> comment: 'The base directory to serve files from.';
> default: (SpFilename named: 'xxxDoesNotExists') asAbsoluteFilename directory asString. "#asString on SPFilename"
> (config boolean: #listing)
> label: 'Allow Listing';
> comment: 'Enable listing of directory entries.';
> default: false!
>
> ----- Method: WAPackage class>>seasideFileSystem (in category '*seaside-filesystem') -----
> seasideFileSystem
> ^ self new
> name: 'Seaside-FileSystem';
> description: 'File library that serves files from external directory.';
> addDependency: 'Seaside-Core';
> yourself!
>
> WAEntryPoint subclass: #WAExternalFileLibrary
> instanceVariableNames: ''
> classVariableNames: ''
> poolDictionaries: ''
> category: 'Seaside-FileSystem'!
>
> ----- Method: WAExternalFileLibrary class>>description (in category 'accessing') -----
> description
> ^ 'File Directory'!
>
> ----- Method: WAExternalFileLibrary>>asAbsoluteUrl:relativeTo: (in category 'private') -----
> asAbsoluteUrl: aFileName relativeTo: aRequest
> ^aRequest url copy
> addToPath: aFileName;
> yourself!
>
> ----- Method: WAExternalFileLibrary>>contentsOfFile: (in category 'private') -----
> contentsOfFile: aFilename
> | stream |
> stream := aFilename readStream.
> ^[
> stream binary.
> stream upToEnd ]
> ensure: [ stream close ]!
>
> ----- Method: WAExternalFileLibrary>>defaultConfiguration (in category 'configuration') -----
> defaultConfiguration
> ^ super defaultConfiguration
> addParent: WAExternalFileLibraryConfiguration instance;
> yourself!
>
> ----- Method: WAExternalFileLibrary>>directory (in category 'accessing') -----
> directory
> | path filename |
> path := self preferenceAt: #directory.
> filename := SpFilename named: path.
> "hack around SPort bugs"
> ^(path last = filename separator)
> ifTrue: [ SpFilename named: path allButLast ]
> ifFalse: [ filename ]!
>
> ----- Method: WAExternalFileLibrary>>filenameForRequest: (in category 'private') -----
> filenameForRequest: aRequest
> | filename basePathUrl |
> filename := self directory.
> basePathUrl := WAUrl new parsePath: self basePath; yourself.
> (basePathUrl relativeTo: aRequest url) do: [ :each |
> filename := filename construct: each ].
> ^filename!
>
> ----- Method: WAExternalFileLibrary>>filesIn:do: (in category 'private') -----
> filesIn: aPath do: aOneArgumentBlock
> "this can not be done with SPort"
> (WAPlatform current filesIn: aPath) do: [ :each |
> aOneArgumentBlock value: (WAPlatform current localNameOf: each) ]!
>
> ----- Method: WAExternalFileLibrary>>handleFiltered: (in category 'handling') -----
> handleFiltered: aRequestContext
> [ self processContext: aRequestContext ]
> on: Error
> do: [ :error |
> aRequestContext responseGenerator
> internalError: error;
> respond ]!
>
> ----- Method: WAExternalFileLibrary>>listing (in category 'accessing') -----
> listing
> ^ self preferenceAt: #listing!
>
> ----- Method: WAExternalFileLibrary>>mimetypeForRequest: (in category 'private') -----
> mimetypeForRequest: aRequest
> | path |
> path := aRequest url path.
> ^(path isEmpty or: [ (path last includes: $.) not ])
> ifTrue: [ WAFileLibrary defaultMimeType seasideMimeType ]
> ifFalse: [
> | extension |
> extension := path last copyAfterLast: $..
> WAFileLibrary mimetypeFor: extension ]!
>
> ----- Method: WAExternalFileLibrary>>processContext: (in category 'handling') -----
> processContext: aRequestContext
> | filename |
> filename := self filenameForRequest: aRequestContext request.
> (self listing and: [ filename isDirectory ])
> ifTrue: [ self
> processDirectory: filename asString "#asString on SPFilename"
> context: aRequestContext ]
> ifFalse: [ self processFile: filename context: aRequestContext ]!
>
> ----- Method: WAExternalFileLibrary>>processDirectory:context: (in category 'handling') -----
> processDirectory: aString context: aRequestContext
> | contents |
> contents := WARenderCanvas builder
> fullDocument: true;
> rootBlock: [ :html | html title: aRequestContext request url seasideString ];
> render: [ :html |
> html heading
> level: 1;
> with: aRequestContext request url.
> html unorderedList: [
> self filesIn: aString do: [ :each |
> html listItem: [
> html anchor
> url: (self asAbsoluteUrl: each relativeTo: aRequestContext request);
> with: each ] ] ] ].
> aRequestContext respond: [ :response |
> response
> contentType: WAMimeType textHtml;
> nextPutAll: contents ]!
>
> ----- Method: WAExternalFileLibrary>>processFile:context: (in category 'handling') -----
> processFile: aFilename context: aRequestContext
> aRequestContext respond: [ :response |
> response
> document: (self contentsOfFile: aFilename)
> mimeType: (self mimetypeForRequest: aRequestContext request)
> fileName: (aRequestContext request url path last) ]!
>
>
> _______________________________________________
> commits mailing list
> To unsubscribe, email commits-leave at lists.seaside.st
> http://lists.seaside.st/listinfo/commits
>
More information about the seaside-dev
mailing list