cloudinary 1.0.14 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/cloudinary.rb CHANGED
@@ -7,7 +7,7 @@ require "cloudinary/utils"
7
7
  require "cloudinary/uploader"
8
8
  require "cloudinary/downloader"
9
9
  require "cloudinary/blob"
10
- require "cloudinary/static" if defined?(::ActiveSupport)
10
+ require "cloudinary/static"
11
11
  require "cloudinary/missing"
12
12
  require "cloudinary/carrier_wave" if defined?(::CarrierWave)
13
13
  require "cloudinary/helper" if defined?(::ActionView::Base)
@@ -97,7 +97,7 @@ module CloudinaryHelper
97
97
  content = []
98
98
 
99
99
  params.each do |name, value|
100
- content << hidden_field_tag(name, value)
100
+ content << hidden_field_tag(name, value, :id => nil) if value.present?
101
101
  end
102
102
 
103
103
  content << capture(&block)
@@ -171,7 +171,8 @@ end
171
171
 
172
172
  ActionView::Base.send :include, CloudinaryHelper
173
173
 
174
- if defined?(Sass::Rails)
174
+ begin
175
+ require 'sass-rails'
175
176
  class Sass::Rails::Resolver
176
177
  alias :original_image_path :image_path
177
178
  def image_path(img)
@@ -182,5 +183,22 @@ if defined?(Sass::Rails)
182
183
  end
183
184
  end
184
185
  end
186
+ rescue LoadError
187
+ # no sass rails support. Ignore.
185
188
  end
186
189
 
190
+ begin
191
+ require 'sass/script/functions'
192
+ module Sass::Script::Functions
193
+ def cloudinary_url(public_id, sass_options={})
194
+ options = {}
195
+ sass_options.each{|k, v| options[k.to_sym] = v.value}
196
+ url = Cloudinary::Utils.cloudinary_url(public_id.value, {:type=>:asset}.merge(options))
197
+ Sass::Script::String.new("url(#{url})")
198
+ end
199
+ declare :cloudinary_url, [:string], :var_kwargs => true
200
+ end
201
+ rescue LoadError
202
+ # no sass support. Ignore.
203
+ end
204
+
@@ -1,5 +1,6 @@
1
- require 'active_support/time'
2
1
  require 'find'
2
+ require 'time'
3
+ require 'set'
3
4
  class Cloudinary::Static
4
5
  IGNORE_FILES = [".svn", "CVS", "RCS", ".git", ".hg"]
5
6
  SUPPORTED_IMAGES = [/\.gif$/i, /\.jpe?g$/i, /\.png$/i, /\.bmp$/i, /\.ico$/i]
@@ -32,8 +33,6 @@ class Cloudinary::Static
32
33
  end
33
34
  end
34
35
 
35
- UTC = ActiveSupport::TimeZone["UTC"]
36
-
37
36
  def self.root
38
37
  defined?(Rails) ? Rails.root : Pathname.new(".")
39
38
  end
@@ -56,7 +55,7 @@ class Cloudinary::Static
56
55
  path, public_id, upload_time, version, width, height = line.split("\t")
57
56
  metadata << [path, {
58
57
  "public_id" => public_id,
59
- "upload_time" => UTC.at(upload_time.to_i),
58
+ "upload_time" => Time.at(upload_time.to_i).getutc,
60
59
  "version" => version,
61
60
  "width" => width.to_i,
62
61
  "height" => height.to_i
@@ -94,9 +93,9 @@ class Cloudinary::Static
94
93
  $stderr.print "#{public_path} - #{public_id} - Uploading\n"
95
94
  result = Cloudinary::Uploader.upload(Cloudinary::Blob.new(data, :original_filename=>path.to_s),
96
95
  options.merge(:format=>format, :public_id=>public_id, :type=>:asset)
97
- )
96
+ ).merge("upload_time"=>Time.now)
98
97
  end
99
- metadata_lines << [public_path, public_id, Time.now.to_i, result["version"], result["width"], result["height"]].join("\t")+"\n"
98
+ metadata_lines << [public_path, public_id, result["upload_time"].to_i, result["version"], result["width"], result["height"]].join("\t")+"\n"
100
99
  end
101
100
  File.open(self.metadata_file_path, "w"){|f| f.print(metadata_lines.join)}
102
101
  metadata.to_a.each do |path, info|
@@ -13,7 +13,7 @@ class Cloudinary::Uploader
13
13
  :type=>options[:type],
14
14
  :tags=>options[:tags] && Cloudinary::Utils.build_array(options[:tags]).join(",")}
15
15
  if options[:eager]
16
- params[:eager] = options[:eager].map do
16
+ params[:eager] = Cloudinary::Utils.build_array(options[:eager]).map do
17
17
  |transformation, format|
18
18
  transformation = transformation.clone
19
19
  format = transformation.delete(:format) || format
@@ -28,7 +28,7 @@ class Cloudinary::Utils
28
28
  if base_transformations.any?{|base_transformation| base_transformation.is_a?(Hash)}
29
29
  base_transformations = base_transformations.map do
30
30
  |base_transformation|
31
- base_transformation.is_a?(Hash) ? generate_transformation_string(base_transformation) : generate_transformation_string(:transformation=>base_transformation)
31
+ base_transformation.is_a?(Hash) ? generate_transformation_string(base_transformation.clone) : generate_transformation_string(:transformation=>base_transformation)
32
32
  end
33
33
  else
34
34
  named_transformation = base_transformations.join(".")
@@ -50,6 +50,7 @@ class Cloudinary::Utils
50
50
 
51
51
  # Warning: options are being destructively updated!
52
52
  def self.cloudinary_url(source, options = {})
53
+ original_source = source
53
54
  transformation = self.generate_transformation_string(options)
54
55
 
55
56
  type = options.delete(:type)
@@ -64,22 +65,21 @@ class Cloudinary::Utils
64
65
  force_remote = options.delete(:force_remote)
65
66
 
66
67
  if !force_remote
67
- return source if (type.nil? || type == :asset) && source.match(%r(^https?:/)i)
68
+ return original_source if (type.nil? || type == :asset) && source.match(%r(^https?:/)i)
68
69
  if source.start_with?("/")
69
70
  if source.start_with?("/images/")
70
71
  source = source.sub(%r(/images/), '')
71
72
  else
72
- return source
73
+ return original_source
73
74
  end
74
75
  end
75
76
  @metadata ||= defined?(Cloudinary::Static) ? Cloudinary::Static.metadata : {}
76
77
  if type == :asset && @metadata["images/#{source}"]
77
- return source if !Cloudinary.config.static_image_support
78
- original_source = source
78
+ return original_source if !Cloudinary.config.static_image_support
79
79
  source = @metadata["images/#{source}"]["public_id"]
80
80
  source += File.extname(original_source) if !format
81
81
  elsif type == :asset
82
- return source # requested asset, but no metadata - probably local file. return.
82
+ return original_source # requested asset, but no metadata - probably local file. return.
83
83
  end
84
84
  end
85
85
  type ||= :upload
@@ -1,4 +1,4 @@
1
1
  # Copyright Cloudinary
2
2
  module Cloudinary
3
- VERSION = "1.0.14"
3
+ VERSION = "1.0.15"
4
4
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cloudinary
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.14
5
+ version: 1.0.15
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nadav Soferman