jekyll_picture_tag 1.7.1 → 1.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -7
  3. data/Dockerfile +9 -0
  4. data/docs/Gemfile.lock +183 -88
  5. data/docs/contributing.md +50 -16
  6. data/docs/example_presets.md +1 -1
  7. data/docs/global_configuration.md +55 -2
  8. data/docs/index.md +26 -20
  9. data/docs/installation.md +22 -7
  10. data/docs/notes.md +11 -1
  11. data/docs/output.md +32 -21
  12. data/docs/presets.md +109 -54
  13. data/docs/releases.md +17 -1
  14. data/docs/usage.md +68 -38
  15. data/jekyll_picture_tag.gemspec +2 -1
  16. data/lib/jekyll_picture_tag.rb +27 -10
  17. data/lib/jekyll_picture_tag/defaults/global.yml +2 -0
  18. data/lib/jekyll_picture_tag/defaults/presets.yml +2 -0
  19. data/lib/jekyll_picture_tag/generated_image.rb +105 -19
  20. data/lib/jekyll_picture_tag/instructions.rb +1 -0
  21. data/lib/jekyll_picture_tag/instructions/arg_splitter.rb +68 -0
  22. data/lib/jekyll_picture_tag/instructions/configuration.rb +47 -11
  23. data/lib/jekyll_picture_tag/instructions/preset.rb +34 -14
  24. data/lib/jekyll_picture_tag/instructions/set.rb +18 -8
  25. data/lib/jekyll_picture_tag/instructions/tag_parser.rb +59 -69
  26. data/lib/jekyll_picture_tag/output_formats/basic.rb +36 -7
  27. data/lib/jekyll_picture_tag/output_formats/data_attributes.rb +4 -1
  28. data/lib/jekyll_picture_tag/router.rb +16 -0
  29. data/lib/jekyll_picture_tag/source_image.rb +6 -1
  30. data/lib/jekyll_picture_tag/srcsets/basic.rb +45 -19
  31. data/lib/jekyll_picture_tag/srcsets/pixel_ratio.rb +1 -3
  32. data/lib/jekyll_picture_tag/srcsets/width.rb +1 -1
  33. data/lib/jekyll_picture_tag/utils.rb +18 -0
  34. data/lib/jekyll_picture_tag/version.rb +1 -1
  35. data/readme.md +39 -16
  36. metadata +24 -8
@@ -18,7 +18,10 @@ module PictureTag
18
18
  end
19
19
 
20
20
  def add_sizes(element, srcset)
21
- element.attributes << { 'data-sizes' => srcset.sizes } if srcset.sizes
21
+ return unless srcset.sizes
22
+
23
+ attribute = PictureTag.preset['data_sizes'] ? 'data-sizes' : 'sizes'
24
+ element.attributes << { attribute => srcset.sizes }
22
25
  end
23
26
 
24
27
  def build_noscript(base_content)
@@ -47,6 +47,14 @@ module PictureTag
47
47
  @instructions.source_images
48
48
  end
49
49
 
50
+ def crop(media = nil)
51
+ @instructions.crop(media)
52
+ end
53
+
54
+ def gravity(media = nil)
55
+ @instructions.gravity(media)
56
+ end
57
+
50
58
  # Config Forwarding
51
59
 
52
60
  def source_dir
@@ -69,6 +77,14 @@ module PictureTag
69
77
  config.pconfig
70
78
  end
71
79
 
80
+ def disabled?
81
+ config.disabled?
82
+ end
83
+
84
+ def fast_build?
85
+ config.fast_build?
86
+ end
87
+
72
88
  # Preset forwarding
73
89
 
74
90
  def widths(media)
@@ -4,6 +4,7 @@ module PictureTag
4
4
  # to be reused by many different generated images.
5
5
  class SourceImage
6
6
  attr_reader :name, :shortname, :missing, :media_preset
7
+ attr_accessor :digest_guess
7
8
  include MiniMagick
8
9
 
9
10
  def initialize(relative_filename, media_preset = nil)
@@ -23,12 +24,16 @@ module PictureTag
23
24
  def digest
24
25
  @digest ||= if @missing
25
26
  'x' * 6
