sysgears/grain

Customizing resource mapping to add new binary types

marshallpierce opened this issue · 2 comments

I I have non-image assets that are treated as binary files (pdfs, for instance). I'm not seeing how to customize resource mapping to make that happen.

I see that DefaultConfig.groovy (in grain itself) has a 'binary_files" var that appears to control what the default binary files are. It'd be nice to simply add another regex to that, but it's not clear how to do so.

I've tried customizing the ResourceMapper in the theme (I'm using the template theme) but my code doesn't appear to be being hit. I've tried logging and even throwing exceptions from inside ResourceMapper but nothing seems to produce any visible effect.

Here's the error I'm seeing:

Caused by: com.sysgears.grain.render.RenderException: Failed to parse /home/mbp/dev/piercelab/grain-theme-template/theme/......./filename.pdf script: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
GrainScript7.groovy: 415: unexpected char: 0x11 @ line 415, column 99.

   �7����K�����A����
                    ���:${<6���

Please check Configuration -> Filesystem Layout section of Grain documentation:
http://sysgears.com/grain/docs/latest/#filesystem-layout

You can override binary_files in SiteConfig.groovy, i.e. you can have the line like that in SiteConfig.groovy:

binary_files += [/(?i).*.(pdf)$/]

That worked, thanks!

When I applied the change at first, the grain preview server continued to throw exceptions when serving pdfs; it seems that I had to clean first. For my own curiosity, why was a clean necessary?