Sha256: 583f28687cfb4f38c96b302c803ee8e6f1baf8239241b519d9e0cbfb25a1f202

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

module ActionView
  module TemplateHandlers
    class Rails3View < TemplateHandler
      include Compilable
      class TemplateDidNotReturnImage < RuntimeError #:nodoc:
      end

      def compile(template)
        <<-CODE
        @template_format = :flexi
        controller.response.content_type ||= Mime::JPG    
        result = #{template.source}
        requested_format = (params[:format] || :jpg).to_sym
        begin
          # Raise an error if object returned from template is not an image record
          unless result.class.include?(Fleximage::Model::InstanceMethods)
            raise TemplateDidNotReturnImage, ".flexi template was expected to return a model instance that acts_as_fleximage, but got an instance of instead."
          end
          # Figure out the proper format
          raise 'Image must be requested with an image type format.  jpg, gif and png only are supported.' unless [:jpg, :gif, :png].include?(requested_format)
          result.output_image(:format => requested_format)
        rescue Exception => e
          e
        end
        CODE
      ensure
        GC.start
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
tvdeyen-fleximage-1.0.7 lib/fleximage/rails3_view.rb
robinboening-fleximage-1.0.6 lib/fleximage/rails3_view.rb
tvdeyen-fleximage-1.0.5 lib/fleximage/rails3_view.rb