27
+ elsif PictureTag.fast_build? && @digest_guess
28
+ # Digest guess will be handed off to this class by the first
29
+ # generated image which needs it (via attr_accessor).
30
+ @digest_guess
26
31
  else
27
32
  Digest::MD5.hexdigest(File.read(@name))[0..5]
28
33
  end
29
34
  end
30
35
 
31
- # Includes path relative to default sorce folder, and the original filename.
36
+ # Includes path relative to default source folder and the original filename.
32
37
  def base_name
33
38
  @shortname.delete_suffix File.extname(@shortname)
34
39
  end
@@ -24,7 +24,7 @@ module PictureTag
24
24
  end
25
25
 
26
26
  def files
27
- @files ||= widths.collect { |w| generate_file(w) }
27
+ @files ||= build_files
28
28
  end
29
29
 
30
30
  def to_a
@@ -46,15 +46,6 @@ module PictureTag
46
46
  nil
47
47
  end
48
48
 
49
- # Check our source image size vs requested sizes
50
- def check_widths(targets)
51
- if targets.any? { |t| t > @source_image.width }
52
- handle_small_source(targets, @source_image.width)
53
- else
54
- targets
55
- end
56
- end
57
-
58
49
  # Generates an HTML attribute
59
50
  def media_attribute
60
51
  "(#{PictureTag.media_presets[@media]})"
@@ -62,24 +53,59 @@ module PictureTag
62
53
 
63
54
  private
64
55
 
65
- def handle_small_source(targets, image_width)
66
- Utils.warning(
67
- " #{@source_image.shortname} is #{image_width}px wide, smaller than" \
68
- " at least one size in the set #{targets}. Will not enlarge."
69
- )
56
+ def build_files
57
+ # By 'files', we mean the GeneratedImage class.
58
+ return target_files if target_files.all?(&:exists?)
59
+
60
+ # This triggers GeneratedImage to actually build an image file.
61
+ files = checked_targets
62
+ files.each(&:generate)
63
+
64
+ files
65
+ end
66
+
67
+ def checked_targets
68
+ if target_files.any? { |f| f.width > source_width }
70
69
 
71
- small_targets = targets.dup.delete_if { |t| t >= image_width }
70
+ small_source_warn
72
71
 
73
- small_targets.push image_width
72
+ files = target_files.reject { |f| f.width >= source_width }
73
+ files.push(generate_file(source_width))
74
+ end
75
+
76
+ files || target_files
77
+ end
78
+
79
+ def source_width
80
+ @source_width ||= if PictureTag.crop(@media)
81
+ target_files.first.cropped_source_width
82
+ else
83
+ @source_image.width
84
+ end
85
+ end
74
86
 
75
- small_targets
87
+ def target_files
88
+ @target_files ||= widths.collect { |w| generate_file(w) }
89
+ end
90
+
91
+ def small_source_warn
92
+ Utils.warning(
93
+ <<~HEREDOC
94
+ #{@source_image.shortname}
95
+ is #{source_width}px wide (after cropping, if applicable),
96
+ smaller than at least one size in the set #{widths}.
97
+ Will not enlarge.
98
+ HEREDOC
99
+ )
76
100
  end
77
101
 
78
102
  def generate_file(width)
79
103
  GeneratedImage.new(
80
104
  source_file: @source_image,
81
105
  width: width,
82
- format: @input_format
106
+ format: @input_format,
107
+ crop: PictureTag.crop(@media),
108
+ gravity: PictureTag.gravity(@media)
83
109
  )
84
110
  end
85
111
  end
@@ -6,11 +6,9 @@ module PictureTag
6
6
  private
7
7
 
8
8
  def widths
9
- target = PictureTag.preset['pixel_ratios'].collect do |p|
9
+ PictureTag.preset['pixel_ratios'].collect do |p|
10
10
  p * PictureTag.preset['base_width']
11
11
  end
12
-
13
- check_widths target
14
12
  end
15
13
 
16
14
  def build_srcset_entry(file)
@@ -22,7 +22,7 @@ module PictureTag
22
22
  private
23
23
 
24
24
  def widths
25
- check_widths PictureTag.widths(@media)
25
+ PictureTag.widths(@media)
26
26
  end
