jekyll_picture_tag 1.10.0 → 1.13.0

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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +79 -0
  3. data/docs/Gemfile +4 -2
  4. data/docs/Gemfile.lock +14 -12
  5. data/docs/_config.yml +6 -10
  6. data/docs/devs/contributing/code.md +44 -0
  7. data/docs/devs/contributing/docs.md +13 -0
  8. data/docs/devs/contributing/index.md +15 -0
  9. data/docs/devs/contributing/setup.md +13 -0
  10. data/docs/devs/contributing/testing.md +41 -0
  11. data/docs/devs/index.md +7 -0
  12. data/docs/{releases.md → devs/releases.md} +37 -13
  13. data/docs/index.md +42 -26
  14. data/docs/users/configuration/cdn.md +35 -0
  15. data/docs/users/configuration/directories.md +34 -0
  16. data/docs/users/configuration/disable.md +24 -0
  17. data/docs/users/configuration/fast_build.md +28 -0
  18. data/docs/users/configuration/ignore_missing.md +23 -0
  19. data/docs/users/configuration/index.md +29 -0
  20. data/docs/users/configuration/kramdown_fix.md +20 -0
  21. data/docs/users/configuration/relative_urls.md +15 -0
  22. data/docs/users/configuration/suppress_warnings.md +16 -0
  23. data/docs/users/index.md +7 -0
  24. data/docs/users/installation.md +52 -0
  25. data/docs/users/liquid_tag/argument_reference/alternate_images.md +18 -0
  26. data/docs/users/liquid_tag/argument_reference/attributes.md +42 -0
  27. data/docs/users/liquid_tag/argument_reference/base_image.md +12 -0
  28. data/docs/users/liquid_tag/argument_reference/crop.md +48 -0
  29. data/docs/users/liquid_tag/argument_reference/link.md +16 -0
  30. data/docs/users/liquid_tag/argument_reference/preset.md +17 -0
  31. data/docs/users/liquid_tag/argument_reference/readme.md +9 -0
  32. data/docs/users/liquid_tag/examples.md +93 -0
  33. data/docs/users/liquid_tag/index.md +31 -0
  34. data/docs/users/notes/git_lfs.md +7 -0
  35. data/docs/users/notes/github_pages.md +5 -0
  36. data/docs/users/notes/html_attributes.md +5 -0
  37. data/docs/users/notes/index.md +6 -0
  38. data/docs/users/notes/input_checking.md +6 -0
  39. data/docs/users/notes/kramdown_bug.md +41 -0
  40. data/docs/users/notes/managing_images.md +21 -0
  41. data/docs/{migration.md → users/notes/migration.md} +0 -0
  42. data/docs/users/presets/cropping.md +61 -0
  43. data/docs/users/presets/default.md +23 -0
  44. data/docs/users/presets/examples.md +79 -0
  45. data/docs/users/presets/fallback_image.md +28 -0
  46. data/docs/users/presets/html_attributes.md +26 -0
  47. data/docs/users/presets/image_formats.md +21 -0
  48. data/docs/users/presets/image_quality.md +105 -0
  49. data/docs/users/presets/index.md +101 -0
  50. data/docs/users/presets/link_source.md +16 -0
  51. data/docs/users/presets/markup_formats/fragments.md +48 -0
  52. data/docs/users/presets/markup_formats/javascript_friendly.md +57 -0
  53. data/docs/users/presets/markup_formats/readme.md +43 -0
  54. data/docs/users/presets/markup_formats/standard_html.md +25 -0
  55. data/docs/users/presets/media_queries.md +36 -0
  56. data/docs/users/presets/nomarkdown_override.md +17 -0
  57. data/docs/users/presets/pixel_ratio_srcsets.md +32 -0
  58. data/docs/users/presets/quality_width_graph.png +0 -0
  59. data/docs/users/presets/width_height_attributes.md +34 -0
  60. data/docs/users/presets/width_srcsets.md +85 -0
  61. data/jekyll_picture_tag.gemspec +4 -5
  62. data/lib/jekyll_picture_tag.rb +3 -4
  63. data/lib/jekyll_picture_tag/cache.rb +3 -0
  64. data/lib/jekyll_picture_tag/cache/base.rb +59 -0
  65. data/lib/jekyll_picture_tag/cache/generated.rb +20 -0
  66. data/lib/jekyll_picture_tag/cache/source.rb +19 -0
  67. data/lib/jekyll_picture_tag/defaults/presets.yml +1 -0
  68. data/lib/jekyll_picture_tag/images.rb +3 -0
  69. data/lib/jekyll_picture_tag/images/generated_image.rb +127 -0
  70. data/lib/jekyll_picture_tag/{img_uri.rb → images/img_uri.rb} +1 -0
  71. data/lib/jekyll_picture_tag/images/source_image.rb +103 -0
  72. data/lib/jekyll_picture_tag/instructions/arg_splitter.rb +3 -2
  73. data/lib/jekyll_picture_tag/instructions/configuration.rb +1 -1
  74. data/lib/jekyll_picture_tag/instructions/preset.rb +24 -4
  75. data/lib/jekyll_picture_tag/instructions/set.rb +5 -1
  76. data/lib/jekyll_picture_tag/output_formats/basic.rb +16 -14
  77. data/lib/jekyll_picture_tag/output_formats/img.rb +11 -0
  78. data/lib/jekyll_picture_tag/output_formats/picture.rb +22 -0
  79. data/lib/jekyll_picture_tag/router.rb +3 -2
  80. data/lib/jekyll_picture_tag/srcsets/basic.rb +10 -1
  81. data/lib/jekyll_picture_tag/utils.rb +14 -0
  82. data/lib/jekyll_picture_tag/version.rb +1 -1
  83. data/readme.md +9 -7
  84. metadata +78 -45
  85. data/docs/_layouts/directory.html +0 -32
  86. data/docs/assets/style.css +0 -31
  87. data/docs/contributing.md +0 -109
  88. data/docs/example_presets.md +0 -116
  89. data/docs/global_configuration.md +0 -173
  90. data/docs/installation.md +0 -45
  91. data/docs/notes.md +0 -91
  92. data/docs/output.md +0 -63
  93. data/docs/presets.md +0 -361
  94. data/docs/usage.md +0 -143
  95. data/lib/jekyll_picture_tag/generated_image.rb +0 -161
  96. data/lib/jekyll_picture_tag/source_image.rb +0 -87
