On Tue, Sep 27, 2011 at 10:02 AM, Dieter Vrancken <
[email protected]> wrote:

> We are filtering our resources with settings from the profile and it is
> great! The problem is that one of our devs added a png image to the
> resources directory. As the filter tries to interpolate variables into this
> binary file, it fails miserably. Are we not supposed to put binary files in
> our resources? That would be unfortunate!
>

Hi Dieter,

Yeah, that's a problem.  You can circumvent the problem by monkey-patching
the Mapper class, e.g.,

https://gist.github.com/1245748

module Buildr
  class Filter
    class Mapper

      alias_method :transform_old, :transform

      BINARY_FILES = [ '*.png', '*.gif' ]

      def is_binary?(content, path)
        BINARY_FILES.any? { |glob| File.fnmatch(glob, path) }
      end

      def transform(content, path = nil)
        return content if is_binary?(content, path)
        transform_old(content, path)
      end
    end
  end
end

I'll fix this in Buildr so the next release doesn't apply filter mappings
willy-nelly on binary files.  (BTW, do you have any suggestion on good
binary content detection?)

Thanks for bringing this up.

alex

Reply via email to