27
27
 
28
28
  def build_srcset_entry(file)
@@ -2,6 +2,24 @@ module PictureTag
2
2
  # This is a little module to hold logic that doesn't fit other places. If it
3
3
  # starts getting big, refactor.
4
4
  module Utils
5
+ # These are valid ImageMagick gravity arguments (relevant to our use
6
+ # case):
7
+ GRAVITIES =
8
+ %w[center
9
+ north
10
+ northeast
11
+ east
12
+ southeast
13
+ south
14
+ southwest
15
+ west
16
+ northwest].freeze
17
+
18
+ # This is an attempt to recognize valid imagemagick geometry arguments
19
+ # with regex. It only tries to match values which don't preserve aspect
20
+ # ratio, as they're the ones people might actually need here.
21
+ GEOMETRY_REGEX = /\A\d*%?[x:]?\d*[%!]?([+-]\d+){,2}\Z/i.freeze
22
+
5
23
  class << self
6
24
  # Configure Jekyll to keep our generated files
7
25
  def keep_files
@@ -1,3 +1,3 @@
1
1
  module PictureTag
2
- VERSION = '1.7.1'.freeze
2
+ VERSION = '1.10.2'.freeze
3
3
  end
data/readme.md CHANGED
@@ -1,21 +1,20 @@
1
1
  # Jekyll Picture Tag
2
2
 
3
- **Easy responsive images for Jekyll.**
3
+ **Responsive Images done correctly.**
4
4
 
5
- It's easy to throw an image on a webpage and call it a day. Doing justice to your users by serving
6
- it efficiently on all browsers and screen sizes is tedious and tricky. Tedious, tricky things should be
7
- automated.
5
+ It's simple to throw a photo on a page and call it a day, but doing justice to users on all
6
+ different browsers and devices is tedious and tricky. Tedious, tricky things should be automated.
8
7
 
