all repos — h3rald @ 22c6126ca58625f1f2cfa8a5000f2d3315b304f3

The sources of https://h3rald.com

content/articles/glyph-030-released.glyph

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
----- 
:type: article
:tags: 
- glyph
- ruby
- opensource
:permalink: glyph-030-released
:title: "Glyph 0.3.0 Released"
:subtitle: The third release of the Glyph Authoring Framework features dramatic speed improvements, and much more
:toc: true
:date: 2010-06-13 14:10:00.000000 +02:00
:intro: |
  The third release of "Glyph":/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":http://github.com/downloads/h3rald/glyph/glyph.pdf.

  This release brings more stability to Glyph, more speed, and features affecting Glyph's core functionality. As a consequence, some "incompatibilities":http://github.com/h3rald/glyph/issues/closed#issue/121 had to be introduced – but after all, better now than later. 
-----
&:[yardoc|http://yardoc.org/docs/h3rald-glyph]
&:[book|http://github.com/downloads/h3rald/glyph/glyph.pdf]

p[The third release of =>[$[site.root]/glyph/|Glyph] is out!] 

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

p[This release brings more stability to Glyph, more speed, and features affecting Glyph's core functionality. As a consequence, some =>[http://github.com/h3rald/glyph/issues/closed#issue/121|incompatibilities] had to be introduced – but after all, better now than later.] 

section[
	@title[New parser and performance improvements]

	p[This release's big news is the brand new =>[&[yardoc]/glyph/parser|Glyph Parser]. Until this release, Glyph relied on the awesome =>[http://treetop.rubyforge.org/|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 =>[http://groups.google.com/group/treetop-dev/browse_thread/thread/15ff7659b2efbeed|dot star] patterns.]

	p[So I ran a few benchmarks and in the end decided to write my very own (first!) parser from scratch using just the =>[http://ruby-doc.org/core/classes/StringScanner.html|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.]

	p[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 em[seconds] rather than em[minutes].]
]

section[
	@title[Macro Attributes]

	p[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 code[section] macro now takes an optional code[title] and code[id] attributes, rather than two parameters]
	
	p[Attributes look like macros, but they all start with a code[@] character. For example, see the the following image, showing this very section:]
	
	image[\/$[site.root]/img/pictures/updated_glyph_syntax.png]
]

section[
	@title[Full XML support]
	
	p[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:]

	highlight[=html|
p[This is a paragraph with some em[emphasized] text.]
img[
  @alt[Glyph Code]
  @width[50%]
  @height[50%]
  @src[glyph_code.png]
]
	=]

	p[And get the following HTML code back:]
	
	highlight[=html|
<p>This is a paragraph with some <em>emphasized</em> text.</p>
<img 
  alt="Glyph Code"
  width="50%"
  height="60%"
  src="glyph_code.png"  
/>
	=]

  p[...and none of the macros used in the previosu Glyph code snippet are actually defined in Glyph. Among other things, this means that em[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).]
]

section[
	@title[Improved code[include] macro and "safe mode"]

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

	p[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 em[unsafe] macros.]
]

section[
	@title[What's next?]

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

	p[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, =>[http://github.com/h3rald/glyph/|get forking] and contact me!]
]