Trapped-Frontend.st 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. Smalltalk current createPackage: 'Trapped-Frontend' properties: #{}!
  2. Object subclass: #TrappedSingleton
  3. instanceVariableNames: ''
  4. package: 'Trapped-Frontend'!
  5. !TrappedSingleton methodsFor: 'action'!
  6. start
  7. ^ self subclassResponsibility
  8. ! !
  9. TrappedSingleton class instanceVariableNames: 'current'!
  10. !TrappedSingleton class methodsFor: 'accessing'!
  11. current
  12. ^ current ifNil: [ current := self new ]
  13. ! !
  14. !TrappedSingleton class methodsFor: 'action'!
  15. start
  16. self current start
  17. ! !
  18. TrappedSingleton subclass: #Trapped
  19. instanceVariableNames: 'registry'
  20. package: 'Trapped-Frontend'!
  21. !Trapped methodsFor: 'accessing'!
  22. byName: aString
  23. ^ registry at: aString
  24. !
  25. register: aFly name: aString
  26. registry at: aString put: aFly
  27. ! !
  28. !Trapped methodsFor: 'action'!
  29. start
  30. '[data-trap]' asJQuery each: [ :index :elem |
  31. | trap viewName modelName tokens model view |
  32. trap := (jQuery value: elem) attr: 'data-trap'.
  33. tokens := trap tokenize: ':'.
  34. viewName := tokens first.
  35. modelName := tokens second.
  36. model := Trapped current byName: modelName.
  37. view := (Smalltalk current at: viewName) new
  38. startOn: elem;
  39. observe: model;
  40. yourself.
  41. ]
  42. ! !
  43. !Trapped methodsFor: 'initialization'!
  44. initialize
  45. registry := #{}.
  46. ! !
  47. TrappedSingleton subclass: #TrappedFly
  48. instanceVariableNames: ''
  49. package: 'Trapped-Frontend'!
  50. !TrappedFly methodsFor: 'action'!
  51. name
  52. ^ self class name
  53. !
  54. start
  55. Trapped current register: self name: self name
  56. ! !
  57. Object subclass: #TrappedView
  58. instanceVariableNames: ''
  59. package: 'Trapped-Frontend'!
  60. !TrappedView methodsFor: 'not yet classified'!
  61. observe: aFly
  62. !
  63. startOn: aHTMLElement
  64. (jQuery value: aHTMLElement) html: self class name, ': contents'
  65. ! !