Module: CloudinaryHelper
- Includes:
- ActionView::Helpers::AssetTagHelper
- Defined in:
- lib/cloudinary/helper.rb
Constant Summary collapse
- CLOUDINARY_JS_CONFIG_PARAMS =
[:api_key, :cloud_name, :private_cdn, :secure_distribution, :cdn_subdomain]
Class Method Summary collapse
Instance Method Summary collapse
-
#cl_form_tag(callback_url, options = {}, &block) ⇒ Object
cl_form_tag was originally contributed by Milovan Zogovic.
- #cl_image_path(source, options = {}) ⇒ Object
-
#cl_image_tag(source, options = {}) ⇒ Object
Examples cl_image_tag “israel.png”, :width=>100, :height=>100, :alt=>“hello” # W/H are not sent to cloudinary cl_image_tag “israel.png”, :width=>100, :height=>100, :alt=>“hello”, :crop=>:fit # W/H are sent to cloudinary.
- #cl_image_upload(object_name, method, options = {}) ⇒ Object
- #cl_image_upload_tag(field, options = {}) ⇒ Object
- #cl_private_download_url(public_id, format, options = {}) ⇒ Object
- #cl_signed_download_url(public_id, options = {}) ⇒ Object
- #cl_sprite_tag(source, options = {}) ⇒ Object
- #cl_sprite_url(source, options = {}) ⇒ Object
- #cl_zip_download_url(tag, options = {}) ⇒ Object
- #cloudinary_js_config ⇒ Object
- #cloudinary_url(source, options = {}) ⇒ Object
- #facebook_profile_image_path(profile, options = {}) ⇒ Object
- #facebook_profile_image_tag(profile, options = {}) ⇒ Object
- #fetch_image_tag(profile, options = {}) ⇒ Object
- #gplus_profile_image_path(profile, options = {}) ⇒ Object
- #gplus_profile_image_tag(profile, options = {}) ⇒ Object
- #gravatar_profile_image_path(email, options = {}) ⇒ Object
- #gravatar_profile_image_tag(email, options = {}) ⇒ Object
- #image_path(*args) ⇒ Object
- #image_tag(*args) ⇒ Object
- #original_image_path ⇒ Object
- #original_image_tag ⇒ Object
- #twitter_name_profile_image_path(profile, options = {}) ⇒ Object
- #twitter_name_profile_image_tag(profile, options = {}) ⇒ Object
- #twitter_profile_image_path(profile, options = {}) ⇒ Object
- #twitter_profile_image_tag(profile, options = {}) ⇒ Object
Class Method Details
.included(base) ⇒ Object
187 188 189 |
# File 'lib/cloudinary/helper.rb', line 187 def self.included(base) ActionView::Helpers::FormBuilder.send(:include, Cloudinary::FormBuilder) end |
Instance Method Details
#cl_form_tag(callback_url, options = {}, &block) ⇒ Object
cl_form_tag was originally contributed by Milovan Zogovic
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/cloudinary/helper.rb', line 109 def cl_form_tag(callback_url, ={}, &block) = .delete(:form) || {} [:method] = :post [:multipart] = true params = Cloudinary::Uploader.build_upload_params(.merge(:callback=>callback_url)) params[:signature] = Cloudinary::Utils.api_sign_request(params, Cloudinary.config.api_secret) params[:api_key] = Cloudinary.config.api_key api_url = Cloudinary::Utils.cloudinary_api_url("upload", {:resource_type => .delete(:resource_type), :upload_prefix => .delete(:upload_prefix)}) form_tag(api_url, ) do content = [] params.each do |name, value| content << hidden_field_tag(name, value, :id => nil) if value.present? end content << capture(&block) content.join("\n").html_safe end end |
#cl_image_path(source, options = {}) ⇒ Object
21 22 23 24 25 |
# File 'lib/cloudinary/helper.rb', line 21 def cl_image_path(source, = {}) = .clone url = cloudinary_url(source, ) original_image_path(url) end |
#cl_image_tag(source, options = {}) ⇒ Object
Examples cl_image_tag “israel.png”, :width=>100, :height=>100, :alt=>“hello” # W/H are not sent to cloudinary cl_image_tag “israel.png”, :width=>100, :height=>100, :alt=>“hello”, :crop=>:fit # W/H are sent to cloudinary
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cloudinary/helper.rb', line 10 def cl_image_tag(source, = {}) = .clone source = cloudinary_url(source, ) [:width] = .delete(:html_width) if .include?(:html_width) [:height] = .delete(:html_height) if .include?(:html_height) [:size] = .delete(:html_size) if .include?(:html_size) [:border] = .delete(:html_border) if .include?(:html_border) original_image_tag(source, ) end |
#cl_image_upload(object_name, method, options = {}) ⇒ Object
150 151 152 |
# File 'lib/cloudinary/helper.rb', line 150 def cl_image_upload(object_name, method, ={}) cl_image_upload_tag("#{object_name}[#{method}]", ) end |
#cl_image_upload_tag(field, options = {}) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/cloudinary/helper.rb', line 154 def cl_image_upload_tag(field, ={}) = .delete(:html) || {} cloudinary_upload_url = Cloudinary::Utils.cloudinary_api_url("upload", {:resource_type=>:auto}.merge()) api_key = [:api_key] || Cloudinary.config.api_key || raise(CloudinaryException, "Must supply api_key") api_secret = [:api_secret] || Cloudinary.config.api_secret || raise(CloudinaryException, "Must supply api_secret") cloudinary_params = Cloudinary::Uploader.build_upload_params() cloudinary_params[:callback] = build_callback_url() cloudinary_params[:signature] = Cloudinary::Utils.api_sign_request(cloudinary_params, api_secret) cloudinary_params[:api_key] = api_key = .merge(:type=>"file", :name=>"file", :"data-url"=>cloudinary_upload_url, :"data-form-data"=>cloudinary_params.reject{|k, v| v.blank?}.to_json, :"data-cloudinary-field"=>field, :"class" => [[:class], "cloudinary-fileupload"].flatten.compact ).reject{|k,v| v.blank?} content_tag("input", nil, ) end |
#cl_private_download_url(public_id, format, options = {}) ⇒ Object
175 176 177 |
# File 'lib/cloudinary/helper.rb', line 175 def cl_private_download_url(public_id, format, = {}) Cloudinary::Utils.private_download_url(public_id, format, ) end |
#cl_signed_download_url(public_id, options = {}) ⇒ Object
183 184 185 |
# File 'lib/cloudinary/helper.rb', line 183 def cl_signed_download_url(public_id, = {}) Cloudinary::Utils.signed_download_url(public_id, ) end |
#cl_sprite_tag(source, options = {}) ⇒ Object
104 105 106 |
# File 'lib/cloudinary/helper.rb', line 104 def cl_sprite_tag(source, = {}) stylesheet_link_tag(cl_sprite_url(source, )) end |
#cl_sprite_url(source, options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/cloudinary/helper.rb', line 89 def cl_sprite_url(source, = {}) = .clone version_store = .delete(:version_store) if [:version].blank? && (version_store == :file) && defined?(Rails) && defined?(Rails.root) file_name = "#{Rails.root}/tmp/cloudinary/cloudinary_sprite_#{source.sub(/\..*/, '')}.version" if File.exists?(file_name) [:version] = File.read(file_name).chomp end end [:format] = "css" unless source.ends_with?(".css") cloudinary_url(source, .merge(:type=>:sprite)) end |
#cl_zip_download_url(tag, options = {}) ⇒ Object
179 180 181 |
# File 'lib/cloudinary/helper.rb', line 179 def cl_zip_download_url(tag, = {}) Cloudinary::Utils.zip_download_url(tag, ) end |
#cloudinary_js_config ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/cloudinary/helper.rb', line 135 def cloudinary_js_config params = {} CLOUDINARY_JS_CONFIG_PARAMS.each do |param| value = Cloudinary.config.send(param) params[param] = value if !value.nil? end content_tag("script", "$.cloudinary.config(#{params.to_json});".html_safe, :type=>"text/javascript") end |
#cloudinary_url(source, options = {}) ⇒ Object
145 146 147 148 |
# File 'lib/cloudinary/helper.rb', line 145 def cloudinary_url(source, = {}) [:ssl_detected] = request.ssl? if defined?(request) && request && request.respond_to?(:ssl?) Cloudinary::Utils.cloudinary_url(source, ) end |
#facebook_profile_image_path(profile, options = {}) ⇒ Object
53 54 55 |
# File 'lib/cloudinary/helper.rb', line 53 def facebook_profile_image_path(profile, = {}) cl_image_path(profile, {:type=>:facebook}.merge()) end |
#facebook_profile_image_tag(profile, options = {}) ⇒ Object
49 50 51 |
# File 'lib/cloudinary/helper.rb', line 49 def facebook_profile_image_tag(profile, = {}) cl_image_tag(profile, {:type=>:facebook}.merge()) end |
#fetch_image_tag(profile, options = {}) ⇒ Object
45 46 47 |
# File 'lib/cloudinary/helper.rb', line 45 def fetch_image_tag(profile, = {}) cl_image_tag(profile, {:type=>:fetch}.merge()) end |
#gplus_profile_image_path(profile, options = {}) ⇒ Object
85 86 87 |
# File 'lib/cloudinary/helper.rb', line 85 def gplus_profile_image_path(profile, = {}) cl_image_path(profile, {:type=>:gplus}.merge()) end |
#gplus_profile_image_tag(profile, options = {}) ⇒ Object
81 82 83 |
# File 'lib/cloudinary/helper.rb', line 81 def gplus_profile_image_tag(profile, = {}) cl_image_tag(profile, {:type=>:gplus}.merge()) end |
#gravatar_profile_image_path(email, options = {}) ⇒ Object
61 62 63 |
# File 'lib/cloudinary/helper.rb', line 61 def gravatar_profile_image_path(email, = {}) cl_image_path(Digest::MD5.hexdigest(email.strip.downcase), {:type=>:gravatar, :format=>:jpg}.merge()) end |
#gravatar_profile_image_tag(email, options = {}) ⇒ Object
57 58 59 |
# File 'lib/cloudinary/helper.rb', line 57 def gravatar_profile_image_tag(email, = {}) cl_image_tag(Digest::MD5.hexdigest(email.strip.downcase), {:type=>:gravatar, :format=>:jpg}.merge()) end |
#image_path(*args) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/cloudinary/helper.rb', line 36 def image_path(*args) if Cloudinary.config.enhance_image_tag source, = args cl_image_path(source, {:type=>:asset}.merge( || {})) else original_image_path(*args) end end |
#image_tag(*args) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/cloudinary/helper.rb', line 27 def image_tag(*args) if Cloudinary.config.enhance_image_tag source, = args cl_image_tag(source, {:type=>:asset}.merge( || {})) else original_image_tag(*args) end end |
#original_image_path ⇒ Object
5 |
# File 'lib/cloudinary/helper.rb', line 5 alias :original_image_path :image_path |
#original_image_tag ⇒ Object
4 |
# File 'lib/cloudinary/helper.rb', line 4 alias :original_image_tag :image_tag |
#twitter_name_profile_image_path(profile, options = {}) ⇒ Object
77 78 79 |
# File 'lib/cloudinary/helper.rb', line 77 def twitter_name_profile_image_path(profile, = {}) cl_image_path(profile, {:type=>:twitter_name}.merge()) end |
#twitter_name_profile_image_tag(profile, options = {}) ⇒ Object
73 74 75 |
# File 'lib/cloudinary/helper.rb', line 73 def twitter_name_profile_image_tag(profile, = {}) cl_image_tag(profile, {:type=>:twitter_name}.merge()) end |
#twitter_profile_image_path(profile, options = {}) ⇒ Object
69 70 71 |
# File 'lib/cloudinary/helper.rb', line 69 def twitter_profile_image_path(profile, = {}) cl_image_path(profile, {:type=>:twitter}.merge()) end |
#twitter_profile_image_tag(profile, options = {}) ⇒ Object
65 66 67 |
# File 'lib/cloudinary/helper.rb', line 65 def twitter_profile_image_tag(profile, = {}) cl_image_tag(profile, {:type=>:twitter}.merge()) end |