Class: View::Image
Overview
Makes an image tag. It also works with paperclip objects.
With paperclip, it also checks if the file was really uploaded.
This is actually longer than the regular Rails way. But the added benefit of this formatter comes from using it inside the table and definition list formatter.
Instance Attribute Summary
Attributes inherited from Formatter
Instance Method Summary (collapse)
- - (Boolean) file?
- - (Object) file_method
- - (Object) format
-
- (Object) options
The options for the image tag are in the :html option.
-
- (Object) path
Returns the path of the image, based on the path_methods and path_arguments configuration.
- - (Object) path_arguments
-
- (Object) path_method
TODO I'm only guessing here, I don't actually know how other upload gems work, besides paperclip.
Methods inherited from Formatter
#all_options, as, #format!, inherited, skip_blank_formatter, #to_s, type
Instance Method Details
- (Boolean) file?
68 69 70 |
# File 'lib/view/formatters/image.rb', line 68 def file? value.is_a?(String) || value.send(file_method) end |
- (Object) file_method
72 73 74 |
# File 'lib/view/formatters/image.rb', line 72 def file_method View.configuration.file_methods.find { |method| value.respond_to?(method) } end |
- (Object) format
34 35 36 |
# File 'lib/view/formatters/image.rb', line 34 def format template.image_tag(path, ) if file? end |
- (Object) options
The options for the image tag are in the :html option. You can use the default options to change them.
54 55 56 |
# File 'lib/view/formatters/image.rb', line 54 def super[:html] end |
- (Object) path
Returns the path of the image, based on the path_methods and path_arguments configuration.
40 41 42 43 44 45 46 |
# File 'lib/view/formatters/image.rb', line 40 def path if value.is_a?(String) value else value.send(path_method, *path_arguments) end end |
- (Object) path_arguments
64 65 66 |
# File 'lib/view/formatters/image.rb', line 64 def path_arguments [:style] || View.configuration.path_arguments end |
- (Object) path_method
TODO I'm only guessing here, I don't actually know how other upload gems work, besides paperclip.
60 61 62 |
# File 'lib/view/formatters/image.rb', line 60 def path_method View.configuration.path_methods.find { |method| value.respond_to?(method) } end |