Trapped-Frontend.st 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. super initialize.
  46. registry := #{}.
  47. ! !
  48. TrappedSingleton subclass: #TrappedFly
  49. instanceVariableNames: ''
  50. package: 'Trapped-Frontend'!
  51. !TrappedFly methodsFor: 'action'!
  52. name
  53. ^ self class name
  54. !
  55. start
  56. Trapped current register: self name: self name
  57. ! !
  58. Widget subclass: #TrappedView
  59. instanceVariableNames: ''
  60. package: 'Trapped-Frontend'!
  61. !TrappedView methodsFor: 'initializing'!
  62. observe: aFly
  63. !
  64. startOn: aHTMLElement
  65. | el |
  66. el := jQuery value: aHTMLElement.
  67. el empty.
  68. self appendToJQuery: el.
  69. ! !
  70. !TrappedView methodsFor: 'rendering'!
  71. renderOn: html
  72. html with: self class name, ': contents'
  73. ! !