Documentation.st 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. Smalltalk current createPackage: 'Documentation' properties: #{}!
  2. Object subclass: #ChapterSelectionAnnouncement
  3. instanceVariableNames: 'id'
  4. package: 'Documentation'!
  5. !ChapterSelectionAnnouncement methodsFor: 'accessing'!
  6. id
  7. ^id
  8. !
  9. id: aString
  10. id := aString
  11. ! !
  12. Object subclass: #ClassSelectionAnnouncement
  13. instanceVariableNames: 'theClass'
  14. package: 'Documentation'!
  15. !ClassSelectionAnnouncement methodsFor: 'accessing'!
  16. theClass
  17. ^theClass
  18. !
  19. theClass: aClass
  20. theClass := aClass
  21. ! !
  22. !ClassSelectionAnnouncement class methodsFor: 'instance creation'!
  23. on: aClass
  24. ^self new
  25. theClass: aClass;
  26. yourself
  27. ! !
  28. Widget subclass: #DocChapter
  29. instanceVariableNames: 'title contents parent level'
  30. package: 'Documentation'!
  31. !DocChapter methodsFor: 'accessing'!
  32. announcer
  33. ^DocumentationBuilder current announcer
  34. !
  35. chapters
  36. "A doc chapter can contain sub chapters"
  37. ^#()
  38. !
  39. contents
  40. ^contents ifNil: ['']
  41. !
  42. contents: aString
  43. contents := aString
  44. !
  45. cssClass
  46. ^'doc_chapter'
  47. !
  48. htmlContents
  49. ^(Showdown at: #converter) new makeHtml: self contents
  50. !
  51. id
  52. "The id is used in url fragments.
  53. It must be unique amoung all chapters"
  54. ^self title replace: ' ' with: '-'
  55. !
  56. level
  57. ^self parent ifNil: [1] ifNotNil: [self parent level +1]
  58. !
  59. level: anInteger
  60. level := anInteger
  61. !
  62. parent
  63. ^parent
  64. !
  65. parent: aChapter
  66. parent := aChapter
  67. !
  68. title
  69. ^title ifNil: ['']
  70. !
  71. title: aString
  72. title := aString
  73. ! !
  74. !DocChapter methodsFor: 'actions'!
  75. displayChapter: aChapter
  76. DocumentationBuilder current widget displayChapter: aChapter
  77. !
  78. selectChapter: aChapter
  79. document location hash: aChapter id
  80. !
  81. selectClass: aClass
  82. DocumentationBuilder current announcer announce: (ClassSelectionAnnouncement on: aClass)
  83. ! !
  84. !DocChapter methodsFor: 'initialization'!
  85. initialize
  86. super initialize.
  87. self subscribe
  88. ! !
  89. !DocChapter methodsFor: 'rendering'!
  90. renderDocOn: html
  91. | div |
  92. html h1 with: self title.
  93. self renderNavigationOn: html.
  94. div := html div class: 'contents'.
  95. div asJQuery html: self htmlContents
  96. !
  97. renderLinksOn: html
  98. html ul
  99. class: 'links';
  100. with: [
  101. self chapters do: [:each |
  102. html li with: [
  103. html a
  104. with: each title;
  105. onClick: [self selectChapter: each]]]]
  106. !
  107. renderNavigationOn: html
  108. self parent ifNotNil: [
  109. html div
  110. class: 'navigation'; with: [
  111. html a
  112. with: '← back to ', self parent title;
  113. onClick: [self selectChapter: self parent]]]
  114. !
  115. renderOn: html
  116. html div
  117. class: self cssClass;
  118. with: [
  119. self renderDocOn: html.
  120. self renderLinksOn: html]
  121. ! !
  122. !DocChapter methodsFor: 'subscriptions'!
  123. subscribe
  124. self announcer on: ChapterSelectionAnnouncement do: [:ann |
  125. ann id = self id ifTrue: [self displayChapter: self]]
  126. ! !
  127. DocChapter subclass: #ClassDocChapter
  128. instanceVariableNames: 'theClass'
  129. package: 'Documentation'!
  130. !ClassDocChapter methodsFor: 'accessing'!
  131. contents
  132. ^self theClass comment isEmpty
  133. ifTrue: [self theClass name, ' is not documented yet.']
  134. ifFalse: [self theClass comment]
  135. !
  136. cssClass
  137. ^'doc_class ', super cssClass
  138. !
  139. initializeWithClass: aClass
  140. theClass := aClass
  141. !
  142. theClass
  143. ^theClass
  144. !
  145. title
  146. ^self theClass name
  147. ! !
  148. !ClassDocChapter methodsFor: 'rendering'!
  149. renderLinksOn: html
  150. html ul
  151. class: 'links';
  152. with: [
  153. html li with: [html a
  154. with: 'Browse this class';
  155. onClick: [Browser openOn: self theClass]]]
  156. ! !
  157. !ClassDocChapter methodsFor: 'subscriptions'!
  158. subscribe
  159. super subscribe.
  160. self announcer
  161. on: ClassSelectionAnnouncement do: [:ann |
  162. ann theClass = self theClass ifTrue: [
  163. self selectChapter: self]]
  164. ! !
  165. !ClassDocChapter class methodsFor: 'accessing'!
  166. on: aClass
  167. ^self basicNew
  168. initializeWithClass: aClass;
  169. initialize;
  170. yourself
  171. ! !
  172. DocChapter subclass: #ClassesIndexChapter
  173. instanceVariableNames: ''
  174. package: 'Documentation'!
  175. !ClassesIndexChapter methodsFor: 'accessing'!
  176. alphabet
  177. ^'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  178. !
  179. cssClass
  180. ^'index_doc ', super cssClass
  181. !
  182. title
  183. ^'Smalltalk classes by index'
  184. ! !
  185. !ClassesIndexChapter methodsFor: 'rendering'!
  186. renderDocOn: html
  187. html h1 with: self title.
  188. self alphabet do: [:letter || classes |
  189. classes := Smalltalk current classes select: [:each | each name first = letter].
  190. classes ifNotEmpty: [html h2 with: letter].
  191. html ul with: [
  192. (classes sorted: [:a :b | a name < b name])
  193. do: [:each |
  194. html li with: [html a
  195. with: each name;
  196. onClick: [self selectClass: each]]]]]
  197. ! !
  198. DocChapter subclass: #PackageDocChapter
  199. instanceVariableNames: 'package chapters'
  200. package: 'Documentation'!
  201. !PackageDocChapter methodsFor: 'accessing'!
  202. chapters
  203. ^chapters
  204. !
  205. contents
  206. ^'Classes in package ', self package name, ':'
  207. !
  208. package
  209. ^package
  210. !
  211. title
  212. ^'Package ', self package name
  213. ! !
  214. !PackageDocChapter methodsFor: 'initialization'!
  215. initializeWithPackage: aPackage
  216. package := aPackage.
  217. chapters := (aPackage classes sorted: [:a :b | a name < b name]) collect: [:each |
  218. (ClassDocChapter on: each)
  219. parent: self;
  220. yourself]
  221. ! !
  222. !PackageDocChapter class methodsFor: 'instance creation'!
  223. on: aPackage
  224. ^self basicNew
  225. initializeWithPackage: aPackage;
  226. initialize;
  227. yourself
  228. ! !
  229. DocChapter subclass: #TutorialsChapter
  230. instanceVariableNames: ''
  231. package: 'Documentation'!
  232. !TutorialsChapter methodsFor: 'accessing'!
  233. chapters
  234. ^{ self firstAppChapter. self counterChapter }
  235. !
  236. contents
  237. ^'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)'
  238. !
  239. counterChapter
  240. ^DocChapter new
  241. title: 'The counter application';
  242. contents: '
  243. This tutorial will teach you how to build HTML with Amber using jQuery and the HTMLCanvas API. It is freely adapted from
  244. the [Seaside counter example](http://www.seaside.st/about/examples/counter)
  245. ##The counter widget
  246. The counter is the most basic example of a widget. It allows to increment and decrement a number by clicking a button.
  247. Amber already comes with a counter example in the `Examples` package. To avoid class name conflict, we''ll name our counter class `TCounter`.
  248. Widget subclass: #TCounter
  249. instanceVariableNames: ''count header''
  250. package: ''Tutorials''
  251. The first method is used to initialize the component with the default state, in this case we set the counter to 0:
  252. initialize
  253. super initialize.
  254. count := 0
  255. The method used for rendering a widget is `#renderOn:`. It takes an instance of HTMLCanvas as parameter.
  256. The `header` h1 kept as an instance variable, so when the count value change, we can update it''s contents accordingly.
  257. renderOn: html
  258. header := html h1
  259. with: count asString;
  260. yourself.
  261. html button
  262. with: ''++'';
  263. onClick: [self increase].
  264. html button
  265. with: ''--'';
  266. onClick: [self decrease]
  267. The counter is almost ready. All we need now is to implement the two action methods `#increase` and `#decrease` to change the state
  268. of our counter and update its header.
  269. increase
  270. count := count + 1.
  271. header contents: [:html | html with: count asString]
  272. decrease
  273. count := count - 1.
  274. header contents: [:html | html with: count asString]
  275. That''s it!! We can now display an instance of TCounter by rendering it on the page using jQuery:
  276. TCounter new appendToJQuery: ''body'' asJQuery
  277. '
  278. !
  279. firstAppChapter
  280. ^DocChapter new
  281. title: 'A first application';
  282. contents: '
  283. Let''s make Hello World in Amber.
  284. First, you need a place for your new project. I made a new directory under amber:
  285. amber/projects/hello
  286. 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.
  287. 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:
  288. <!!DOCTYPE html>
  289. <html>
  290. <head>
  291. <title>My First Amber Project</title>
  292. <script src="../../js/amber.js" type="text/javascript"></script>
  293. <script type="text/javascript">
  294. loadAmber({
  295. files: [],
  296. prefix: ''projects/hello/js'',
  297. ready: function() {
  298. }});
  299. </script>
  300. </head>
  301. <body>
  302. <article>
  303. <h1>My First Amber Project</h1>
  304. <button onclick="smalltalk.Browser._open()">class browser</button>
  305. <button id="sayHello">say hello</button>
  306. </article>
  307. </body>
  308. </html>
  309. Now start up amber with node.js and navigate to http://localhost:4000/projects/hello/index.html
  310. 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.
  311. 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:
  312. Object subclass: #Hello
  313. instanceVariableNames: ''''
  314. package: ''HelloApp''
  315. Now click save and navigate to your new class in its new package.
  316. Then click ''commit package''. You just created a new class and saved your work.
  317. On your file system check out your js and st folders. Your new class is now saved in both JavaScript and Smalltalk.
  318. 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:
  319. loadAmber({
  320. files: [''HelloApp.js''],
  321. prefix: ''projects/hello/js'',
  322. ready: function() {
  323. }});
  324. Save and refresh again. Now your class is loaded and shows up in the class browser.
  325. 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:
  326. begin
  327. "Makes me say hello to the user."
  328. | msg button |
  329. msg := ''Hello world!!''.
  330. button := ''#sayHello'' asJQuery.
  331. button click: [button after: ''<p>'' , msg , ''</p>''].
  332. 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:
  333. loadAmber({
  334. files: [''HelloApp.js''],
  335. prefix: ''projects/hello/js'', // path for js files i think
  336. ready: function() {
  337. $(function() {
  338. smalltalk.Hello._new()._begin();
  339. });
  340. }});
  341. From there, you can create new Smalltalk classes and messages to build up your app. Enjoy!!
  342. '
  343. !
  344. title
  345. ^'Tutorials'
  346. ! !
  347. Object subclass: #DocumentationBuilder
  348. instanceVariableNames: 'chapters announcer widget'
  349. package: 'Documentation'!
  350. !DocumentationBuilder methodsFor: 'accessing'!
  351. announcer
  352. ^announcer ifNil: [announcer := Announcer new]
  353. !
  354. chapters
  355. ^chapters ifNil: [chapters := self buildChapters]
  356. !
  357. widget
  358. ^widget ifNil: [widget := DocumentationWidget on: self]
  359. ! !
  360. !DocumentationBuilder methodsFor: 'building'!
  361. build
  362. self buildOnJQuery: ('body' asJQuery)
  363. !
  364. buildChapters
  365. ^((self class methodDictionary values sorted: [:a :b | a selector < b selector])
  366. select: [:each | each category = 'chapters'])
  367. collect: [:each | self perform: each selector]
  368. !
  369. buildOn: aCanvas
  370. aCanvas with: self widget.
  371. self
  372. checkHashChange;
  373. checkHash
  374. !
  375. buildOnJQuery: aJQuery
  376. self buildOn: (HTMLCanvas onJQuery: aJQuery)
  377. ! !
  378. !DocumentationBuilder methodsFor: 'chapters'!
  379. ch1introduction
  380. ^DocChapter new
  381. title: 'Introduction';
  382. contents: '
  383. ##Amber Smalltalk in a nutshell
  384. Amber is an implementation of the Smalltalk-80 language. It is designed to make client-side web development **faster, easier and more fun** as it allows developers to write HTML5 applications in a live Smalltalk environment!!
  385. Amber is written in itself, including the IDE and the compiler and it runs **directly inside your browser**. The IDE is fairly complete with a class browser, workspace, transcript, unit test runner, object inspectors, cross reference tools and even a debugger.
  386. Noteworthy features:
  387. - Amber is semantically and syntactically very close to [Pharo Smalltalk](http://www.pharo-project.org). Pharo is considered the reference implementation.
  388. - Amber **seamlessly interacts with JavaScript** and can use its full eco system of libraries without any glue code needed.
  389. - Amber **has no dependencies** and can be used in any JavaScript runtime, not only inside browsers. An important example is [Node.js](http://nodejs.org).
  390. - Amber is a live Smalltalk that **compiles incrementally into efficient JavaScript** often mapping one-to-one with JavaScript equivalents.
  391. - Amber has a **Seaside influenced canvas library** to dynamically generate HTML.
  392. ## Arguments for using Amber
  393. In our humble opinion the main arguments for using Amber are:
  394. - JavaScript is quite a broken language with lots of traps and odd quirks. It is the assembler of the Internet which is cool, but we don''t want to write in it.
  395. - Smalltalk as a language is immensely cleaner and more mature, both syntactically and semantically.
  396. - Smalltalk has a simple class model with a lightweight syntax for closures, it is in many ways a perfect match for the Good Parts of JavaScript.
  397. - Having a true live interactive incremental development environment where you can build your application directly in the browser is unbeatable.
  398. ## Disclaimer
  399. This documentation doesn''t aim to teach Smalltalk.
  400. Knowledge of Smalltalk is needed to understand the topics covered in this documentation.
  401. If you want to learn the Smalltalk language, you can read the excellent [Pharo By Example](http://www.pharobyexample.org) book.
  402. '
  403. !
  404. ch2differencesWithOtherSmalltalks
  405. ^DocChapter new
  406. title: 'Differences with other Smalltalks';
  407. contents: '
  408. Amber has some differences with other Smalltalk implementations. This makes porting code a non-trivial thing, but still quite manageable.
  409. 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.
  410. And since we want Amber to be useful in building lean browser apps we can''t let it bloat too much.
  411. But apart from missing things other Smalltalks may have, there are also things that are plain different:
  412. - The collection class hierarchy is much simpler compared to most Smalltalk implementations. In part this is because we want to map reasonably well with JavaScript counter parts.
  413. - As of today, there is no SortedCollection. The size of arrays is dynamic, and they behave like an ordered collection. They can also be sorted with the `#sort*` methods.
  414. - The `Date` class behaves like the `Date` and `TimeStamp` classes in Pharo Smalltalk. Therefore both `Date today` and `Date now` are valid in Amber.
  415. - Amber does not have class Character, but `String` does implement some of Character behavior so a single character String can work as a Character.
  416. - Amber does support **class instance variables**, but not class variables.
  417. - Amber only has global classes and packages, but not arbitrary objects. Use classes instead like `Smalltalk current` instead of `Smalltalk` etc.
  418. - Amber does not support pool dictionaries.
  419. - Amber uses **< ...javascript code... >** to inline JavaScript code and does not have pragmas.
  420. - Amber does not have class categories. The left side in the browser lists real Packages, but they feel much the same.
  421. '
  422. !
  423. ch3GettingStarted
  424. ^DocChapter new
  425. title: 'Getting started';
  426. contents: '
  427. To get started hacking in Amber you can basically take three routes, independent of your platform:
  428. 1. Just **try it out directly** at [www.amber-lang.net](http://www.amber-lang.net) - click the **Class browser** button there. But you will **not be able to save any code you write**!!
  429. Still, it works fine for looking at the IDE and playing around. Just **don''t press F5/reload** - it will lose any code you have written.
  430. 2. Download an Amber zip-ball, install [Nodejs](http://www.nodejs.org), fire up the Amber server and then open Amber from localhost - then you **can save code**. Detailed instructions are below!!
  431. 3. Same as above but install git first and get a proper clone from [http://github.com/NicolasPetton/amber](http://github.com/NicolasPetton/amber) instead of a zip/tar-ball.
  432. If you want to **contribute to Amber itself** this is really what you want to do. In fact, in most cases this is 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" :)
  433. **PLEASE NOTE:** Amber core developers use Linux.
  434. 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
  435. (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.
  436. 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!!
  437. ## Downloading Amber
  438. 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).
  439. Unpack wherever you like, but I would rename the directory that is unpacked to something slightly shorter - like say "amber". :)
  440. 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 :)
  441. ## Installing Node.js
  442. [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".
  443. 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).
  444. There are also several Amber-Node examples to look at if you want to play with running Amber programs server side. **In short - you really want to install Nodejs. :)**
  445. - 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).
  446. - Installing Node on MacOS or Windows is probably done best by using the [installers available at Nodejs.org](http://nodejs.org/#download).
  447. ## Starting Amber server
  448. 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!!
  449. And it runs on top of Node. So to start it up serving your brand new directory tree of sweet Amber you do:
  450. cd amber (or whatever you called the directory you unpackaged)
  451. ./bin/server (in windows you type `node server\server.js` instead)
  452. 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!!
  453. ## Firing up Amber
  454. The Amber IDE is written in... Amber. It uses [jQuery](http://jquery.com) and runs right in your browser as a ... well, a web page.
  455. 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.
  456. 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](http://localhost:4000/index.html).
  457. Clicking that link and then pressing the **Class browser** should get your Amber IDE running with the ability to commit modified packages locally.
  458. To verify that you can indeed commit now - just select a Package in the browser, like say "Examples" and press the **Commit** button below. **If all goes well nothing happens :)**.
  459. 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.
  460. 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.
  461. '
  462. !
  463. ch4Tutorials
  464. ^TutorialsChapter new
  465. !
  466. ch5Index
  467. ^ClassesIndexChapter new
  468. !
  469. ch6KernelObjects
  470. ^PackageDocChapter on: (Package named: 'Kernel-Objects')
  471. !
  472. ch7KernelClasses
  473. ^PackageDocChapter on: (Package named: 'Kernel-Classes')
  474. !
  475. ch8KernelCollection
  476. ^PackageDocChapter on: (Package named: 'Kernel-Collections')
  477. !
  478. ch9KernelMethods
  479. ^PackageDocChapter on: (Package named: 'Kernel-Methods')
  480. ! !
  481. !DocumentationBuilder methodsFor: 'routing'!
  482. checkHash
  483. | hash presentation |
  484. hash := document location hash replace: '^#' with: ''.
  485. self announcer announce: (ChapterSelectionAnnouncement new
  486. id: hash;
  487. yourself)
  488. !
  489. checkHashChange
  490. (window jQuery: window) bind: 'hashchange' do: [self checkHash]
  491. ! !
  492. !DocumentationBuilder methodsFor: 'updating'!
  493. update
  494. chapters := nil.
  495. announcer := nil.
  496. widget := nil.
  497. (window jQuery: '.documentation') remove.
  498. self build
  499. ! !
  500. DocumentationBuilder class instanceVariableNames: 'current'!
  501. !DocumentationBuilder class methodsFor: 'accessing'!
  502. current
  503. ^current ifNil: [current := self new]
  504. ! !
  505. !DocumentationBuilder class methodsFor: 'initialization'!
  506. initialize
  507. self current build
  508. ! !
  509. Widget subclass: #DocumentationWidget
  510. instanceVariableNames: 'builder selectedChapter chapterDiv'
  511. package: 'Documentation'!
  512. !DocumentationWidget methodsFor: 'accessing'!
  513. builder
  514. ^builder
  515. !
  516. builder: aDocumentationBuilder
  517. builder := aDocumentationBuilder
  518. !
  519. chapters
  520. ^self builder chapters
  521. !
  522. selectedChapter
  523. ^selectedChapter ifNil: [selectedChapter := self chapters first]
  524. !
  525. selectedChapter: aChapter
  526. ^selectedChapter := aChapter
  527. ! !
  528. !DocumentationWidget methodsFor: 'actions'!
  529. displayChapter: aChapter
  530. self selectedChapter: aChapter.
  531. self updateChapterDiv
  532. !
  533. selectChapter: aChapter
  534. document location hash: aChapter id
  535. ! !
  536. !DocumentationWidget methodsFor: 'rendering'!
  537. renderChapterMenu: aChapter on: html
  538. html a
  539. with: aChapter title;
  540. onClick: [
  541. self selectChapter: aChapter].
  542. html ol with: [
  543. aChapter chapters do: [:each |
  544. html li with: [
  545. self renderChapterMenu: each on: html]]]
  546. !
  547. renderMenuOn: html
  548. html div
  549. class: 'menu';
  550. with: [
  551. html ol with: [
  552. self chapters do: [:each |
  553. html li with: [
  554. self renderChapterMenu: each on: html]]]]
  555. !
  556. renderOn: html
  557. html div
  558. class: 'documentation';
  559. with: [
  560. self renderMenuOn: html.
  561. chapterDiv := html div.
  562. self updateChapterDiv]
  563. ! !
  564. !DocumentationWidget methodsFor: 'updating'!
  565. updateChapterDiv
  566. chapterDiv contents: [:html |
  567. html with: self selectedChapter]
  568. ! !
  569. !DocumentationWidget class methodsFor: 'instance creation'!
  570. on: aBuilder
  571. ^self new
  572. builder: aBuilder;
  573. yourself
  574. ! !