In most cases, you can extend Glyph just by creating your own custom macros. In some cases though, you may want to further customize Glyph to fit the needs of your project, in terms of creating custom commands and custom tasks.
Glyph’s modular architecture (and the Ruby language itself) lets you to add arbitrary functionality to its core, simply by creating a few Ruby files and putting them in the right places.
How Commands and Tasks work ⇈
Before creating custom Glyph commands and tasks, you should have a basic understanding on how they work, and which commands — or better, which tasks — are already available.
The following diagram outlines the relationships between the default commands and some tasks:
As you can see:
- All commands call at at least one task.
- There are several task inter-dependencies spanning across three main Rake namespaces:
project:— used for tasks affecting only the physical structure of the Glyph project.load:— used to load all kinds of files.generate:— used to generate files or copy files from source to output directories
Suppose you want to generate a PDF file by issuing the
glyph compile -f pdf command. Under the hood, Glyph calls the following tasks:
load:config— Load the configuration filesload:tasks— Load custom tasks (if any)load:commands— Load custom commands (if any)load:snippets— Load snippets from thesnippet.ymlfileload:macros— Load macrosload:all— Dummy task used to call the previous onesgenerate:document— Parse, analyze and finalize the Glyph documentgenerate:images— Copy images to the output directory (if any)generate:styles— Copy stylesheets to the output directory (if necessary)generate:html— Generate a standalone HTML filegenerate:pdf— Generate a PDF file from a standalone HTML file