1
0

name.st 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. Smalltalk createPackage: '{%= name %}'!
  2. (Smalltalk packageAt: '{%= name %}' ifAbsent: [ self error: 'Package not created: {%= name %}' ]) imports: {'amber/web/Web'. 'amber/web/Web-JQuery'. 'silk/Silk'}!
  3. Object subclass: #{%= name %}
  4. slots: {}
  5. package: '{%= name %}'!
  6. !{%= name %} methodsFor: 'action'!
  7. alert: aString after: aNumberOfMilliseconds
  8. [ Terminal alert: aString ] valueWithTimeout: aNumberOfMilliseconds
  9. !
  10. doAmberWith
  11. '#output-list' asBrush with: [ :html | html li: 'Amber Web #with: added me!!' ]
  12. !
  13. doConsoleLog
  14. | greeting target |
  15. greeting := 'Hello'.
  16. target := 'world'.
  17. console log: #{ #greeting -> greeting. #target -> target. #callback -> [ console log: greeting, ', ', target, '!!' ] }
  18. !
  19. doInspectStatus
  20. (self getApi: '/status')
  21. then: {#json. #inspect}
  22. catch: [ :err | Terminal alert: err ]
  23. !
  24. doJQueryAppend
  25. '#output-list' asJQuery append: '<li>jQuery append added me!!</li>'
  26. !
  27. doSilkTAG
  28. '#output-list' asSilk LI: 'Silk TAG: added me!!'
  29. ! !
  30. !{%= name %} methodsFor: 'backend'!
  31. endpoint
  32. "Return something like 'https://<char mess>.execute-api.eu-central-1.amazonaws.com/default'"
  33. ^ self error: 'Not yet implemented'
  34. !
  35. getApi: path
  36. ^ Platform fetch: self endpoint, path
  37. ! !
  38. !{%= name %} methodsFor: 'starting'!
  39. augmentPage
  40. '#lambda-status' asSilk on: #click bind: [ self doInspectStatus ].
  41. '#console-log' asSilk on: #click bind: [ self doConsoleLog ].
  42. '#timeout-alert' asSilk on: #click bind: [ self alert: 'REMINDER!!' after: 5000 ].
  43. '#amber-with' asBrush onClick: [ self doAmberWith ].
  44. '#silk-tag' asSilk on: #click bind: [ self doSilkTAG ].
  45. '#jquery-append' asJQuery click: [ self doJQueryAppend ]
  46. ! !
  47. !{%= name %} class methodsFor: 'starting'!
  48. start
  49. self new augmentPage
  50. ! !