9
- Jekyll Picture Tag adds responsive images to your [Jekyll](http://jekyllrb.com) static site. It
10
- automatically creates resized, reformatted source images, is fully configurable, implements sensible
11
- defaults, and solves both the art direction and resolution switching problems with a little YAML
12
- configuration and a simple template tag.
8
+ Jekyll Picture Tag automatically builds cropped, resized, and reformatted images, builds several
9
+ kinds of markup, offers extensive configuration while requiring none, and solves both the art
10
+ direction and resolution switching problems with a little YAML configuration and a simple template
11
+ tag.
13
12
 
14
13
  ## Why use Responsive Images?
15
14
 
16
- **Performance:** The fastest sites are static sites, but when you plonk a 2mb picture of your dog at
17
- the top of a blog post you're throwing it all away. Responsive images allow you to keep your site
18
- fast, without compromising image quality.
15
+ **Performance:** The fastest sites are static sites, but if you plonk a 2mb picture of your dog at
16
+ the top of a blog post you throw it all away. Responsive images allow you to keep your site fast,
17
+ without compromising image quality.
19
18
 
20
19
  **Design:** Your desktop image may not work well on mobile, regardless of its resolution. We often
21
20
  want to do more than just resize images for different screen sizes, we want to crop them or use a
@@ -24,15 +23,39 @@ different image entirely.
24
23
  ## Why use Jekyll Picture Tag?
25
24
 
26
25
  **Developer Sanity:** If you want to serve multiple images in multiple formats and resolutions, you
27
- have a litany of markup to write and a big pile of images to generate. Jekyll Picture Tag is your
28
- responsive images minion - give it simple instructions and it'll handle the rest.
26
+ have a litany of markup to write and a big pile of images to generate and organize. Jekyll Picture
27
+ Tag is your responsive images minion - give it simple instructions and it'll handle the rest.
29
28
 
30
29
  ## Features
31
30
 
32
- * Automatic generation and organization of resized image files in basically any format(s).
33
- * Automatic generation of complex markup in several different formats.
34
- * No configuration required, extensive configuration available.
31
+ * Generate piles of cropped, resized, and converted image files.
32
+ * Generate corresponding markup in several different formats.
33
+ * Configure it easily, or not at all.
34
+ * Make Lighthouse happy.
35
35
 
36
36
  ## Documentation:
37
37
 
38
38
  https://rbuchberger.github.io/jekyll_picture_tag/
39
+
40
+ ## Changelog:
41
+
42
+ https://rbuchberger.github.io/jekyll_picture_tag/releases
43
+
44
+ Latest versions:
45
+
46
+ * 1.10.0 May 11, 2020
47
+ * **Image Cropping support!** access the power of ImageMagick's `crop` function.
48
+ * Don't issue a warning when `default` preset is not found.
49
+ * Documentation improvements
50
+ * 1.10.1 July 2, 2020
51
+ * Bugfix for erroneously regenerated images
52
+ * 1.10.2 July 6, 2020
53
+ * Bugfix for fallback image files not actually getting generated
54
+
55
+ ## Help Wanted
56
+
57
+ Writing code is only part of the job; often the harder part is knowing what needs to be changed. Any
58
+ and all feedback is greatly appreciated, especially in regards to documentation. What are your pain
59
+ points? See the [contributing
60
+ guidelines](https://rbuchberger.github.io/jekyll_picture_tag/contributing), or the
61
+ [issues](https://github.com/rbuchberger/jekyll_picture_tag/issues) page for more.
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_picture_tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Wierzbowski
8
8
  - Brendan Tobolaski
9
9
  - Robert Buchberger
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-11-14 00:00:00.000000000 Z
13
+ date: 2020-07-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -152,6 +152,20 @@ dependencies:
152
152
  - - "~>"
153
153
  - !ruby/object:Gem::Version
154
154
  version: '2.6'
155
+ - !ruby/object:Gem::Dependency
156
+ name: base32
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: '0.3'
162
+ type: :runtime
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - "~>"
167
+ - !ruby/object:Gem::Version
168
+ version: '0.3'
155
169
  - !ruby/object:Gem::Dependency
156
170
  name: mime-types
157
171
  requirement: !ruby/object:Gem::Requirement
@@ -186,14 +200,14 @@ dependencies:
186
200
  requirements:
187
201
  - - "~>"
188
202
  - !ruby/object:Gem::Version
189
- version: 1.1.1
203
+ version: 1.1.2
190
204
  type: :runtime
191
205
  prerelease: false
192
206
  version_requirements: !ruby/object:Gem::Requirement
193
207
  requirements:
194
208
  - - "~>"
195
209
  - !ruby/object:Gem::Version
196
- version: 1.1.1
210
+ version: 1.1.2
197
211
  - !ruby/object:Gem::Dependency
198
212
  name: jekyll
199
213
  requirement: !ruby/object:Gem::Requirement
@@ -225,6 +239,7 @@ files:
225
239
  - ".ruby-version"
226
240
  - ".solargraph.yml"
227
241
  - ".travis.yml"
242
+ - Dockerfile
228
243
  - Gemfile
229
244
  - LICENSE.txt
230
245
  - Rakefile
@@ -253,6 +268,7 @@ files:
253
268
  - lib/jekyll_picture_tag/generated_image.rb
254
269
  - lib/jekyll_picture_tag/img_uri.rb
255
270
  - lib/jekyll_picture_tag/instructions.rb
271
+ - lib/jekyll_picture_tag/instructions/arg_splitter.rb
256
272
  - lib/jekyll_picture_tag/instructions/configuration.rb
257
273
  - lib/jekyll_picture_tag/instructions/html_attributes.rb
258
274
  - lib/jekyll_picture_tag/instructions/preset.rb
@@ -283,7 +299,7 @@ homepage: https://github.com/rbuchberger/jekyll_picture_tag
283
299
  licenses:
284
300
  - BSD-3-Clause
285
301
  metadata: {}
286
- post_install_message:
302
+ post_install_message:
287
303
  rdoc_options: []
288
304
  require_paths:
289
305
  - lib
@@ -301,8 +317,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
317
  - !ruby/object:Gem::Version
302
318
  version: '0'
303
319
  requirements: []
304
- rubygems_version: 3.0.4
305
- signing_key:
320
+ rubygems_version: 3.1.4
321
+ signing_key:
306
322
  specification_version: 4
307
323
  summary: Easy responsive images for Jekyll.
308
324
  test_files: []