jekyll-cloudinary 1.2.15 → 1.2.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 343d4c46dbcc0330c200f38793b923a357c828af
4
- data.tar.gz: 5314f74f3c74aea64306d7dff45bb810ca9902ca
3
+ metadata.gz: cbd2c52248fa02e936e4dbf7816a23aa5cfaa866
4
+ data.tar.gz: a417e4a1b1369e3b8f7ce6cb5a696853661fc1d5
5
5
  SHA512:
6
- metadata.gz: e1b35c1e6c71c1fd873435955820eaaa3243822cc949c9a6a590e55e04a3f0df34d5ad7c172d2d72d3cbfe275d52b07214f5b67954d1789a104f9389de359f7d
7
- data.tar.gz: a70758fddcacd02ca3a50a4f8f6c459f572ae9c87db992f6bb289527b8462ceebbde4c9262af6fd7cf0426f06a38fedc6ef3439872062f06fe5dac9639fe3456
6
+ metadata.gz: 24e32b20536c43c13db0cf44d4f02a88854bda4fa02dfa6c8a8eb13bf99b993587c1fadc38560772f86a68d410713068da5f11d31879c59a442eb30b8c099b75
7
+ data.tar.gz: 25cf64ff3dda1cd46a99c34a789903f4c22a63efe48279f5ae43201156f02f063d8e3b4db38fc9ce0c28e234941dcaacc1f281595c6aa559f1804d5cae0eeee3
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Cloudinary
3
- VERSION = "1.2.15"
3
+ VERSION = "1.2.16".freeze
4
4
  end
5
5
  end
@@ -2,7 +2,6 @@ module Jekyll
2
2
  module Cloudinary
3
3
 
4
4
  class CloudinaryTag < Liquid::Tag
5
-
6
5
  require "RMagick"
7
6
 
8
7
  def initialize(tag_name, markup, tokens)
@@ -11,152 +10,179 @@ module Jekyll
11
10
  end
12
11
 
13
12
  def render(context)
14
-
15
13
  # Default settings
16
14
  preset_defaults = {
17
- "min_width" => 320,
18
- "max_width" => 1200,
19
- "steps" => 5,
20
- "sizes" => "100vw",
21
- "figure" => "auto",
22
- "attributes" => { },
23
- "verbose" => false
15
+ "min_width" => 320,
16
+ "max_width" => 1200,
17
+ "steps" => 5,
18
+ "sizes" => "100vw",
19
+ "figure" => "auto",
20
+ "attributes" => {},
21
+ "verbose" => false
24
22
  }
25
23
 
26
24
  # Settings
27
25
  site = context.registers[:site]
28
- url = site.config['url']
29
- settings = site.config['cloudinary']
26
+ url = site.config["url"]
27
+ settings = site.config["cloudinary"]
30
28
 
31
29
  # Get Markdown converter
32
30
  markdown_converter = site.find_converter_instance(::Jekyll::Converters::Markdown)
33
31
 
34
32
  preset_user_defaults = {}
35
- if settings['presets']
36
- if settings['presets']['default']
37
- preset_user_defaults = settings['presets']['default']
33
+ if settings["presets"]
34
+ if settings["presets"]["default"]
35
+ preset_user_defaults = settings["presets"]["default"]
38
36
  end
39
37
  end
40
38
 
41
39
  preset = preset_defaults.merge(preset_user_defaults)
42
40
 
43
41
  # Render any liquid variables in tag arguments and unescape template code
