Trapped-Frontend.st 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 jq viewName modelName tokens model view |
  32. jq := elem asJQuery.
  33. trap := jq attr: 'data-trap'.
  34. tokens := trap tokenize: ':'.
  35. viewName := tokens first.
  36. modelName := tokens second.
  37. model := Trapped current byName: modelName.
  38. "TODO do something with model"
  39. (Smalltalk current at: viewName) new appendToJQuery: jq.
  40. ]
  41. ! !
  42. !Trapped methodsFor: 'initialization'!
  43. initialize
  44. super 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. Widget subclass: #TrappedView
  58. instanceVariableNames: ''
  59. package: 'Trapped-Frontend'!
  60. !TrappedView methodsFor: 'rendering'!
  61. renderOn: html
  62. html root empty.
  63. html with: self class name, ': contents'
  64. ! !