class Middleman::ImageUploaderTag::CloudinaryCDN
Constants
- OBLIGATORY_OPTIONS
Public Class Methods
new(config)
click to toggle source
# File lib/middleman/image-uploader-tag/cdns/cloudinary.rb, line 9 def initialize(config) raise AuthorizationRequired if OBLIGATORY_OPTIONS.any? { |k| config[k].nil? } Cloudinary.config do |c| config.each { |key, value| c.public_send(:"#{key}=", value) unless value.nil? } end end
Public Instance Methods
get_remote_link(image_path, secure = false)
click to toggle source
# File lib/middleman/image-uploader-tag/cdns/cloudinary.rb, line 17 def get_remote_link(image_path, secure = false) raise NotFound if !image_path || !File.exist?(image_path.to_s) image_attributes = upload_to_cloud(image_path) secure ? image_attributes[:secure_url] : image_attributes[:url] end
upload_to_cloud(file, options = {})
click to toggle source
# File lib/middleman/image-uploader-tag/cdns/cloudinary.rb, line 24 def upload_to_cloud(file, options = {}) # rescue Cloudinary exceptions? (timeouts, limits and so on..) raise NotFound if !file || !File.exist?(file.to_s) options.merge!({ use_filename: true, unique_filename: false }) Cloudinary::Uploader.upload(file, options).inject({}) do |memo, (k,v)| memo[k.to_sym] = v memo end end