Smalltalk createPackage: 'Silk'!
Domite subclass: #Silk
instanceVariableNames: ''
package: 'Silk'!
!Silk commentStamp!
I am adding convenience APIs to my subclass, `Domite`.
##Rendering
- `aSilk << anObject` uses double-dispatch via `renderOnSilk:`. This allows creating widgets (no formal superclass, anything with `renderOnSilk:` is a widget), as well as incorporating blocks: `aSilk << aBlock` runs the block, passing aSilk as a parameter.
##Convenience
- `aCssSelectorString asSilk` returns Silk wrapping an element at a selector.
- `anObject inSilk` returns anObject rendered in a document fragment.
##Element creation
These messages use DNU to dynamically create
elements with any (letters-and-numbers) tag name,
Next samples show this on an example of `
`.
- `Silk DIV` is shortcut for `Silk newElement: 'div'`.!
!Silk methodsFor: 'writing'!
nextPut: anObject
"Double-dispatches anObject via renderOnSilk: message.
If a message returns nil, this fallbacks to superclass.
Otherwise, it is assumed renderOnSilk: did its job."
(anObject renderOnSilk: self)
ifNil: [ super nextPut: anObject ]
! !
!Silk class methodsFor: 'message handling'!
doesNotUnderstand: aMessage
"`Silk DIV` creates a div element"
| selector |
selector := aMessage selector.
selector asUppercase = selector
ifFalse: [ ^ super doesNotUnderstand: aMessage ].
(selector includes: ':')
ifTrue: [ ^ super doesNotUnderstand: aMessage ].
^ self newElement: selector asLowercase
! !
!BlockClosure methodsFor: '*Silk'!
renderOnSilk: aSilk
self value: aSilk
! !
!CharacterArray methodsFor: '*Silk'!
asSilk
^ Silk at: self asString
! !
!JSObjectProxy methodsFor: '*Silk'!
inSilk
^ Silk newStream << self; yourself
! !
!Object methodsFor: '*Silk'!
inSilk
^ Silk newStream << self; yourself
!
renderOnSilk: aSilk
^ nil
! !