44
- rendered_markup = Liquid::Template.parse(@markup).render(context).gsub(/\\\{\\\{|\\\{\\%/, '\{\{' => '{{', '\{\%' => '{%')
42
+ rendered_markup = Liquid::Template
43
+ .parse(@markup)
44
+ .render(context)
45
+ .gsub(%r!\\\{\\\{|\\\{\\%!, '\{\{' => '{{', '\{\%' => '{%')
45
46
 
46
47
  # Extract tag segments
47
- markup = /^(?:(?<preset>[^\s.:\/]+)\s+)?(?<image_src>[^\s]+\.[a-zA-Z0-9]{3,4})\s*(?<html_attr>[\s\S]+)?$/.match(rendered_markup)
48
- if !markup
49
- Jekyll.logger.abort_with('[Cloudinary]', "Can't read this tag: #{@markup}")
48
+ markup =
49
+ %r!^(?:(?<preset>[^\s.:\/]+)\s+)?(?<image_src>[^\s]+\.[a-zA-Z0-9]{3,4})\s*(?<html_attr>[\s\S]+)?$!
50
+ .match(rendered_markup)
51
+
52
+ unless markup
53
+ Jekyll.logger.abort_with("[Cloudinary]", "Can't read this tag: #{@markup}")
50
54
  end
51
55
 
52
56
  image_src = markup[:image_src]
53
57
 
54
58
  # Build source image URL
55
- is_image_path_absolute = /^\/.*$/.match(image_src)
59
+ is_image_path_absolute = %r!^/.*$!.match(image_src)
56
60
  if is_image_path_absolute
57
- image_path = File.join(site.config['destination'], image_src)
61
+ image_path = File.join(site.config["destination"], image_src)
58
62
  image_url = File.join(url, image_src)
59
63
  else
60
- image_path = File.join(site.config['destination'], File.dirname(context['page'].url), image_src)
61
- image_url = File.join(url, File.dirname(context['page'].url), image_src)
64
+ image_path = File.join(
65
+ site.config["destination"],
66
+ File.dirname(context["page"].url),
67
+ image_src
68
+ )
69
+ image_url = File.join(
70
+ url,
71
+ File.dirname(context["page"].url),
72
+ image_src
73
+ )
62
74
  end
63
75
 
64
76
  # Get source image natural width
65
77
  if File.exist?(image_path)
66
78
  image = Magick::Image::read(image_path).first
67
79
  natural_width = image.columns
68
- fallback_url = "https://res.cloudinary.com/#{settings['cloud_name']}/image/fetch/c_scale,w_#{natural_width},q_auto,f_auto/#{image_url}"
80
+ fallback_url = "https://res.cloudinary.com/#{settings["cloud_name"]}/image/fetch/c_limit,w_#{natural_width},q_auto,f_auto/#{image_url}"
69
81
  else
70
- natural_width = 100000
71
- Jekyll.logger.warn('[Cloudinary]', "Couldn't find this image to check its width: #{image_path}. Try to run Jekyll build a second time.")
72
- fallback_url = "#{image_url}"
82
+ natural_width = 100_000
83
+ Jekyll.logger.warn(
84
+ "[Cloudinary]",
85
+ "Couldn't find this image to check its width: #{image_path}. \
86
+ Try to run Jekyll build a second time."
87
+ )
88
+ fallback_url = image_url
73
89
  end
74
90
 
75
91
  if markup[:preset]
76
- if settings['presets'][markup[:preset]]
77
- preset = preset.merge(settings['presets'][markup[:preset]])
78
- else
79
- if settings['verbose']
80
- Jekyll.logger.warn('[Cloudinary]', "'#{markup[:preset]}' preset for the Cloudinary plugin doesn't exist, using the default one")
81
- end
92
+ if settings["presets"][markup[:preset]]
93
+ preset = preset.merge(settings["presets"][markup[:preset]])
94
+ elsif settings["verbose"]
95
+ Jekyll.logger.warn(
96
+ "[Cloudinary]",
97
+ "'#{markup[:preset]}' preset for the Cloudinary plugin doesn't exist, \
98
+ using the default one"
99
+ )
82
100
  end
83
101
  end
84
102
 
85
- attributes = preset['attributes']
103
+ attributes = preset["attributes"]
86
104
 
87
105
  # Deep copy preset for single instance manipulation
88
106
  instance = Marshal.load(Marshal.dump(preset))
89
107
 
90
108
  # Process attributes
91
109
  html_attr = if markup[:html_attr]
92
- Hash[ *markup[:html_attr].scan(/(?<attr>[^\s="]+)(?:="(?<value>[^"]+)")?\s?/).flatten ]
110
+ Hash[ *markup[:html_attr].scan(%r!(?<attr>[^\s="]+)(?:="(?<value>[^"]+)")?\s?!).flatten ]
93
111
  else
94
112
  {}
95
113
  end
96
114
 
97
- if instance['attr']
98
- html_attr = instance.delete('attr').merge(html_attr)
115
+ if instance["attr"]
116
+ html_attr = instance.delete("attr").merge(html_attr)
99
117
  end
100
118
 
101
119
  # Classes from the tag should complete, not replace, the ones from the preset
102
- if html_attr['class'] && attributes['class']
103
- html_attr['class'] << " #{attributes['class']}"
120
+ if html_attr["class"] && attributes["class"]
121
+ html_attr["class"] << " #{attributes["class"]}"
104
122
  end
105
123
  html_attr = attributes.merge(html_attr)
106
124
 
107
125
  # Deal with the "caption" attribute as a true <figcaption>
108
- if html_attr['caption']
109
- caption = markdown_converter.convert(html_attr['caption'])
110
- html_attr.delete('caption')
126
+ if html_attr["caption"]
127
+ caption = markdown_converter.convert(html_attr["caption"])
128
+ html_attr.delete("caption")
111
129
  end
112
130
 
113
131
  # alt and title attributes should go only to the <img> even when there is a caption
114
132
  img_attr = ""
115
- if html_attr['alt']
116
- img_attr << " alt=\"#{html_attr['alt']}\""
117
- html_attr.delete('alt')
133
+ if html_attr["alt"]
134
+ img_attr << " alt=\"#{html_attr["alt"]}\""
135
+ html_attr.delete("alt")
118
136
  end
119
- if html_attr['title']
120
- img_attr << " title=\"#{html_attr['title']}\""
121
- html_attr.delete('title')
137
+ if html_attr["title"]
138
+ img_attr << " title=\"#{html_attr["title"]}\""
139
+ html_attr.delete("title")
122
140
  end
123
141
 
124
- attr_string = html_attr.map { |a,v| "#{a}=\"#{v}\"" }.join(' ')
142
+ attr_string = html_attr.map { |a, v| "#{a}=\"#{v}\"" }.join(" ")
125
143
 
126
144
  srcset = []
127
- steps = preset['steps'].to_i
128
- min_width = preset['min_width'].to_i
129
- max_width = preset['max_width'].to_i
145
+ steps = preset["steps"].to_i
146
+ min_width = preset["min_width"].to_i
147
+ max_width = preset["max_width"].to_i
130
148
  step_width = (max_width - min_width) / (steps - 1)
131
- sizes = preset['sizes']
149
+ sizes = preset["sizes"]
132
150
 
133
151
  if natural_width < min_width
134
- if settings['verbose']
135
- Jekyll.logger.warn('[Cloudinary]', "Width of source image '#{File.basename(image_src)}' (#{natural_width}px) in #{context['page'].path} not enough for ANY srcset version")
152
+ if settings["verbose"]
153
+ Jekyll.logger.warn(
154
+ "[Cloudinary]",
155
+ "Width of source image '#{File.basename(image_src)}' (#{natural_width}px) \
156
+ in #{context["page"].path} not enough for ANY srcset version"
157
+ )
136
158
  end
137
- srcset << "https://res.cloudinary.com/#{settings['cloud_name']}/image/fetch/c_scale,w_#{natural_width},q_auto,f_auto/#{image_url} #{natural_width}w"
159
+ srcset << "https://res.cloudinary.com/#{settings["cloud_name"]}/image/fetch/c_limit,w_#{natural_width},q_auto,f_auto/#{image_url} #{natural_width}w"
138
160
  else
139
161
  missed_sizes = []
140
162
  (1..steps).each do |factor|
141
163
  width = min_width + (factor - 1) * step_width
142
164
  if width <= natural_width
143
- srcset << "https://res.cloudinary.com/#{settings['cloud_name']}/image/fetch/c_scale,w_#{width},q_auto,f_auto/#{image_url} #{width}w"
165
+ srcset << "https://res.cloudinary.com/#{settings["cloud_name"]}/image/fetch/c_limit,w_#{width},q_auto,f_auto/#{image_url} #{width}w"
144
166
  else
145
167
  missed_sizes.push(width)
146
168
  end
147
169
  end
148
- if missed_sizes.length > 0
149
- srcset << "https://res.cloudinary.com/#{settings['cloud_name']}/image/fetch/c_scale,w_#{natural_width},q_auto,f_auto/#{image_url} #{natural_width}w"
150
- if settings['verbose']
151
- Jekyll.logger.warn('[Cloudinary]', "Width of source image '#{File.basename(image_src)}' (#{natural_width}px) in #{context['page'].path} not enough for #{missed_sizes.join('px, ')}px version#{missed_sizes.length > 1 ? 's' : ''}")
152
- end
170
+ if missed_sizes.length.empty?
171
+ srcset << "https://res.cloudinary.com/#{settings["cloud_name"]}/image/fetch/c_limit,w_#{natural_width},q_auto,f_auto/#{image_url} #{natural_width}w"
172
+ if settings["verbose"]
173
+ Jekyll.logger.warn(
174
+ "[Cloudinary]",
175
+ "Width of source image '#{File.basename(image_src)}' (#{natural_width}px) \
176
+ in #{context["page"].path} not enough for #{missed_sizes.join("px, ")}px \
177
+ version#{missed_sizes.length > 1 ? "s" : ""}"
178
+ )
153
179
  end
154
-
180
+ end
155
181
  end
156
182
  srcset_string = srcset.join(",\n")
157
183
 
158
184
  # preset['figure'] can be 'never', 'auto' or 'always'
159
- if (caption || preset['figure'] == 'always') && preset['figure'] != 'never'
185
+ if (caption || preset["figure"] == "always") && preset["figure"] != "never"
160
186
  "\n<figure #{attr_string}>\n<img src=\"#{fallback_url}\" srcset=\"#{srcset_string}\" sizes=\"#{sizes}\" #{img_attr} />\n<figcaption>#{caption}</figcaption>\n</figure>\n"
161
187
  else
162
188
  "<img src=\"#{fallback_url}\" srcset=\"#{srcset_string}\" sizes=\"#{sizes}\" #{attr_string} #{img_attr} />"
@@ -167,5 +193,4 @@ module Jekyll
167
193
  end
168
194
  end
169
195
 
170
- Liquid::Template.register_tag('cloudinary', Jekyll::Cloudinary::CloudinaryTag)
171
-
196
+ Liquid::Template.register_tag("cloudinary", Jekyll::Cloudinary::CloudinaryTag)
@@ -1 +1 @@
1
- require "jekyll/cloudinary"
1
+ require "jekyll/cloudinary"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-cloudinary
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.15
4
+ version: 1.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Hoizey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-29 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -78,6 +78,20 @@ dependencies:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
80
  version: '10.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rubocop
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '0.42'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '0.42'
81
95
  description: " Liquid tag to use Cloudinary for optimized responsive posts images.\n"
82
96
  email:
83
97
  - nicolas@hoizey.com