Customizing the filters

When you select a file in TextMate, or when a file is referenced by an <img> tag in the html, Spanakopita can optionally run a helper program to convert the file into something viewable, such as HTML or a PNG image.  The programs that are used are completely customizable.  So you could easily add support for Markdown or some other filter.

The system used to select and configure these commands is going to change soon and will not be backwards compatible.  But this is how it works as of v1.2 in case you want to use it.  

When rendering a file, Spanakopita extracts its extension, converts it to lowercase, and checks the user's preferences for an entry for that extension type.  If no entry is found, then it checks for an entry called "DEFAULT".  If the default entry is also not defined, then the file is passed through "as is".

The entries are strings which can have one of the following forms:

RUN_STDIN <mime-type> <encoding> <program_name> <arguments...>
RUN <mime-type> <encoding> <program_name> <arguments...>
PASSTHROUGH

The first two forms run a helper command.  The argument must be an absolute path (use /usr/bin/env as the name of the program to search the user's path).  The arguments and program name may reference two variables:

${FILTERPY} is replaced with the path to the Spanakopita filter command, included in the bundle.

${PATH} is replaced with the path to the input.  

To change how Spanakopita handles a particular extension, you simply need to update the defaults entry for that extension.  For example, to modify Graphviz files (".dot") to emit png images instead of svg (which allows them to be scrolled), you would execute the following:

defaults write \
'com.macromates.textmate' \
'com.smallcultfollowing.Spanakopita:dot' \
'"RUN image/png UTF-8 /usr/local/bin/dot -T png ${PATH}"'

Note that the defaults domain was that of TextMate, and the key is prefixed with com.smallcultfollowing.Spanakopita:.  The default key is therefore com.smallcultfollowing.Spanakopita:DEFAULT.  This command simply says to run the dot command with the -T png option, and indicates that we should declare an image/png MIME type.

As I said, in the future I plan to update this system.  For one thing, I will add a GUI (the button is already present, but does nothing).  

Under the hood, the defaults will move into their own domain, and lose the prefix.  They will probably have more structure than simple strings, or at least have the option of more structure.  

Alternatively, I am considering making .spanakopitarc files where we search up the directory to tree to find the inner-most file with an entry for a particular extension.  This has the advantage of supporting per-project preferences, but it seems less "Mac-like".  

(c) 2010 Niko Matsakis