Class: Configuration::Thumbnail::ThumbnailSpec

Inherits:
HandlerStatement show all
Includes:
ConditionalInclusion, ImageName
Defined in:
lib/httpimagestore/configuration/thumbnailer.rb

Instance Attribute Summary

Attributes inherited from HandlerStatement

#config_locals

Instance Method Summary collapse

Methods inherited from HandlerStatement

#config_local, #path_template

Constructor Details

#initialize(image_name, method, width, height, format, options = {}, matcher = nil) ⇒ ThumbnailSpec

Returns a new instance of ThumbnailSpec.



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/httpimagestore/configuration/thumbnailer.rb', line 68

def initialize(image_name, method, width, height, format, options = {}, matcher = nil)
  super(nil, image_name, matcher)
  @method = method.to_template.with_missing_resolver{|locals, key| raise NoValueForSpecTemplatePlaceholerError.new(image_name, 'method', key, method)}
  @width =  width.to_s.to_template.with_missing_resolver{|locals, key| raise NoValueForSpecTemplatePlaceholerError.new(image_name, 'width', key, width)}
  @height = height.to_s.to_template.with_missing_resolver{|locals, key| raise NoValueForSpecTemplatePlaceholerError.new(image_name, 'height', key, height)}
  @format = format.to_template.with_missing_resolver{|locals, key| raise NoValueForSpecTemplatePlaceholerError.new(image_name, 'format', key, format)}

  @options = options.merge(options) do |option, old, template|
    template.to_s.to_template.with_missing_resolver{|locals, field| raise NoValueForSpecTemplatePlaceholerError.new(image_name, option, field, template)}
  end
end

Instance Method Details

#render(locals = {}) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/httpimagestore/configuration/thumbnailer.rb', line 80

def render(locals = {})
  options = @options.inject({}){|h, v| h[v.first] = v.last.render(locals); h}
  nested_options = options['options'] ? Hash[options.delete('options').to_s.split(',').map{|pair| pair.split(':', 2)}] : {}
  {
    image_name =>
      [
        @method.render(locals),
        @width.render(locals),
        @height.render(locals),
        @format.render(locals),
        nested_options.merge(options)
      ]
  }
end