Pharo by Example (vol 1)
repository·pharo5·Indexed 42 days ago
https://github.com/squarebracketassociates/updatedpharobyexampleA practical guide to the Pharo programming language and live coding environment. This repository contains an older version of the book as a collection of Pillar-formatted documentation files, including guidelines for contributions, Pillar image and code block syntax, and support for the sba-book LaTeX class.
What's inside Pharo by Example
- This repository contains an older version of the book. For the most up-to-date content, use Pharo by Example 9 at https://github.com/SquareBracketAssociates/NewPharoByExample9. You can also find PDF versions in the releases section of this repository.
How the Pharo Logo SVG is composed
pharo5The Pharo Logo SVG uses a nested group structure. The top-level
Pharo_Logocontains aPharo_Icon, which in turn contains aPharo_Beacon. ThePharo_Beaconis intended for use as a website favicon.SVG Hierarchy:
<g id="logo"> ... <g id="icon"> ... <g id="beacon"> ... </g> </g> </g>Quickstart: Use Highlight.js on a web page
pharo5To use Highlight.js on a web page, include the library, a CSS theme, and call
hljs.initHighlightingOnLoad(). The library will automatically find and highlight code inside<pre><code>tags by attempting to auto-detect the language.To explicitly specify a language when auto-detection fails, use the
classattribute on the<code>tag with the language name (e.g.,class="html") or use thelanguage-orlang-prefixes.To disable highlighting for a specific block, use the
nohighlightclass.<link rel="stylesheet" href="/path/to/styles/default.css"> <script src="/path/to/highlight.pack.js"></script> <script>hljs.initHighlightingOnLoad();</script> <!-- Explicit language --> <pre><code class="html">...</code></pre> <!-- Disable highlighting --> <pre><code class="nohighlight">...</code></pre>Add missing languages to CDN-hosted Highlight.js
pharo5The standard CDN-hosted package of Highlight.js does not include all languages to keep the file size small. If a required language is missing, you can manually include it by adding a script tag pointing to the specific language file from a CDN (e.g., cdnjs).
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/languages/go.min.js"></script>Manually initialize highlighting with highlightBlock and configure
pharo5For more control over what and when to highlight, use
hljs.highlightBlock(block)andhljs.configure(options). This allows you to target specific elements instead of relying on the automaticinitHighlightingOnLoad()behavior.If you are using a container that does not preserve line breaks, you can configure Highlight.js to use
<br>tags by settinguseBR: truein theconfiguremethod.// Example using jQuery to manually highlight blocks $(document).ready(function() { $('pre code').each(function(i, block) { hljs.highlightBlock(block); }); }); // Example with custom configuration for non-preserving containers hljs.configure({useBR: true}); $('div.code').each(function(i, block) { hljs.highlightBlock(block); });How to contribute to Updated Pharo By Example
pharo5Contributions follow the GitHub fork-and-pull workflow:
- Fork the repository.
- Create a topic branch using the naming convention:
initials_ChapterName_my_topic_description(e.g.,git checkout -b dz_PharoTour_update_screen_snapshots). - Commit your changes to that branch.
- Submit a Pull Request.
For detailed instructions on Pillar syntax and LaTeX setup, refer to the
CONTRIBUTING.mdfile in the repository. For technical questions, contact thepharo-devmailing list.Install Highlight.js via CDN or Module
pharo5Highlight.js can be used via CDN, downloaded as a custom build, or installed as a module on a server.
Important Notes:
- Do not link directly to GitHub source code. The library requires a specific build to function correctly.
- CDN limitations: CDN files do not include all languages to keep the file size small. If a language is missing, you can manually add it by including the specific language script (e.g.,
go.min.js) after the main library script. - Almond/Optimization: If using an optimizer like Almond, you must specify the module name (e.g.,
r.js -o name=hljs ...).
<!-- Adding a missing language from CDN --> <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.4.0/languages/go.min.js"></script># Example r.js command for optimization r.js -o name=hljs paths.hljs=/path/to/highlight out=highlight.jsUse the SBAbook LaTeX class
pharo5The
sbabookclass is built on thememoirdocument class and is designed for specific semantic markup and typographic styles.Important Requirements:
- Use LuaLaTeX as your compiler instead of
pdflatexto ensure fonts load correctly. - The class uses
polyglossiafor language settings, notbabel.
Basic preamble structure:
\documentclass{sbabook} \setmainlanguage{english} % this is polyglossia, not babel \begin{document} ...and off you go! \end{document}- Use LuaLaTeX as your compiler instead of
Create Pharo_Icon_v0.9.svg from pharo-logos.zip
pharo5To generate the
Pharo_Icon_v0.9.svgasset, follow this workflow involving Inkscape and manual optimization:- Setup:
- Download
pharo-logos.zipfromhttp://www.pharo-project.org/pharo-download/media-files. - Import
pharo-0.8.1.pdfinto Inkscape.
- Download
- Inkscape Processing:
- Ungroup all SVG elements.
- Recalculate relative to absolute coordinates.
- Split SVG elements if necessary (e.g., for the Pharo letter glare effect).
- (Re-)Group associated parts.
- Replace all bitmap parts with vector-only equivalents (specifically for the
shadow). - Reorganize references between shapes and color-gradients/filters to eliminate duplicates.
- Export from Inkscape without including Inkscape-specific XML elements or attributes.
- Optimization:
- Use the SVG Optimiser to shorten long coordinate system numbers (e.g., convert
25.772936550317932to25.77). - Use a UTF-8 capable text editor for final touches.
- Ensure SVG elements have descriptive ("speaking") names.
- Use the SVG Optimiser to shorten long coordinate system numbers (e.g., convert
- Icon-Specific Adjustments:
- Set
background'sfill-opacityto0. - Set
flare'sopacityto0.7(increased from0.5for better contrast). - Note:
water-splashesandflareof the icon-part will extend out of the stylized "o" (minimal intervention).
- Set
- Setup:
Quick Start with Highlight.js
pharo5To use Highlight.js on a web page with automatic language detection, link a style sheet, include the
highlight.pack.jslibrary, and callhljs.initHighlightingOnLoad(). This method automatically finds and highlights code within<pre><code>tags.If automatic detection fails, you can manually specify the language by adding a class to the
<code>tag using thelanguage-orlang-prefix (e.g.,class="language-html").To prevent a specific block from being highlighted, use the
nohighlightclass.<link rel="stylesheet" href="/path/to/styles/default.css"> <script src="/path/to/highlight.pack.js"></script> <script>hljs.initHighlightingOnLoad();</script> <!-- Manual language specification --> <pre><code class="html">...</code></pre> <!-- Disable highlighting --> <pre><code class="nohighlight">...</code></pre>General Documentation Style Guidelines
pharo5When contributing documentation, follow these formatting rules:
- Line Wrapping: Hard-wrap lines at 80 characters where possible (except for ordered/unordered list elements, which must remain on a single line for Pillar parsing).
- Spacing: Use exactly one space between sentences.
- Titles: Do not use periods in section titles.
- Inline Code: Use Pillar monospace notation
==Object==for all inline mentions of objects, messages, variables, or packages.
Run Highlight.js in a Web Worker
pharo5To prevent large code blocks from freezing the browser UI, you can offload the syntax highlighting process to a Web Worker.
Main Script Implementation: Listen for the
loadevent, select the code element, create a newWorker, and set up anonmessagehandler to update the element'sinnerHTMLwith the worker's result.Worker Script (
worker.js) Implementation: UseimportScriptsto loadhighlight.pack.js, then useself.hljs.highlightAuto(event.data)to process the text andpostMessagethe result back to the main thread.// In your main script addEventListener('load', function() { var code = document.querySelector('#code'); var worker = new Worker('worker.js'); worker.onmessage = function(event) { code.innerHTML = event.data; } worker.postMessage(code.textContent); }) // In worker.js onmessage = function(event) { importScripts('<path>/highlight.pack.js'); var result = self.hljs.highlightAuto(event.data); postMessage(result.value); }