The Structure
Static >> The StructureOne of the major benefits of static is the ability to seperate the content and structure of a site. Using rbml as the xhtml processor, we have what I think is a great html replacement with some nice ability to use partials to make the page sections understandable at a glance.
This page serves as a brief explanation of some of the particulars of the system in general, while the base and blueprint sections will focus more on function and use of those individual folders.
Pre-xhtml Site Reprentation with rbml
To be brief, rbml is some code that recursively runs blocks. In the html module, rbml expects that normal tags either recieve a hash which will be included as html options or a string of text to go inside the tag.
Some Basic rbml for xhtml
div(:class => 'ex' :id => 'ample'){
ul{
li 'text may be inserted in elements like this
if there is no class, id, or elements within'
li(:class => 'other'){
i 'otherwise, plain text may be inserted like this'
}
li(:class => 'other'){
t 'while textile text can be inserted like this'
}
}
}
Partials Are Key
An element of a site generator that I thought to be ultimately important is the ability to effectively use partials. There are three places that a partial may come from: :base, :page, and the file_name of a particular page as described in the site map. Additionally, there are two types of sub sections that may be addressed: files named with and without a leading underscore.
get vs. partial
- to process the file _submenu.rbml within a given page you would use
partial :page, :submenu
- this is exactly equivalent to
get :page, :_submenu
Location Location Location…
In deciding how to address partials i determined that one should be able to indicate where the file is coming from in a simple way as well as the name of the file to be included. Three spaces were formed and are addressed as the first argument of both get and partial
Oh the Places You’ll Go
- :base
- Indicates a site-wide file coming from the base/ directory as described in the site map
- :page
- Indicates the page currently being processed. This can be seen in use when getting the main contents of a page as described in the base.
- :file_name
- :file_name is not actually a ‘place’ you can go. Instead this refers to a specific page’s file name as described in the site map.
The Generator
Rbml, as wonderous as it is, has some major downsides. For one thing, outside of using some sort of global, it is at this point impossible to send external information to a file being processed. For this reason the Generator singleton was born.
The Generator has one object that it can act_on and a stack of supporting actors that is added to each time a new object is loaded. In this way it is possible to use a singleton to talk about the appropriate current object through Generator.act_on. The obvious downside to this is that it is often difficult to tell exactly what the object to be acted on is, though by convention the Generator’s scope and that of the rbml document it is addressed in are the same. If there is confusion, I suggest trying puts Generator.act_on.inspect in the file in question.
Practically speaking this means that while in a page’s blueprint the Generator’s act_on method will correspond with that page’s instance, having access to all of its attributes and methods, whatever those might be.
As an additional note (and a possible bad idea) the method missing for the Generator sends the method in question to act_on. Because of this you can address the Generator directly for some methods, though at the very least name, home and inspect are in conflict and require being addressed through act_on