123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- Smalltalk current createPackage: 'Trapped-Frontend' properties: #{}!
- Widget subclass: #TrappedDumbView
- instanceVariableNames: ''
- package: 'Trapped-Frontend'!
- !TrappedDumbView commentStamp!
- I just read and show an actual path.!
- !TrappedDumbView methodsFor: 'rendering'!
- renderOn: html
- html root trapShow: #()
- ! !
- Object subclass: #TrappedSingleton
- instanceVariableNames: ''
- package: 'Trapped-Frontend'!
- !TrappedSingleton methodsFor: 'action'!
- start
- ^ self subclassResponsibility
- ! !
- TrappedSingleton class instanceVariableNames: 'current'!
- !TrappedSingleton class methodsFor: 'accessing'!
- current
- ^ current ifNil: [ current := self new ]
- ! !
- !TrappedSingleton class methodsFor: 'action'!
- start
- self current start
- ! !
- TrappedSingleton subclass: #Trapped
- instanceVariableNames: 'registry'
- package: 'Trapped-Frontend'!
- !Trapped methodsFor: 'accessing'!
- byName: aString
- ^ registry at: aString
- !
- register: aFly name: aString
- registry at: aString put: aFly
- ! !
- !Trapped methodsFor: 'action'!
- start
- '[data-trap]' asJQuery each: [ :index :elem |
- | trap jq viewName modelName tokens path |
- jq := elem asJQuery.
- trap := jq attr: 'data-trap'.
- tokens := trap tokenize: ':'.
- tokens size = 1 ifTrue: [ tokens := { 'TrappedDumbView' }, tokens ].
- viewName := tokens first.
- tokens := (tokens second tokenize: ' ') select: [ :each | each notEmpty ].
- modelName := tokens first.
- path := Trapped parse: tokens allButFirst.
- { modelName }, path trapDescend: [(Smalltalk current at: viewName) new appendToJQuery: jq].
- ]
- ! !
- !Trapped methodsFor: 'initialization'!
- initialize
- super initialize.
- registry := #{}.
- ! !
- !Trapped class methodsFor: 'accessing'!
- parse: anArray
- ^anArray collect: [ :each |
- | asNum |
- <asNum = parseInt(each)>.
- asNum = asNum ifTrue: [ asNum ] ifFalse: [
- each first = '#' ifTrue: [ each allButFirst asSymbol ] ifFalse: [ each ]]]
- !
- path
- ^TrappedPathStack current elements
- ! !
- TrappedSingleton subclass: #TrappedPathStack
- instanceVariableNames: 'elements'
- package: 'Trapped-Frontend'!
- !TrappedPathStack methodsFor: 'accessing'!
- elements
- ^elements
- ! !
- !TrappedPathStack methodsFor: 'descending'!
- append: anArray
- elements := elements, anArray
- !
- with: anArray do: aBlock
- | old |
- old := elements.
- [ self append: anArray.
- aBlock value ] ensure: [ elements := old ]
- ! !
- !TrappedPathStack methodsFor: 'initialization'!
- initialize
- elements := #().
- ! !
- !Array methodsFor: '*Trapped-Frontend'!
- trapDescend: aBlock
- TrappedPathStack current with: self do: aBlock
- ! !
- !Array methodsFor: '*Trapped-Frontend'!
- trapDescend: aBlock
- TrappedPathStack current with: self do: aBlock
- ! !
- !TagBrush methodsFor: '*Trapped-Frontend'!
- trap: path read: aBlock
- path trapDescend: [ | actual model |
- actual := Trapped path.
- model := Trapped current byName: actual first.
- model watch: actual allButFirst do: [ :data |
- aBlock value: self value: data
- ]
- ]
- !
- trapShow: path
- self trap: path read: [ :brush :model | brush empty; with: model ]
- ! !
|