public
Description: Rails plugin for uploading images as resources, with support for resizing, text stamping, and other special effects.
Homepage: http://fleximage.rubyforge.org
Clone URL: git://github.com/Squeegy/fleximage.git
Added branch for rails 1.2 compatibility.  View handler now inherits form 
the new ActionView::TemplateHandler class to make things nice and DRY.
Squeegy (author)
Sun Apr 06 22:34:36 -0700 2008
commit  5b589906a68feabc145bf8f07deca2af6ecc1b5b
tree    2512841d916ba7bedb678e0a5bf3191d40c0aeb7
parent  dbc4b868d6d1aac50fd048364bb32c03b743b4ff
...
32
33
34
35
 
36
37
38
...
32
33
34
 
35
36
37
38
0
@@ -32,7 +32,7 @@ require 'fleximage/image_proxy'
0
 # Setup View
0
 require 'fleximage/view'
0
 ActionController::Base.exempt_from_layout :flexi
0
-ActionView::Base.register_template_handler :flexi, Fleximage::View
0
+ActionView::Template.register_template_handler :flexi, Fleximage::View
0
 
0
 # Register mime types
0
 Mime::Type.register "image/jpeg", :jpg
...
1
2
3
4
 
5
6
7
8
9
10
11
12
 
13
14
15
...
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
56
 
 
57
58
59
...
1
2
3
 
4
5
6
7
 
 
 
 
 
8
9
10
11
...
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
0
@@ -1,15 +1,11 @@
0
 module Fleximage
0
   
0
   # Renders a .flexi template
0
- class View #:nodoc:
0
+ class View < ActionView::TemplateHandler #:nodoc:
0
     class TemplateDidNotReturnImage < RuntimeError #:nodoc:
0
     end
0
     
0
- def initialize(view)
0
- @view = view
0
- end
0
-
0
- def render(template, local_assigns = {})
0
+ def render(template)
0
       # process the view
0
       result = @view.instance_eval do
0
         
0
@@ -22,38 +18,27 @@ module Fleximage
0
           end
0
         end
0
         
0
- # inject assigns into instance variables
0
- assigns.each do |key, value|
0
- instance_variable_set "@#{key}", value
0
- value.load_image if value.respond_to?(:load_image)
0
- end
0
-
0
- # inject local assigns into reader methods
0
- local_assigns.each do |key, value|
0
- class << self; self; end.send(:define_method, key) { val }
0
- end
0
-
0
         #execute the template
0
- eval(template)
0
+ eval(template.source)
0
       end
0
       
0
       # Raise an error if object returned from template is not an image record
0
       unless result.class.include?(Fleximage::Model::InstanceMethods)
0
- raise TemplateDidNotReturnImage, ".flexi template was expected to return a model instance that acts_as_fleximage, but got an instance of <#{result.class}> instead."
0
+ raise TemplateDidNotReturnImage,
0
+ ".flexi template was expected to return a model instance that acts_as_fleximage, but got an instance of <#{result.class}> instead."
0
       end
0
       
0
       # Figure out the proper format
0
       requested_format = (@view.params[:format] || :jpg).to_sym
0
- raise 'Image must be requested with an image type format. jpg, gif and png only are supported.' unless [:jpg, :gif, :png].include?(requested_format)
0
+ unless [:jpg, :gif, :png].include?(requested_format)
0
+ raise 'Image must be requested with an image type format. jpg, gif and png only are supported.'
0
+ end
0
       
0
       # Set proper content type
0
- @view.controller.headers["Content-Type"] = Mime::Type.lookup_by_extension(requested_format.to_s).to_s
0
-
0
- # get rendered result
0
- rendered_image = result.output_image(:format => requested_format)
0
+ @view.controller.response.content_type = Mime::Type.lookup_by_extension(requested_format.to_s).to_s
0
       
0
- # Return image data
0
- return rendered_image
0
+ # return rendered result
0
+ return result.output_image(:format => requested_format)
0
     ensure
0
     
0
       # ensure garbage collection happens after every flex image render

Comments

    No one has commented yet.