PackageDescription: Seaside-Javascript


Seaside - Javascript

Last published: July 9, 2009 by 'jkott'

Defines 5 Classes
Extends 13 Classes


This package provides the capability to represent common Smalltalk objects as Javascript syntax to be sent to a web browser for execution / interpretation. It also provides DynamicCompiler parsers for Javascript and CSS. This package is a cut of the code in Scriptaculous for generating Javascript from Smalltalk objects.

Each object implements #asJavascriptOn: aStream which transforms the objects representation in to the javascript version, for example:

"Dictionary in to Javascript Hash"
| stream |
stream := String new writeStream.
Dictionary new
at: #boolean put: true;
at: #nil put: nil;
at: #string put: 'y';
at: #number put: 5;
at: #code put: 'this.value' js;
asJavascriptOn: stream.
stream contents

"OrderedCollection in to Javascript Array"
| stream |
stream := String new writeStream.
OrderedCollection new
add: 'y';
add: 5;
add: 'this.value' js;
asJavascriptOn: stream.
stream contents

"Javascript escaping"
| stream |
stream := String new writeStream.
'Test " quotes and '' single quotes' asJavascriptOn: stream.
stream contents

"Representing a string as javascript code so it isn't escaped"
| stream |
stream := String new writeStream.
'alert("hi")' js asJavascriptOn: stream.
stream contents

"Concatenating two scripts together - it adds the ; for you"
| stream |
stream := String new writeStream.
('alert("hi")' js, 'alert("and again")' js) asJavascriptOn: stream.
stream contents

"Building quick anonymous functions"
| stream |
stream := String new writeStream.
('(x, y)' jsFunction: 'return x + y') asJavascriptOn: stream.
stream contents