16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/fleximage/view.rb', line 16
def render(template)
result = @view.instance_eval do
def color(*args)
Fleximage::Operator::Base.color(*args)
end
eval(template.source)
end
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 <#{result.class}> instead."
end
requested_format = (@view.params[:format] || :jpg).to_sym
unless [:jpg, :gif, :png].include?(requested_format)
raise 'Image must be requested with an image type format. jpg, gif and png only are supported.'
end
@view.controller.response.content_type = Mime::Type.lookup_by_extension(requested_format.to_s).to_s
if defined?(Rails) && Rails.env == 'production'
@view.controller.response.['Cache-Control'] = 'public, max-age=86400'
end
return result.output_image(:format => requested_format)
ensure
GC.start
end
|