@@ -1,161 +0,0 @@
1
- require 'mini_magick'
2
- require 'base32'
3
-
4
- module PictureTag
5
- # Represents a generated image file.
6
- class GeneratedImage
7
- attr_reader :width, :format
8
- include MiniMagick
9
-
10
- def initialize(source_file:, width:, format:, crop: nil, gravity: '')
11
- @source = source_file
12
- @width = width
13
- @format = process_format format
14
- @crop = crop
15
- @gravity = gravity
16
- end
17
-
18
- def exists?
19
- File.exist?(absolute_filename)
20
- end
21
-
22
- def generate
23
- generate_image unless @source.missing || exists?
24
- end
25
-
26
- # /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
27
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28
- def absolute_filename
29
- @absolute_filename ||= File.join(PictureTag.dest_dir, name)
30
- end
31
-
32
- # /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
33
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34
- def name
35
- name_left + digest + name_right
36
- end
37
-
38
- # https://example.com/assets/images/myimage-100-123abc.jpg
39
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40
- def uri
41
- ImgURI.new(name).to_s
42
- end
43
-
44
- def cropped_source_width
45
- image.width
46
- end
47
-
48
- private
49
-
50
- # /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
51
- # ^^^^^^^^^^^^^^^^^^^^^^^
52
- def name_left
53
- "#{@source.base_name}-#{@width}-"
54
- end
55
-
56
- # /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
57
- # ^^^^^^
58
- def digest
59
- guess_digest if !@source.digest_guess && PictureTag.fast_build?
60
-
61
- @source.digest
62
- end
63
-
64
- # /home/dave/my_blog/_site/generated/somefolder/myimage-100-123abc.jpg
65
- # ^^^^
66
- def name_right
67
- crop_code + '.' + @format
68
- end
69
-
70
- # Hash the crop settings, so we can detect when they change. We use a
71
- # base32 encoding scheme to pack more information into fewer characters,
72
- # without dealing with various filesystem naming limitations that would crop
73
- # up using base64 (such as NTFS being case insensitive).
74
- def crop_code
75
- return '' unless @crop
76
-
77
- Base32.encode(
78
- Digest::MD5.hexdigest(@crop + @gravity)
79
- )[0..2]
80
- end
81
-
82
- # Used for the fast build option: look for a file which matches everything
83
- # we know about the destination file without calculating a digest on the
84
- # source file, and if it exists we assume it's the right one.
85
- def guess_digest
86
- matches = dest_glob
87
- return unless matches.length == 1
88
-
89
- # Start and finish of the destination image's hash value
90
- finish = -name_right.length
91
- start = finish - 6
92
-
93
- # The source image keeps track of this guess, so we hand it off:
94
- @source.digest_guess = matches.first[start...finish]
95
- end
96
-
97
- # Returns a list of images which are probably correct.
98
- def dest_glob
99
- query = File.join(
100
- PictureTag.dest_dir,
101
- name_left + '?' * 6 + name_right
102
- )
103
-
104
- Dir.glob query
105
- end
106
-
107
- def generate_image
108
- puts 'Generating new image file: ' + name
109
- process_image
110
- write_image
111
- end
112
-
113
- def image
114
- @image ||= open_image
115
- end
116
-
117
- def open_image
118
- image_base = Image.open(@source.name)
119
- image_base.combine_options do |i|
120
- i.auto_orient
121
- if @crop
122
- i.gravity @gravity
123
- i.crop @crop
124
- end
125
- end
126
-
127
- image_base
128
- end
129
-
130
- def process_image
131
- image.combine_options do |i|
132
- i.resize "#{@width}x"
133
- i.strip
134
- end
135
-
136
- image.format @format
137
- image.quality PictureTag.quality(@format)
138
- end
139
-
140
- def write_image
141
- # Make sure destination directory exists:
142
- FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir)
143
-
144
- image.write absolute_filename
145
-
146
- FileUtils.chmod(0o644, absolute_filename)
147
- end
148
-
149
- def dest_dir
150
- File.dirname absolute_filename
151
- end
152
-
153
- def process_format(format)
154
- if format.casecmp('original').zero?
155
- @source.ext
156
- else
157
- format.downcase
158
- end
159
- end
160
- end
161
- end
@@ -1,87 +0,0 @@
1
- module PictureTag
2
- # Handles a given source image file and its properties. Provides a speed
3
- # advantage by storing expensive file reads and writes in instance variables,
4
- # to be reused by many different generated images.
5
- class SourceImage
6
- attr_reader :name, :shortname, :missing, :media_preset
7
- attr_accessor :digest_guess
8
- include MiniMagick
9
-
10
- def initialize(relative_filename, media_preset = nil)
11
- @shortname = relative_filename
12
- @name = grab_file relative_filename
13
- @media_preset = media_preset
14
- end
15
-
16
- def width
17
- @width ||= if @missing
18
- 999_999
19
- else
20
- image.width
21
- end
22
- end
23
-
24
- def digest
25
- @digest ||= if @missing
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
31
- else
32
- Digest::MD5.hexdigest(File.read(@name))[0..5]
33
- end
34
- end
35
-
36
- # Includes path relative to default source folder and the original filename.
37
- def base_name
38
- @shortname.delete_suffix File.extname(@shortname)
39
- end
40
-
41
- # File exention
42
- def ext
43
- # [1..-1] will strip the leading period.
44
- @ext ||= File.extname(@name)[1..-1].downcase
45
- end
46
-
47
- private
48
-
49
- def image
50
- @image ||= Image.open(@name)
51
- end
52
-
53
- # Turn a relative filename into an absolute one, and make sure it exists.
54
- def grab_file(source_file)
55
- source_name = File.join(PictureTag.source_dir, source_file)
56
-
57
- if File.exist? source_name
58
- @missing = false
59
-
60
- elsif PictureTag.continue_on_missing?
61
- @missing = true
62
- Utils.warning missing_image_warning(source_name)
63
-
64
- else
65
- raise ArgumentError, missing_image_error(source_name)
66
- end
67
-
68
- source_name
69
- end
70
-
71
- def missing_image_warning(source_name)
72
- <<~HEREDOC
73
- Could not find #{source_name}. Your site will have broken images in it.
74
- Continuing.
75
- HEREDOC
76
- end
77
-
78
- def missing_image_error(source_name)
79
- <<~HEREDOC
80
- Jekyll Picture Tag could not find #{source_name}. You can force the
81
- build to continue anyway by setting "picture: ignore_missing_images:
82
- true" in "_config.yml". This setting can also accept a jekyll build
83
- environment, or an array of environments.
84
- HEREDOC
85
- end
86
- end
87
- end