193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/jekyll-img-srcset.rb', line 193
def render(context)
config = context.registers[:site].config
base_image_path = config["base_image_path"] || "assets/images"
attrs = {
classes: [],
}
[/(\S+)="([^"]+?)"/, /(\S+)=([^\s\}"][^\s\}]+)/].each do | attr_regex |
@text.scan(attr_regex) do | key, value |
if key == "class"
context_content = check_in_context context, value
if context_content.nil?
attrs[:classes] << value
else
attrs[:classes] << context_content
end
else
context_content = check_in_context context, value
if context_content.nil?
attrs[key.to_sym] = value
else
attrs[key.to_sym] = context_content
end
end
end
end
if File.exists?(File.join base_image_path, attrs[:src])
widths, original_width = resize_image(
attrs[:src],
config["widths"],
config["destination"], base_image_path, cache)
context.registers[:site].keep_files.concat(widths.map do |w|
File.join(base_image_path, "#{w}", attrs[:src])
end)
format_image(attrs, widths, original_width,
attrs[:src], attrs[:caption], attrs[:title],
context.registers[:site].baseurl, base_image_path)
else
puts "image not found: #{File.join base_image_path, attrs[:src]} in page at url #{context["page"]["url"]}"
""
end
end
|