Trapped-Frontend.st 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. Smalltalk current createPackage: 'Trapped-Frontend' properties: #{}!
  2. Widget subclass: #TrappedDumbView
  3. instanceVariableNames: ''
  4. package: 'Trapped-Frontend'!
  5. !TrappedDumbView commentStamp!
  6. I just read and show an actual path.!
  7. !TrappedDumbView methodsFor: 'rendering'!
  8. renderOn: html
  9. html root trapShow: #()
  10. ! !
  11. Object subclass: #TrappedSingleton
  12. instanceVariableNames: ''
  13. package: 'Trapped-Frontend'!
  14. !TrappedSingleton methodsFor: 'action'!
  15. start
  16. ^ self subclassResponsibility
  17. ! !
  18. TrappedSingleton class instanceVariableNames: 'current'!
  19. !TrappedSingleton class methodsFor: 'accessing'!
  20. current
  21. ^ current ifNil: [ current := self new ]
  22. ! !
  23. !TrappedSingleton class methodsFor: 'action'!
  24. start
  25. self current start
  26. ! !
  27. TrappedSingleton subclass: #Trapped
  28. instanceVariableNames: 'registry'
  29. package: 'Trapped-Frontend'!
  30. !Trapped methodsFor: 'accessing'!
  31. byName: aString
  32. ^ registry at: aString
  33. !
  34. register: aFly name: aString
  35. registry at: aString put: aFly
  36. ! !
  37. !Trapped methodsFor: 'action'!
  38. start
  39. '[data-trap]' asJQuery each: [ :index :elem |
  40. | trap jq viewName modelName tokens path |
  41. jq := elem asJQuery.
  42. trap := jq attr: 'data-trap'.
  43. tokens := trap tokenize: ':'.
  44. tokens size = 1 ifTrue: [ tokens := { 'TrappedDumbView' }, tokens ].
  45. viewName := tokens first.
  46. tokens := (tokens second tokenize: ' ') select: [ :each | each notEmpty ].
  47. modelName := tokens first.
  48. path := Trapped parse: tokens allButFirst.
  49. { modelName }, path trapDescend: [(Smalltalk current at: viewName) new appendToJQuery: jq].
  50. ]
  51. ! !
  52. !Trapped methodsFor: 'initialization'!
  53. initialize
  54. super initialize.
  55. registry := #{}.
  56. ! !
  57. !Trapped class methodsFor: 'accessing'!
  58. parse: anArray
  59. ^anArray collect: [ :each |
  60. | asNum |
  61. <asNum = parseInt(each)>.
  62. asNum = asNum ifTrue: [ asNum ] ifFalse: [
  63. each first = '#' ifTrue: [ each allButFirst asSymbol ] ifFalse: [ each ]]]
  64. !
  65. path
  66. ^TrappedPathStack current elements
  67. ! !
  68. TrappedSingleton subclass: #TrappedPathStack
  69. instanceVariableNames: 'elements'
  70. package: 'Trapped-Frontend'!
  71. !TrappedPathStack methodsFor: 'accessing'!
  72. elements
  73. ^elements
  74. ! !
  75. !TrappedPathStack methodsFor: 'descending'!
  76. append: anArray
  77. elements := elements, anArray
  78. !
  79. with: anArray do: aBlock
  80. | old |
  81. old := elements.
  82. [ self append: anArray.
  83. aBlock value ] ensure: [ elements := old ]
  84. ! !
  85. !TrappedPathStack methodsFor: 'initialization'!
  86. initialize
  87. elements := #().
  88. ! !
  89. !Array methodsFor: '*Trapped-Frontend'!
  90. trapDescend: aBlock
  91. TrappedPathStack current with: self do: aBlock
  92. ! !
  93. !Array methodsFor: '*Trapped-Frontend'!
  94. trapDescend: aBlock
  95. TrappedPathStack current with: self do: aBlock
  96. ! !
  97. !TagBrush methodsFor: '*Trapped-Frontend'!
  98. trap: path read: aBlock
  99. path trapDescend: [ | actual model |
  100. actual := Trapped path.
  101. model := Trapped current byName: actual first.
  102. model watch: actual allButFirst do: [ :data |
  103. aBlock value: self value: data
  104. ]
  105. ]
  106. !
  107. trapShow: path
  108. self trap: path read: [ :brush :model | brush empty; with: model ]
  109. ! !