diff --git a/app/models/spree/image.rb b/app/models/spree/image.rb index 945b1ef11f..ded26d20fd 100644 --- a/app/models/spree/image.rb +++ b/app/models/spree/image.rb @@ -46,5 +46,27 @@ module Spree false end end + + # Spree stores attachent definitions in JSON. This converts the style name and format to + # strings. However, when paperclip encounters these, it doesn't recognise the format. + # Here we solve that problem by converting format and style name to symbols. + # See also: ImageSettingsController decorator. + # + # eg. {'mini' => ['48x48>', 'png']} is converted to {mini: ['48x48>', :png]} + def self.format_styles(styles) + styles_a = styles.map do |name, style| + style[1] = style[1].to_sym if style.is_a? Array + [name.to_sym, style] + end + + Hash[styles_a] + end + + def self.reformat_styles + Spree::Image.attachment_definitions[:attachment][:styles] = + format_styles(Spree::Image.attachment_definitions[:attachment][:styles]) + end + + reformat_styles end end diff --git a/app/models/spree/image_decorator.rb b/app/models/spree/image_decorator.rb deleted file mode 100644 index 7d86aae3a6..0000000000 --- a/app/models/spree/image_decorator.rb +++ /dev/null @@ -1,23 +0,0 @@ -Spree::Image.class_eval do - # Spree stores attachent definitions in JSON. This converts the style name and format to - # strings. However, when paperclip encounters these, it doesn't recognise the format. - # Here we solve that problem by converting format and style name to symbols. - # See also: ImageSettingsController decorator. - # - # eg. {'mini' => ['48x48>', 'png']} is converted to {mini: ['48x48>', :png]} - def self.format_styles(styles) - styles_a = styles.map do |name, style| - style[1] = style[1].to_sym if style.is_a? Array - [name.to_sym, style] - end - - Hash[styles_a] - end - - def self.reformat_styles - Spree::Image.attachment_definitions[:attachment][:styles] = - format_styles(Spree::Image.attachment_definitions[:attachment][:styles]) - end - - reformat_styles -end