Module: JekyllIS::Images::Image::Transform
- Extended by:
- Transform
- Included in:
- JekyllIS::Images::Image, Transform
- Defined in:
- lib/jekyll-is/images/image/transform.rb
Instance Method Summary collapse
Methods included from Magick
#magick_convert, #magick_generate
Methods included from Cache
#cached_file, #clean_unused_files, #magick_image, #restore_static_files, #source_digest, #static_info
Instance Method Details
#transform(context, source, params) ⇒ JekyllIS::Images::Image::Info
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jekyll-is/images/image/transform.rb', line 21 def transform context, source, params # Проверяем на assets, возвращаем как есть, если так. return JekyllIS::Images::Image::Info[source, nil, nil] if assets?(source) digest = source_digest(context, source, **params) static_info context, digest, params[:format] do |full| source_path = if external?(source) # Скачиваем. Если не удается скачать, возвращаем url как есть без дополнительных данных. # Исходим из того, что проблемы со скачиванием могут быть временными. load_digest = source_digest context, source, **params.slice(:salt) source_format = source&.split('#')&.first&.split('?')&.first&.split('.')&.last&.downcase loaded, _, _ = cached_file(context, TMP, load_digest, '.' + source_format) do |target| download_file context, source, target end if loaded loaded else context.warning "Failed download #{ source.inspect } on page #{ context.page.relative_path.inspect }" return JekyllIS::Images::Image::Info[source, nil, nil] end else context.site.in_source_dir source end if params[:format] == 'svg' convert_svg context, source_path, full, params else convert_image context, source_path, full, params end end rescue => ex context.error "Error with file #{ source.inspect } on page #{ context.page.relative_path.inspect }: #{ ex.inspect }" end |