Documentation.st 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. Smalltalk current createPackage: 'Documentation' properties: #{}!
  2. Object subclass: #DocumentationBuilder
  3. instanceVariableNames: 'chapters announcer widget'
  4. category: 'Documentation'!
  5. !DocumentationBuilder methodsFor: 'accessing'!
  6. chapters
  7. ^chapters ifNil: [chapters := self buildChapters]
  8. !
  9. announcer
  10. ^announcer ifNil: [announcer := Announcer new]
  11. !
  12. widget
  13. ^widget ifNil: [widget := DocumentationWidget on: self]
  14. ! !
  15. !DocumentationBuilder methodsFor: 'building'!
  16. buildChapters
  17. ^((self class methodDictionary values sorted: [:a :b | a selector < b selector])
  18. select: [:each | each category = 'chapters'])
  19. collect: [:each | self perform: each selector]
  20. !
  21. buildOn: aCanvas
  22. aCanvas with: self widget.
  23. self
  24. checkHashChange;
  25. checkHash
  26. !
  27. buildOnJQuery: aJQuery
  28. self buildOn: (HTMLCanvas onJQuery: aJQuery)
  29. !
  30. build
  31. self buildOnJQuery: ('body' asJQuery)
  32. ! !
  33. !DocumentationBuilder methodsFor: 'chapters'!
  34. ch1introduction
  35. ^DocChapter new
  36. title: 'Introduction';
  37. contents: '
  38. ##Amber Smalltalk in a nutshell.
  39. Amber is an implementation of the Smalltalk-80 language.
  40. It allows developers to write client-side heavy web applications in Smalltalk. Amber includes an integrated development environment with a class browser, workspace and transcript.
  41. Amber includes the following features:
  42. - It is semantically and syntactically equivalent to Pharo Smalltalk (the implementation considered as the reference)
  43. - It is written in itself and compiles into efficient JavaScript
  44. - A canvas API similar to Seaside to generate HTML
  45. - A jQuery binding.
  46. ## Disclaimer
  47. This documentation doesn''t aim to teach Smalltalk.
  48. Knowledge of Smalltalk is needed to understand the topics covered in this documentation.
  49. If you want to learn the Smalltalk language, you can read the excellent [Pharo By Example](http://www.pharobyexample.org) book.
  50. '
  51. !
  52. ch2differencesWithOtherSmalltalks
  53. ^DocChapter new
  54. title: 'Differences with other Smalltalks';
  55. contents: '
  56. Amber has some differences with other Smalltalk implementations.
  57. Because it maps Smalltalk constructs one-to-one with the JavaScript equivalent, including Smalltalk classes to JavaScript constructors, the core class library is simplified compared to Pharo Smalltalk.
  58. The following list explains the main differences:
  59. - The collection class hierarchy is simpler compared to most Smalltalk implementations. As of today, there is no SortedCollection. The size of arrays is dynamic, and they behave like an ordered collection.
  60. They can also be sorted with the #sort* methods.
  61. - The Date class behaves like the Date and TimeStamp classes in Pharo Smalltalk. Therefore both Date today and Date now are valid in Amber.
  62. '
  63. !
  64. ch3GettingStarted
  65. ^DocChapter new
  66. title: 'Getting started';
  67. contents: '
  68. To get started hacking in Amber you can basically take three routes, independent of your platform:
  69. 1. Just try it out at http://www.amber-lang.net (click the "Class browser" button) - but you will **not be able to save any code you write**!!
  70. Still, it works fine for looking at the IDE and playing around. Just don''t press F5/reload - it will bring you back to zero.
  71. (Well, if you still want to develop and save code online someone has set up this site seems for free use: https://www.screwtopdb.com/amberstore/topics?name=amberstore/amber.html )
  72. 2. Download an Amber zip-ball, install Nodejs, fire up the Amber server and then open Amber from localhost - then you **can save code**. Detailed instructions are below!!
  73. 3. Same as above but install git first and get a proper clone from http://github.com/NicolasPetton/amber instead of a zip/tar-ball.
  74. If you want to **contribute to Amber itself** this is really what you want to do. It requires installing git first, but it is quite simple - although we leave this bit as an "exercise to the reader" :)
  75. **PLEASE NOTE:** Amber core developers use Linux.
  76. We do not want to introduce dependencies that aren''t cross platform - but currently amberc (the command line compiler) is a bash script and we also use Makefiles
  77. (for building Amber itself and server side examples) written on Linux/Unix. So using Windows is currently a bit limited - you can''t run "make" in the .st directory to rebuild whole of Amber for example.
  78. BUT... if you only want to use Amber to build web client apps and not really get involved in hacking Amber itself - then you should be fine!!
  79. ## Downloading Amber
  80. Currently you can download in zip or tar-ball format, either cutting edge or a release. [Downloads are available here](https://github.com/NicolasPetton/amber/archives/amber).
  81. At the moment of writing you have release [0.9 as zip](https://github.com/NicolasPetton/amber/zipball/0.9) or [tar](https://github.com/NicolasPetton/amber/tarball/0.9),
  82. or [cutting edge as zip](https://github.com/NicolasPetton/amber/zipball/amber) or [tar](https://github.com/NicolasPetton/amber/tarball/amber).
  83. At the moment this is just a **1.5Mb download**, so its very small. Unpack wherever you like, but I would rename the directory that is unpacked to something slightly shorter - like say "amber-0.9" or just "amber".
  84. And yes, at this point you can double click the index.html file in the amber directory to get the IDE up, but again, **you will not be able to save code**. So please continue below :)
  85. ## Installing Node.js
  86. [Node](http://www.nodejs.org) (for short) is simply the V8 Javascript VM from Google (used in Chrome) hooked together with some hard core C-libraries for doing "evented I/O".
  87. Basically it''s Javascript for the server - on asynch steroids. Amber runs fine in Node and we use it for several Amber tools, like amberc (the command line Amber compiler) or the Amber server (see below).
  88. There are also several Amber-Node example to look at if you want to play with running Amber programs server side. **In short - you really want to install Nodejs. :)**
  89. - Installing Node on Linux can be done using your package tool of choice ("apt-get install nodejs" for example) or any other way described at [the download page](http://nodejs.org/#download).
  90. - Installing Node on MacOS seems to be easiest by getting it from [here](https://sites.google.com/site/nodejsmacosx/).
  91. - Installing Node on Windows is probably done best by using the [download from Nodejs.org](http://nodejs.org/#download). This is not an installer, it is instead simply the node executable - **node.exe**.
  92. - Put node.exe somewhere in your path. In Windows7 I can run a command prompt "As administrator" (right click the command prompt in Start menu) and then just "copy node.exe c:\windows\" or such.
  93. ## Starting Amber server
  94. Nicolas has written a minimal webDAV server that is the easiest way to get up and running Amber with the ability to save code. This little server is written in... Amber!!
  95. And it runs on top of Node. So to start it up serving your brand new directory tree of sweet Amber you do:
  96. cd amber (or whatever you called the directory you unpackaged)
  97. ./bin/server (in windows you type "node server\server.js" instead)
  98. It should say it is listening on port 4000. If it does, hooray!! That means both Node and Amber are good. In Windows you might get a question about opening that port in the local firewall - yep, do it!!
  99. ## Firing up Amber
  100. The Amber IDE is written in... Amber. It uses JQuery and runs right in your browser as a ... well, a web page.
  101. We could open it up just using a file url - but the reason we performed the previous steps is so that we can load the IDE web page from a server that can handle PUTs (webDAV) of source code.
  102. According to web security Amber can only do PUT back to the same server it was loaded from. Thus we instead want to open it through our little server now listening on port 4000:
  103. http://localhost:4000/index.html
  104. Clicking the above link should get your Amber running.
  105. To verify that you can indeed commit - just select a Package in the browser, like say "Examples" and press "Commit package" button. **If all goes well nothing happens :)**.
  106. So in order to really know if it worked we can check the modified date on the files **amber/st/Examples.st**, **amber/js/Examples.js** and **amber/js/Examples.deploy.js** - they should be brand new.
  107. NOTE: We can use any webDAV server and Apache2 has been used earlier and works fine. But the Amber server is smaller and simpler to start.
  108. '
  109. !
  110. ch5Index
  111. ^ClassesIndexChapter new
  112. !
  113. ch6KernelObjects
  114. ^PackageDocChapter on: (Package named: 'Kernel-Objects')
  115. !
  116. ch7KernelClasses
  117. ^PackageDocChapter on: (Package named: 'Kernel-Classes')
  118. !
  119. ch4Tutorials
  120. ^TutorialsChapter new
  121. ! !
  122. !DocumentationBuilder methodsFor: 'routing'!
  123. checkHashChange
  124. (window jQuery: window) bind: 'hashchange' do: [self checkHash]
  125. !
  126. checkHash
  127. | hash presentation |
  128. hash := document location hash replace: '^#' with: ''.
  129. self announcer announce: (ChapterSelectionAnnouncement new
  130. id: hash;
  131. yourself)
  132. ! !
  133. !DocumentationBuilder methodsFor: 'updating'!
  134. update
  135. chapters := nil.
  136. announcer := nil.
  137. widget := nil.
  138. (window jQuery: '.documentation') remove.
  139. self build
  140. ! !
  141. DocumentationBuilder class instanceVariableNames: 'current'!
  142. !DocumentationBuilder class methodsFor: 'accessing'!
  143. current
  144. ^current ifNil: [current := self new]
  145. ! !
  146. !DocumentationBuilder class methodsFor: 'initialization'!
  147. initialize
  148. self current build
  149. ! !
  150. Widget subclass: #DocChapter
  151. instanceVariableNames: 'title contents parent'
  152. category: 'Documentation'!
  153. !DocChapter methodsFor: 'accessing'!
  154. title
  155. ^title ifNil: ['']
  156. !
  157. title: aString
  158. title := aString
  159. !
  160. contents
  161. ^contents ifNil: ['']
  162. !
  163. contents: aString
  164. contents := aString
  165. !
  166. htmlContents
  167. ^(Showdown at: #converter) new makeHtml: self contents
  168. !
  169. chapters
  170. "A doc chapter can contain sub chapters"
  171. ^#()
  172. !
  173. cssClass
  174. ^'doc_chapter'
  175. !
  176. level
  177. ^self parent ifNil: [1] ifNotNil: [self parent level +1]
  178. !
  179. level: anInteger
  180. level := anInteger
  181. !
  182. parent
  183. ^parent
  184. !
  185. parent: aChapter
  186. parent := aChapter
  187. !
  188. id
  189. "The id is used in url fragments.
  190. It must be unique amoung all chapters"
  191. ^self title replace: ' ' with: '-'
  192. !
  193. announcer
  194. ^DocumentationBuilder current announcer
  195. ! !
  196. !DocChapter methodsFor: 'actions'!
  197. selectClass: aClass
  198. DocumentationBuilder current announcer announce: (ClassSelectionAnnouncement on: aClass)
  199. !
  200. selectChapter: aChapter
  201. document location hash: aChapter id
  202. !
  203. displayChapter: aChapter
  204. DocumentationBuilder current widget displayChapter: aChapter
  205. ! !
  206. !DocChapter methodsFor: 'initialization'!
  207. initialize
  208. super initialize.
  209. self subscribe
  210. ! !
  211. !DocChapter methodsFor: 'rendering'!
  212. renderOn: html
  213. html div
  214. class: self cssClass;
  215. with: [
  216. self renderDocOn: html.
  217. self renderLinksOn: html]
  218. !
  219. renderDocOn: html
  220. | div |
  221. html h1 with: self title.
  222. self renderNavigationOn: html.
  223. div := html div class: 'contents'.
  224. div asJQuery html: self htmlContents
  225. !
  226. renderNavigationOn: html
  227. self parent ifNotNil: [
  228. html div
  229. class: 'navigation'; with: [
  230. html a
  231. with: '← back to ', self parent title;
  232. onClick: [self selectChapter: self parent]]]
  233. !
  234. renderLinksOn: html
  235. html ul
  236. class: 'links';
  237. with: [
  238. self chapters do: [:each |
  239. html li with: [
  240. html a
  241. with: each title;
  242. onClick: [self selectChapter: each]]]]
  243. ! !
  244. !DocChapter methodsFor: 'subscriptions'!
  245. subscribe
  246. self announcer on: ChapterSelectionAnnouncement do: [:ann |
  247. ann id = self id ifTrue: [self displayChapter: self]]
  248. ! !
  249. DocChapter subclass: #PackageDocChapter
  250. instanceVariableNames: 'package chapters'
  251. category: 'Documentation'!
  252. !PackageDocChapter methodsFor: 'accessing'!
  253. package
  254. ^package
  255. !
  256. title
  257. ^'Package ', self package name
  258. !
  259. chapters
  260. ^chapters
  261. !
  262. contents
  263. ^'Classes in package ', self package name, ':'
  264. ! !
  265. !PackageDocChapter methodsFor: 'initialization'!
  266. initializeWithPackage: aPackage
  267. package := aPackage.
  268. chapters := (aPackage classes sorted: [:a :b | a name < b name]) collect: [:each |
  269. (ClassDocChapter on: each)
  270. parent: self;
  271. yourself]
  272. ! !
  273. !PackageDocChapter class methodsFor: 'instance creation'!
  274. on: aPackage
  275. ^self basicNew
  276. initializeWithPackage: aPackage;
  277. initialize;
  278. yourself
  279. ! !
  280. DocChapter subclass: #ClassDocChapter
  281. instanceVariableNames: 'theClass'
  282. category: 'Documentation'!
  283. !ClassDocChapter methodsFor: 'accessing'!
  284. theClass
  285. ^theClass
  286. !
  287. contents
  288. ^self theClass comment isEmpty
  289. ifTrue: [self theClass name, ' is not documented yet.']
  290. ifFalse: [self theClass comment]
  291. !
  292. cssClass
  293. ^'doc_class ', super cssClass
  294. !
  295. title
  296. ^self theClass name
  297. !
  298. initializeWithClass: aClass
  299. theClass := aClass
  300. ! !
  301. !ClassDocChapter methodsFor: 'rendering'!
  302. renderLinksOn: html
  303. html ul
  304. class: 'links';
  305. with: [
  306. html li with: [html a
  307. with: 'Browse this class';
  308. onClick: [Browser openOn: self theClass]]]
  309. ! !
  310. !ClassDocChapter methodsFor: 'subscriptions'!
  311. subscribe
  312. super subscribe.
  313. self announcer
  314. on: ClassSelectionAnnouncement do: [:ann |
  315. ann theClass = self theClass ifTrue: [
  316. self selectChapter: self]]
  317. ! !
  318. !ClassDocChapter class methodsFor: 'accessing'!
  319. on: aClass
  320. ^self basicNew
  321. initializeWithClass: aClass;
  322. initialize;
  323. yourself
  324. ! !
  325. Widget subclass: #DocumentationWidget
  326. instanceVariableNames: 'builder selectedChapter chapterDiv'
  327. category: 'Documentation'!
  328. !DocumentationWidget methodsFor: 'accessing'!
  329. builder
  330. ^builder
  331. !
  332. builder: aDocumentationBuilder
  333. builder := aDocumentationBuilder
  334. !
  335. chapters
  336. ^self builder chapters
  337. !
  338. selectedChapter
  339. ^selectedChapter ifNil: [selectedChapter := self chapters first]
  340. !
  341. selectedChapter: aChapter
  342. ^selectedChapter := aChapter
  343. ! !
  344. !DocumentationWidget methodsFor: 'actions'!
  345. displayChapter: aChapter
  346. self selectedChapter: aChapter.
  347. self updateChapterDiv
  348. !
  349. selectChapter: aChapter
  350. document location hash: aChapter id
  351. ! !
  352. !DocumentationWidget methodsFor: 'rendering'!
  353. renderOn: html
  354. html div
  355. class: 'documentation';
  356. with: [
  357. self renderMenuOn: html.
  358. chapterDiv := html div.
  359. self updateChapterDiv]
  360. !
  361. renderMenuOn: html
  362. html div
  363. class: 'menu';
  364. with: [
  365. html ol with: [
  366. self chapters do: [:each |
  367. html li with: [
  368. self renderChapterMenu: each on: html]]]]
  369. !
  370. renderChapterMenu: aChapter on: html
  371. html a
  372. with: aChapter title;
  373. onClick: [
  374. self selectChapter: aChapter].
  375. html ol with: [
  376. aChapter chapters do: [:each |
  377. html li with: [
  378. self renderChapterMenu: each on: html]]]
  379. ! !
  380. !DocumentationWidget methodsFor: 'updating'!
  381. updateChapterDiv
  382. chapterDiv contents: [:html |
  383. html with: self selectedChapter]
  384. ! !
  385. !DocumentationWidget class methodsFor: 'instance creation'!
  386. on: aBuilder
  387. ^self new
  388. builder: aBuilder;
  389. yourself
  390. ! !
  391. DocChapter subclass: #ClassesIndexChapter
  392. instanceVariableNames: ''
  393. category: 'Documentation'!
  394. !ClassesIndexChapter methodsFor: 'accessing'!
  395. cssClass
  396. ^'index_doc ', super cssClass
  397. !
  398. title
  399. ^'Smalltalk classes by index'
  400. !
  401. alphabet
  402. ^'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  403. ! !
  404. !ClassesIndexChapter methodsFor: 'rendering'!
  405. renderDocOn: html
  406. html h1 with: self title.
  407. self alphabet do: [:letter || classes |
  408. classes := Smalltalk current classes select: [:each | each name first = letter].
  409. classes ifNotEmpty: [html h2 with: letter].
  410. html ul with: [
  411. (classes sorted: [:a :b | a name < b name])
  412. do: [:each |
  413. html li with: [html a
  414. with: each name;
  415. onClick: [self selectClass: each]]]]]
  416. ! !
  417. Object subclass: #ClassSelectionAnnouncement
  418. instanceVariableNames: 'theClass'
  419. category: 'Documentation'!
  420. !ClassSelectionAnnouncement methodsFor: 'accessing'!
  421. theClass
  422. ^theClass
  423. !
  424. theClass: aClass
  425. theClass := aClass
  426. ! !
  427. !ClassSelectionAnnouncement class methodsFor: 'instance creation'!
  428. on: aClass
  429. ^self new
  430. theClass: aClass;
  431. yourself
  432. ! !
  433. Object subclass: #ChapterSelectionAnnouncement
  434. instanceVariableNames: 'id'
  435. category: 'Documentation'!
  436. !ChapterSelectionAnnouncement methodsFor: 'accessing'!
  437. id
  438. ^id
  439. !
  440. id: aString
  441. id := aString
  442. ! !
  443. DocChapter subclass: #TutorialsChapter
  444. instanceVariableNames: ''
  445. category: 'Documentation'!
  446. !TutorialsChapter methodsFor: 'accessing'!
  447. title
  448. ^'Tutorials'
  449. !
  450. contents
  451. ^'Here''s a serie of tutorials. If you are new to Smalltalk, you can also learn Amber online with [ProfStef](http://www.amber-lang.net/learn.html)'
  452. !
  453. chapters
  454. ^{ self firstAppChapter. self counterChapter }
  455. !
  456. firstAppChapter
  457. ^DocChapter new
  458. title: 'A first application';
  459. contents: '
  460. Let''s make Hello World in Amber.
  461. First, you need a place for your new project. I made a new directory under amber:
  462. amber/projects/hello
  463. This will store your project files. To get started, add a new index.html file to this folder, as well as empty js and st folders.
  464. Your index.html can be really basic. The most important thing it does is include amber.js and run loadAmber. Here is a basic index.html you can use:
  465. <!!DOCTYPE html>
  466. <html>
  467. <head>
  468. <title>My First Amber Project</title>
  469. <script src="../../js/amber.js" type="text/javascript"></script>
  470. <script type="text/javascript">
  471. loadAmber({
  472. files: [],
  473. prefix: ''projects/hello/js'',
  474. ready: function() {
  475. }});
  476. </script>
  477. </head>
  478. <body>
  479. <article>
  480. <h1>My First Amber Project</h1>
  481. <button onclick="smalltalk.Browser._open()">class browser</button>
  482. <button id="sayHello">say hello</button>
  483. </article>
  484. </body>
  485. </html>
  486. Now start up amber with node.js and navigate to http://localhost:4000/projects/hello/index.html
  487. It''s boring so far, so lets write some code. Click the button to open the class browser. Find an existing class and change its name to Hello and its package to HelloApp.
  488. Then click save. This creates a new class and leaves the old one intact, it doesn''t overwrite it. Your class will look like this:
  489. Object subclass: #Hello
  490. instanceVariableNames: ''''
  491. package: ''HelloApp''
  492. Now click save and navigate to your new class in its new package.
  493. Then click ''commit package''. You just created a new class and saved your work.
  494. On your file system check out your js and st folders. Your new class is now saved in both JavaScript and Smalltalk.
  495. Now, refresh your browser page and reopen the class browser. Oh no, your new class is gone!! To load your new class automatically, you have to add it in index.html. Make your JavaScript look like this:
  496. loadAmber({
  497. files: [''HelloApp.js''],
  498. prefix: ''projects/hello/js'',
  499. ready: function() {
  500. }});
  501. Save and refresh again. Now your class is loaded and shows up in the class browser.
  502. Now, let''s make this class do something. Create a new message in the class browser by navigating to your class, then clicking ''not yet classified'' and fill in a simple message. Try this for example:
  503. begin
  504. "Makes me say hello to the user."
  505. | msg button |
  506. msg := ''Hello world!!''.
  507. button := ''#sayHello'' asJQuery.
  508. button click: [button after: ''<p>'' , msg , ''</p>''].
  509. Your message isn''t too helpful if it doesn''t get called. Save it, commit the package, then edit index.html again. You can write JavaScript code that sends a message to Smalltalk:
  510. loadAmber({
  511. files: [''HelloApp.js''],
  512. prefix: ''projects/hello/js'', // path for js files i think
  513. ready: function() {
  514. $(function() {
  515. smalltalk.Hello._new()._begin();
  516. });
  517. }});
  518. From there, you can create new Smalltalk classes and messages to build up your app. Enjoy!!
  519. '
  520. !
  521. counterChapter
  522. ^DocChapter new
  523. title: 'The counter application';
  524. contents: '
  525. This tutorial will teach you how to build HTML with Amber using jQuery and the HTMLCanvas API. It is freely adapted from
  526. the [Seaside counter example](http://www.seaside.st/about/examples/counter)
  527. ##The counter widget
  528. The counter is the most basic example of a widget. It allows to increment and decrement a number by clicking a button.
  529. Amber already comes with a counter example in the `Examples` package. To avoid class name conflict, we''ll name our counter class `TCounter`.
  530. Widget subclass: #TCounter
  531. instanceVariableNames: ''count header''
  532. package: ''Tutorials''
  533. The first method is used to initialize the component with the default state, in this case we set the counter to 0:
  534. initialize
  535. super initialize.
  536. count := 0
  537. The method used for rendering a widget is `#renderOn:`. It takes an instance of HTMLCanvas as parameter.
  538. The `header` h1 kept as an instance variable, so when the count value change, we can update it''s contents accordingly.
  539. renderOn: html
  540. header := html h1
  541. with: count asString;
  542. yourself.
  543. html button
  544. with: ''++'';
  545. onClick: [self increase].
  546. html button
  547. with: ''--'';
  548. onClick: [self decrease]
  549. The counter is almost ready. All we need now is to implement the two action methods `#increase` and `#decrease` to change the state
  550. of our counter and update its header.
  551. increase
  552. count := count + 1.
  553. header contents: [:html | html with: count asString]
  554. decrease
  555. count := count - 1.
  556. header contents: [:html | html with: count asString]
  557. That''s it!! We can now display an instance of TCounter by rendering it on the page using jQuery:
  558. TCounter new appendToJQuery: ''body'' asJQuery
  559. '
  560. ! !