Class: Fleximage::Rails3View

Inherits:
Object
  • Object
show all
Defined in:
lib/fleximage/rails3_view.rb

Defined Under Namespace

Classes: TemplateDidNotReturnImage

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(template) ⇒ Object



7
8
9
# File 'lib/fleximage/rails3_view.rb', line 7

def self.call(template)
  self.new.compile(template)
end

Instance Method Details

#compile(template) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fleximage/rails3_view.rb', line 11

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