Trapped-Frontend.st 2.5 KB

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