Class: Configuration::Thumbnail::ThumbnailSpec
- Inherits:
-
HandlerStatement
- Object
- Scope
- HandlerStatement
- Configuration::Thumbnail::ThumbnailSpec
- Includes:
- ConditionalInclusion, ImageName, LocalConfiguration
- Defined in:
- lib/httpimagestore/configuration/thumbnailer.rb
Defined Under Namespace
Classes: EditSpec
Instance Method Summary collapse
-
#initialize(image_name, method, width, height, format, options = {}, edits = []) ⇒ ThumbnailSpec
constructor
A new instance of ThumbnailSpec.
- #render(request_state = {}) ⇒ Object
Methods inherited from Scope
node_parsers, #parse, register_node_parser
Constructor Details
#initialize(image_name, method, width, height, format, options = {}, edits = []) ⇒ ThumbnailSpec
Returns a new instance of ThumbnailSpec.
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/httpimagestore/configuration/thumbnailer.rb', line 125 def initialize(image_name, method, width, height, format, = {}, edits = []) with_image_name(image_name) @method = method.to_template.with_missing_resolver{|locals, key| raise NoValueForSpecTemplatePlaceholderError.new(image_name, 'method', key, method)} @width = width.to_s.to_template.with_missing_resolver{|locals, key| raise NoValueForSpecTemplatePlaceholderError.new(image_name, 'width', key, width)} @height = height.to_s.to_template.with_missing_resolver{|locals, key| raise NoValueForSpecTemplatePlaceholderError.new(image_name, 'height', key, height)} @format = format.to_template.with_missing_resolver{|locals, key| raise NoValueForSpecTemplatePlaceholderError.new(image_name, 'format', key, format)} @options = .merge() do |option, old, template| template.to_s.to_template.with_missing_resolver{|locals, field| raise NoValueForSpecTemplatePlaceholderError.new(image_name, option, field, template)} end @edits = edits end |
Instance Method Details
#render(request_state = {}) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/httpimagestore/configuration/thumbnailer.rb', line 139 def render(request_state = {}) = @options.inject({}){|h, v| h[v.first] = v.last.render(request_state); h} # NOTE: normally options will be passed as options=String; but may be supplied each by each as in the configuration with key=value pairs = begin opts = .delete('options') || '' HTTPThumbnailerClient::ThumbnailSpec.(HTTPThumbnailerClient::ThumbnailSpec.split_args(opts)) rescue HTTPThumbnailerClient::ThumbnailSpec::InvalidFormatError => error raise InvalidOptionsSpecError.new(image_name, opts, error) end edits_option = HTTPThumbnailerClient::ThumbnailSpec.split_edits(.delete('edits') || '').map do |edit| begin HTTPThumbnailerClient::ThumbnailSpec::EditSpec.from_string(edit) rescue HTTPThumbnailerClient::ThumbnailSpec::InvalidFormatError => error raise InvalidEditsSpecError.new(image_name, edit, error) end end edits = @edits.select do |edit| edit.included?(request_state) end.map do |edit| edit.render(request_state) end spec = begin HTTPThumbnailerClient::ThumbnailSpec.new( @method.render(request_state), @width.render(request_state), @height.render(request_state), @format.render(request_state), .merge(), edits | edits_option ) rescue HTTPThumbnailerClient::ThumbnailSpec::InvalidFormatError => error raise InvalidSpecError.new(image_name, error) end Struct.new(:name, :spec).new(image_name, spec) end |