Class: Paperclip::Style
- Inherits:
-
Object
- Object
- Paperclip::Style
- Defined in:
- lib/paperclip/style.rb
Overview
The Style class holds the definition of a thumbnail style, applying whatever processing is required to normalize the definition and delaying the evaluation of block parameters until useful context is available.
Instance Attribute Summary collapse
-
#attachment ⇒ Object
readonly
Returns the value of attribute attachment.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Supports getting and setting style properties with hash notation to ensure backwards-compatibility eg.
- #[]=(key, value) ⇒ Object
- #convert_options ⇒ Object
-
#default_format ⇒ Object
defaults to default format (nil by default).
-
#geometry ⇒ Object
returns the geometry string for this style if a proc has been supplied, we call it here.
-
#initialize(name, definition, attachment) ⇒ Style
constructor
Creates a Style object.
-
#processor_options ⇒ Object
Supplies the hash of options that processors expect to receive as their second argument Arguments other than the standard geometry, format etc are just passed through from initialization and any procs are called here, just before post-processing.
-
#processors ⇒ Object
retrieves from the attachment the processors defined in the has_attached_file call (which method (in the attachment) will call any supplied procs) There is an important change of interface here: a style rule can set its own processors by default we behave as before, though.
- #source_file_options ⇒ Object
-
#whiny ⇒ Object
retrieves from the attachment the whiny setting.
-
#whiny? ⇒ Boolean
returns true if we’re inclined to grumble.
Constructor Details
#initialize(name, definition, attachment) ⇒ Style
Creates a Style object. name
is the name of the attachment, definition
is the style definition from has_attached_file, which can be string, array or hash
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/paperclip/style.rb', line 12 def initialize(name, definition, ) @name = name @attachment = if definition.is_a? Hash @geometry = definition.delete(:geometry) @format = definition.delete(:format) @processors = definition.delete(:processors) @convert_options = definition.delete(:convert_options) @source_file_options = definition.delete(:source_file_options) @other_args = definition elsif definition.is_a? String @geometry = definition @format = nil @other_args = {} else @geometry, @format = [definition, nil].flatten[0..1] @other_args = {} end @format = default_format if @format.blank? end |
Instance Attribute Details
#attachment ⇒ Object (readonly)
Returns the value of attribute attachment.
7 8 9 |
# File 'lib/paperclip/style.rb', line 7 def @attachment end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
7 8 9 |
# File 'lib/paperclip/style.rb', line 7 def format @format end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/paperclip/style.rb', line 7 def name @name end |
Instance Method Details
#[](key) ⇒ Object
Supports getting and setting style properties with hash notation to ensure backwards-compatibility eg. @attachment.styles[:geometry]@ will still work
84 85 86 87 88 89 90 |
# File 'lib/paperclip/style.rb', line 84 def [](key) if [:name, :convert_options, :whiny, :processors, :geometry, :format, :animated, :source_file_options].include?(key) send(key) elsif defined? @other_args[key] @other_args[key] end end |
#[]=(key, value) ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/paperclip/style.rb', line 92 def []=(key, value) if [:name, :convert_options, :whiny, :processors, :geometry, :format, :animated, :source_file_options].include?(key) send("#{key}=".intern, value) else @other_args[key] = value end end |
#convert_options ⇒ Object
52 53 54 55 |
# File 'lib/paperclip/style.rb', line 52 def @convert_options.respond_to?(:call) ? @convert_options.call(.instance) : (@convert_options || .send(:extra_options_for, name)) end |
#default_format ⇒ Object
defaults to default format (nil by default)
101 102 103 104 |
# File 'lib/paperclip/style.rb', line 101 def default_format base = .[:default_format] base.respond_to?(:call) ? base.call(, name) : base end |
#geometry ⇒ Object
returns the geometry string for this style if a proc has been supplied, we call it here
64 65 66 |
# File 'lib/paperclip/style.rb', line 64 def geometry @geometry.respond_to?(:call) ? @geometry.call(.instance) : @geometry end |
#processor_options ⇒ Object
Supplies the hash of options that processors expect to receive as their second argument Arguments other than the standard geometry, format etc are just passed through from initialization and any procs are called here, just before post-processing.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/paperclip/style.rb', line 71 def args = { style: name } @other_args.each do |k, v| args[k] = v.respond_to?(:call) ? v.call() : v end [:processors, :geometry, :format, :whiny, :convert_options, :source_file_options].each do |k| (arg = send(k)) && args[k] = arg end args end |
#processors ⇒ Object
retrieves from the attachment the processors defined in the has_attached_file call (which method (in the attachment) will call any supplied procs) There is an important change of interface here: a style rule can set its own processors by default we behave as before, though. if a proc has been supplied, we call it here
38 39 40 |
# File 'lib/paperclip/style.rb', line 38 def processors @processors.respond_to?(:call) ? @processors.call(.instance) : (@processors || .processors) end |
#source_file_options ⇒ Object
57 58 59 60 |
# File 'lib/paperclip/style.rb', line 57 def @source_file_options.respond_to?(:call) ? @source_file_options.call(.instance) : (@source_file_options || .send(:extra_source_file_options_for, name)) end |
#whiny ⇒ Object
retrieves from the attachment the whiny setting
43 44 45 |
# File 'lib/paperclip/style.rb', line 43 def whiny .whiny end |
#whiny? ⇒ Boolean
returns true if we’re inclined to grumble
48 49 50 |
# File 'lib/paperclip/style.rb', line 48 def whiny? !!whiny end |