Glyph 0.3.0 Released

The third release of the Glyph Authoring Framework features dramatic speed improvements, and much more

The third release of Glyph is out!

For those checking it out for the first time, Glyph is a Rapid Document Authoring Framework focused on extensibility and content reuse. For an example of what Glyph can do, have a look at Glyph's free PDF book.

This release brings more stability to Glyph, more speed, and features affecting Glyph's core functionality. As a consequence, some incompatibilities had to be introduced – but after all, better now than later.

New parser and performance improvements

This release's big news is the brand new Glyph Parser. Until this release, Glyph relied on the awesome Treetop library for parsing Glyph language. Treetop is great when it comes to creating language parsers effortlessly, but it can add quite a bit of an overhead especially when using dot star patterns.

So I ran a few benchmarks and in the end decided to write my very own (first!) parser from scratch using just the StringScanner class, which is part of Ruby Standard Library. It took me a bit to get used to it, but in the end I managed to create something able to produce an Abstract Syntax Tree exactly the way I wanted.

After adding the new parser, Glyph became significantly faster. This doesn't mean it's as fast as, say, RedCloth, but I it can be used to process long books in just a few seconds rather than minutes.

Macro Attributes

Glyph now supports named attributes as well as positional parameters. This is particularly handy when you want to create macros with a lot of optional arguments: in this case, positional parameters are not great. As a result, for example, the section macro now takes an optional title and id attributes, rather than two parameters

Attributes look like macros, but they all start with a @ character. For example, see the the following image, showing this very section:

Full XML support

Once macro attributes became available at parser level, having Glyph to produce arbitrary XML code became extremely easy. By default, now if Glyph doesn't find a macro it assumes you're inputting an XML tag of some kind, so you can write:

1p[This is a paragraph with some em[emphasized] text.]
2img[
3  @alt[Glyph Code]
4  @width[50%]
5  @height[50%]
6  @src[glyph_code.png]
7]

And get the following HTML code back:

1<p>This is a paragraph with some <em>emphasized</em> text.</p>
2<img 
3  alt="Glyph Code"
4  width="50%"
5  height="60%"
6  src="glyph_code.png"  
7/>

...and none of the macros used in the previosu Glyph code snippet are actually defined in Glyph. Among other things, this means that you don't have to use Textile or Markup within your Glyph code unless you absolutely need to (e.g. for lists, which would be a bit verbose to create using just Glyph markup).

Improved include macro and "safe mode"

The include macro now must take an path to a file relative to the text/ directory of your project, or it can also be used to include (and evaluate) ruby code within your lib/ directory. Moreover, you can now use the include macro even when compiling single Glyph files.

Now, while evaluating Ruby code in an external file can be quite handy, is also quite insecure. For this reason, it is now possible to use Glyph programmatically in "safe mode", thereby forbidding the usage of certain unsafe macros.

What's next?

Sooner or later I'll have to implement support for generating multiple files in output. This would make it possible to make the Glyph book available online as a collection of separate HTML file, for example, or, later on, maybe even compiled into a (ugh!) CHM file.

Additionally, HTML5 support is also on the horizon: given the current Glyph architecture, it will be relatively easy to have Glyph macros to produce HTML5 code instead of XHTML. LaTeX support, on the other hand, is a completely different game, mainly because I'm not familiar with it, so if anyone feels creative and would like an easier way to produce reusable LaTeX code, get forking and contact me!