documentation.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ---
  2. layout: default
  3. title: Jtalk Smalltalk - documentation
  4. ---
  5. <div class="box last doc" id="documentation">
  6. <h2>Documentation</h2>
  7. <div class="content">
  8. <h3>Disclaimer</h3>
  9. <p class="warning">This documentation is a work in progress. If you find an error in the documentation, please <a href="https://github.com/NicolasPetton/jtalk/issues">file an issue</a>.</p>
  10. <p>This documentation <strong>doesn't aim to teach Smalltalk</strong>. Knowledge of Smalltalk is needed to understand the topics covered in this documentation. If you want to learn the Smalltalk language, you can read the excellent <a target="_blank" href="http://pharobyexamle.org">Pharo By Example</a> book.</p>
  11. <h3>Introduction</h3>
  12. <p class="information">Jtalk is a young piece of code and evolves quickly. Some features are still incomplete and you may very well encounter bugs, in which case you can <a href="https://github.com/NicolasPetton/jtalk/issues">file an issue</a> or a pull request on the <a href="https://github.com/NicolasPetton/jtalk">repository</a>.</p>
  13. <p>Jtalk is an implementation of the Smalltalk-80 language. It allows developers to write client-side heavy web applications in Smalltalk. Jtalk includes an integrated development environment with a class browser, workspace and transcript.</p>
  14. <p>Jtalk includes the following features:</p>
  15. <ol>
  16. <li>It is semantically and syntaxically equivalent to <a href="http://www.pharo-project.org">Pharo Smalltalk</a> (the implementation considered as the reference)</li>
  17. <li>It is written in itself and compiles into efficient JavaScript</li>
  18. <li>A canvas API similar to <a href="http://www.seaside.st">Seaside</a> to generate HTML</li>
  19. <li>A <a href="http://www.jquery.com">jQuery</a> binding</li>
  20. </ol>
  21. <h3>Differences with other Smalltalk implementations</h3>
  22. Jtalk has some differences with other Smalltalk implementations. 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. The following list explains the main differences:
  23. <ul>
  24. <li>There is no identity in Jtalk. Especially, there is no <code>==</code> method, or <code>Symbol</code> class. For convenience and compatibility, the Jtalk parser will recognize symbol literals as strings.</li>
  25. <li>The collection class hierarchy is simpler compared to most Smalltalk implementations. There is no <code>OrderedCollection</code>, <code>Set</code> or <code>SortedCollection</code>. However, the size of arrays is dynamic, and they behave like an ordered collection. They can also be sorted with the <code>#sort*</code> methods.</li>
  26. <li>The <code>Date</code> class behaves like the <code>Date</code> <em>and</em> <code>TimeStamp</code> classes in Pharo Smalltalk. Therefore both <code>Date today</code> and <code>Date now</code> are valid in Jtalk.</li>
  27. <li>Jtalk use solely <code>=</code> to test object equality and not the <code>#hash</code> method.</li>
  28. <li>Jtalk misses <code>thisContext</code> and does not support <code>#doesNotUnderstand</code>.</li>
  29. </ul>
  30. <h3>Committing changes to disk with the web-based IDE</h3>
  31. <p>The class browser is able to commit changes to disk. The <code>commit category</code> button will send a PUT request with the compiled JavaScript code of all classes in the selected class category in a file named <code>js/CATEGORY.js</code>.</p>
  32. <p>The easiest way to enable committing is probably to setup a webdav with Apache.</p>
  33. <p class="information">The following steps explain how to setup a webdav for Jtalk with Debian, but the setup on OSX and other Linux distros should be similar.</p>
  34. <h4>Installing Apache and enabling the dav module</h4>
  35. <p>Evaluate the following as root:</p>
  36. <pre><span class="prompt">~#</span> <span class="kbd">apt-get install</span> <span class="kbd var">apache2</span>
  37. <span class="prompt">~#</span> <span class="kbd">a2enmod</span> <span class="kbd var">dav</span>
  38. <span class="prompt">~#</span> <span class="kbd">a2enmod</span> <span class="kbd var">dav_fs</span></pre>
  39. <h4>Creating a password for the webdav</h4>
  40. <pre><span class="prompt">~#</span> <span class="kbd">htpasswd -c /etc/apache2/htpasswd-webdav <span class="kbd var">USERNAME</span></span></pre>
  41. <h4>Setting up the webdav directory</h4>
  42. <p>Add the following lines to the default vhost (in <code>/etc/apache2/sites-available/default</code>):</p>
  43. <pre>Alias /jtalk/ "/path/to/jtalk/"
  44. &lt;Directory "/path/to/jtalk/"&gt;
  45. Options Indexes MultiViews FollowSymLinks
  46. DirectoryIndex index.html
  47. AllowOverride None
  48. Order allow,deny
  49. allow from all
  50. Dav on
  51. AuthType Basic
  52. AuthName "jtalk"
  53. AuthUserFile /etc/apache2/htpasswd-webdav
  54. &lt;LimitExcept GET OPTIONS&gt;
  55. Require valid-user
  56. &lt;/LimitExcept&gt;
  57. &lt;/Directory&gt;</pre>
  58. <p>Make sure the group <code>www-data</code> has required rights to make changes to files in the webdav directory.</p>
  59. <h4>Restarting Apache</h4>
  60. <p>To restart Apache, evaluate the following: </p>
  61. <pre><span class="prompt">~#</span> <span class="kbd">/etc/init.d/apache2</span> <span class="kbd var">restart</span></pre>
  62. <p>and go to <code>http://localhost/jtalk/</code>.</p>
  63. <p>The class browser should now be able to commit changes to disk.</p>
  64. <h3>The counter example</h3>
  65. <p>The following example is the traditional Seaside-like multi-counter application. The buttons at the bottom of each counter increase or decrease the counter.</p>
  66. <div id="counters"></div>
  67. <script type="text/javascript">
  68. jQuery(document).ready(function() {'#counters'._asJQuery()._append_(smalltalk.Counter._new())._append_(smalltalk.Counter._new())});
  69. </script>
  70. <p>Open a <button onclick="smalltalk.Browser._openOn_(smalltalk.Counter);">browser</button> on the <code>Counter</code> class in the <code>Canvas</code> class category.
  71. <p>Each Jtalk widget is a subclass of <code>Widget</code>. A widget is a graphical component. The <code>#renderOn:</code> method is used to generate HTML using the HTML canvas.</p>
  72. <p class="information">Rendering methods should be placed in the <code>rendering</code> method protocol, and action methods in the <code>actions</code> protocol.</p>
  73. {% highlight smalltalk %}renderOn: html
  74. html h1 with: count asString.
  75. html button
  76. with: '++';
  77. onClick: [self increase].
  78. html button
  79. with: '--';
  80. onClick: [self decrease] {% endhighlight %}
  81. <h3>The HTML canvas</h3>
  82. <h3>Widgets</h3>
  83. <h3>jQuery</h3>
  84. </div>
  85. </div>
  86. <!-- Add anchors to doc titles and build the dropdown menu -->
  87. <script type="text/javascript">
  88. jQuery('#menu .main').append("<ul id='dropdown'></ul>");
  89. jQuery.each(jQuery('.doc h3'), function(i, heading) {
  90. jQuery(heading).attr({'id': jQuery(heading).text().replace(/ /g,"_")});
  91. jQuery(heading).html(i + ". " + jQuery(heading).html());
  92. jQuery('#dropdown').append("<li><a href='#" + jQuery(heading).attr('id') + "'>" + jQuery(heading).text() + "</a></li>");
  93. jQuery(heading).html(jQuery(heading).html() + " <a href='#" + jQuery(heading).attr('id') + "'>&para;</a>");
  94. });
  95. jQuery('#doc_link')
  96. .bind('mouseenter', function() {jQuery('#dropdown').show()})
  97. .bind('mouseleave', function() {jQuery('#dropdown').hide()});
  98. jQuery('#dropdown')
  99. .bind('mouseenter', function() {jQuery('#dropdown').show()})
  100. .bind('mouseleave', function() {jQuery('#dropdown').hide()})
  101. .bind('click', function() {jQuery('#dropdown').hide()});
  102. </script>