jekyll_picture_tag 1.11.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +4 -0
  3. data/.github/workflows/code-checks.yml +33 -0
  4. data/.gitignore +3 -0
  5. data/.rubocop.yml +31 -3
  6. data/.ruby-version +1 -1
  7. data/docs/.envrc +2 -0
  8. data/docs/Gemfile +4 -2
  9. data/docs/Gemfile.lock +14 -12
  10. data/docs/_config.yml +6 -10
  11. data/docs/devs/contributing/code.md +54 -0
  12. data/docs/devs/contributing/docs.md +31 -0
  13. data/docs/devs/contributing/index.md +15 -0
  14. data/docs/devs/contributing/setup.md +33 -0
  15. data/docs/devs/contributing/testing.md +23 -0
  16. data/docs/devs/index.md +7 -0
  17. data/docs/devs/releases.md +118 -0
  18. data/docs/index.md +67 -31
  19. data/docs/logo.png +0 -0
  20. data/docs/logo.svg +880 -0
  21. data/docs/users/configuration/directories.md +34 -0
  22. data/docs/users/configuration/disable.md +24 -0
  23. data/docs/users/configuration/fast_build.md +28 -0
  24. data/docs/users/configuration/ignore_missing.md +23 -0
  25. data/docs/users/configuration/index.md +29 -0
  26. data/docs/users/configuration/kramdown_fix.md +20 -0
  27. data/docs/users/configuration/suppress_warnings.md +16 -0
  28. data/docs/users/configuration/urls.md +69 -0
  29. data/docs/users/getting_started.md +55 -0
  30. data/docs/users/index.md +7 -0
  31. data/docs/users/installation.md +32 -0
  32. data/docs/users/liquid_tag/argument_reference/alternate_images.md +18 -0
  33. data/docs/users/liquid_tag/argument_reference/attributes.md +42 -0
  34. data/docs/users/liquid_tag/argument_reference/base_image.md +12 -0
  35. data/docs/users/liquid_tag/argument_reference/crop.md +33 -0
  36. data/docs/users/liquid_tag/argument_reference/link.md +16 -0
  37. data/docs/users/liquid_tag/argument_reference/preset.md +17 -0
  38. data/docs/users/liquid_tag/argument_reference/readme.md +9 -0
  39. data/docs/users/liquid_tag/examples.md +81 -0
  40. data/docs/users/liquid_tag/index.md +31 -0
  41. data/docs/users/notes/git_lfs.md +7 -0
  42. data/docs/users/notes/github_pages.md +5 -0
  43. data/docs/users/notes/html_attributes.md +5 -0
  44. data/docs/users/notes/index.md +6 -0
  45. data/docs/users/notes/kramdown_bug.md +41 -0
  46. data/docs/users/notes/managing_images.md +21 -0
  47. data/docs/{migration.md → users/notes/migration_1.md} +1 -1
  48. data/docs/users/notes/migration_2.md +99 -0
  49. data/docs/users/presets/cropping.md +60 -0
  50. data/docs/users/presets/default.md +32 -0
  51. data/docs/users/presets/examples.md +111 -0
  52. data/docs/users/presets/fallback_image.md +28 -0
  53. data/docs/users/presets/html_attributes.md +26 -0
  54. data/docs/users/presets/image_formats.md +21 -0
  55. data/docs/users/presets/image_quality.md +120 -0
  56. data/docs/users/presets/index.md +75 -0
  57. data/docs/users/presets/link_source.md +16 -0
  58. data/docs/users/presets/markup_formats/fragments.md +48 -0
  59. data/docs/users/presets/markup_formats/javascript_friendly.md +57 -0
  60. data/docs/users/presets/markup_formats/readme.md +43 -0
  61. data/docs/users/presets/markup_formats/standard_html.md +25 -0
  62. data/docs/users/presets/media_queries.md +36 -0
  63. data/docs/users/presets/nomarkdown_override.md +17 -0
  64. data/docs/users/presets/pixel_ratio_srcsets.md +32 -0
  65. data/docs/users/presets/quality_width_graph.png +0 -0
  66. data/docs/users/presets/width_height_attributes.md +34 -0
  67. data/docs/users/presets/width_srcsets.md +123 -0
  68. data/docs/users/presets/writing_presets.md +65 -0
  69. data/docs/users/tutorial.md +97 -0
  70. data/jekyll_picture_tag.gemspec +38 -23
  71. data/lib/jekyll_picture_tag.rb +11 -10
  72. data/lib/jekyll_picture_tag/cache.rb +64 -3
  73. data/lib/jekyll_picture_tag/defaults/global.rb +18 -0
  74. data/lib/jekyll_picture_tag/defaults/presets.rb +57 -0
  75. data/lib/jekyll_picture_tag/images.rb +4 -0
  76. data/lib/jekyll_picture_tag/images/generated_image.rb +92 -0
  77. data/lib/jekyll_picture_tag/images/image_file.rb +90 -0
  78. data/lib/jekyll_picture_tag/{img_uri.rb → images/img_uri.rb} +3 -10
  79. data/lib/jekyll_picture_tag/{source_image.rb → images/source_image.rb} +44 -9
  80. data/lib/jekyll_picture_tag/instructions.rb +70 -6
  81. data/lib/jekyll_picture_tag/instructions/children/config.rb +128 -0
  82. data/lib/jekyll_picture_tag/instructions/children/context.rb +24 -0
  83. data/lib/jekyll_picture_tag/instructions/children/params.rb +90 -0
  84. data/lib/jekyll_picture_tag/instructions/children/parsers.rb +41 -0
  85. data/lib/jekyll_picture_tag/instructions/children/preset.rb +182 -0
  86. data/lib/jekyll_picture_tag/instructions/parents/conditional_instruction.rb +69 -0
  87. data/lib/jekyll_picture_tag/instructions/parents/env_instruction.rb +29 -0
  88. data/lib/jekyll_picture_tag/output_formats/basic.rb +5 -17
  89. data/lib/jekyll_picture_tag/parsers.rb +5 -0
  90. data/lib/jekyll_picture_tag/{instructions → parsers}/arg_splitter.rb +1 -1
  91. data/lib/jekyll_picture_tag/parsers/configuration.rb +28 -0
  92. data/lib/jekyll_picture_tag/{instructions → parsers}/html_attributes.rb +1 -1
  93. data/lib/jekyll_picture_tag/parsers/preset.rb +43 -0
  94. data/lib/jekyll_picture_tag/{instructions → parsers}/tag_parser.rb +15 -12
  95. data/lib/jekyll_picture_tag/router.rb +35 -93
  96. data/lib/jekyll_picture_tag/srcsets/basic.rb +4 -10
  97. data/lib/jekyll_picture_tag/utils.rb +24 -20
  98. data/lib/jekyll_picture_tag/version.rb +1 -1
  99. data/readme.md +15 -13
  100. metadata +215 -93
  101. data/.travis.yml +0 -8
  102. data/Dockerfile +0 -9
  103. data/docs/_layouts/directory.html +0 -32
  104. data/docs/assets/style.css +0 -31
  105. data/docs/contributing.md +0 -109
  106. data/docs/example_presets.md +0 -116
  107. data/docs/global_configuration.md +0 -173
  108. data/docs/installation.md +0 -45
  109. data/docs/notes.md +0 -91
  110. data/docs/output.md +0 -63
  111. data/docs/presets.md +0 -391
  112. data/docs/releases.md +0 -70
  113. data/docs/usage.md +0 -157
  114. data/jekyll-picture-tag.gemspec +0 -52
  115. data/lib/jekyll-picture-tag.rb +0 -25
  116. data/lib/jekyll_picture_tag/cache/base.rb +0 -59
  117. data/lib/jekyll_picture_tag/cache/generated.rb +0 -20
  118. data/lib/jekyll_picture_tag/cache/source.rb +0 -19
  119. data/lib/jekyll_picture_tag/defaults/global.yml +0 -11
  120. data/lib/jekyll_picture_tag/defaults/presets.yml +0 -11
  121. data/lib/jekyll_picture_tag/generated_image.rb +0 -140
  122. data/lib/jekyll_picture_tag/instructions/configuration.rb +0 -121
  123. data/lib/jekyll_picture_tag/instructions/preset.rb +0 -103
  124. data/lib/jekyll_picture_tag/instructions/set.rb +0 -71
data/docs/releases.md DELETED
@@ -1,70 +0,0 @@
1
- ---
2
- ---
3
- # Release History
4
- * 1.11.0 July 27, 2020
5
- * **Width and height attribute support!** Begone, page reflow.
6
- * Cache image information between builds
7
- * Change image naming format. This update will trigger all images to be regenerated, so you may
8
- want to delete your generated images folder beforehand.
9
- * 1.10.2 July 6, 2020
10
- * Bugfix for fallback image files not actually getting generated
11
- * 1.10.1 July 2, 2020
12
- * Bugfix for erroneously regenerated images
13
- * 1.10.0 May 11, 2020
14
- * **Image Cropping support!** access the power of ImageMagick's `crop` function.
15
- * Don't issue a warning when `default` preset is not found.
16
- * Documentation improvements
17
- * 1.9.0 Feb 2, 2020
18
- * Add `fast_build` global setting
19
- * Add `disabled` global setting
20
- * Reduce unnecessary disk IO; sites with many source images should see build times improve when
21
- no new images need to be generated.
22
- * Add support for empty attributes; specifically so best-practice for decorative images (`alt=""`)
23
- is possible.
24
- * 1.8.0 Nov 25, 2019
25
- * Add `data_sizes` setting for the `data_` family of output formats.
26
- * 1.7.1 Nov 14, 2019
27
- * Fix some HTML attribute related bugs
28
- * Add a few items to the FAQ
29
- * 1.7.0 Aug 12, 2019
30
- * Add support for setting generated image quality, either generally or specific to given
31
- formats.
32
- * Add support for spaces and other url-encoded characters in filenames
33
- * Documentation restructure - Moved it out of the wiki, into the `docs` folder.
34
- * Bugfix: Fallback image width will now be checked against source image width.
35
- * Bugfix: Minor fix to nomarkdown wrapper output
36
- * link_source will now target the base source image, rather than finding the biggest one.
37
- * Remove fastimage dependency, add addressable dependency.
38
- * Moderately significant refactoring and code cleanup
39
- * Decent set of tests added
40
- * 1.6.0 Jul 2, 2019:
41
- * Missing Preset warning respects `data_dir` setting
42
- * Add `continue_on_missing` option
43
- * 1.5.0 Jun 26, 2019:
44
- * better `{::nomarkdown}` necessity detection
45
- * allow user to override `{::nomarkdown}` autodetection
46
- * 1.4.0 Jun 26, 2019:
47
- * Rename gem from `jekyll-picture-tag` to `jekyll_picture_tag`, allowing us to use rubygems again.
48
- * Add new output format: `naked_srcset`.
49
- * 1.3.1 Jun 21, 2019: Bugfix
50
- * 1.3.0 Jun 7, 2019:
51
- * Initial compatibility with Jekyll 4.0
52
- * bugfixes
53
- * change to generated image naming-- The first build after this update will be longer, and you
54
- might want to clear out your generated images.
55
- * 1.2.0 Feb 9, 2019:
56
- * Add nomarkdown fix
57
- * noscript option
58
- * relative url option
59
- * anchor tag wrappers
60
- * 1.1.0 Jan 22, 2019:
61
- * Add direct_url markup format,
62
- * auto-orient images before stripping metadata
63
- * 1.0.2 Jan 18, 2019: Fix ruby version specification
64
- * 1.0.1 Jan 13, 2019: Added ruby version checking
65
- * **1.0.0** Nov 27, 2018: Rewrite from the ground up. See the [migration guide]({{ site.baseurl }}/migration).
66
- * 0.2.2 Aug 2, 2013: Bugfixes
67
- * 0.2.1 Jul 17, 2013: Refactor again, add Liquid parsing.
68
- * 0.2.0 Jul 14, 2013: Rewrite code base, bring in line with Jekyll Image Tag.
69
- * 0.1.1 Jul 5, 2013: Quick round of code improvements.
70
- * 0.1.0 Jul 5, 2013: Initial release.
data/docs/usage.md DELETED
@@ -1,157 +0,0 @@
1
- ---
2
- ---
3
-
4
- # How to use the Liquid Tag:
5
-
6
- This section describes how to use JPT's liquid tag; what options it takes and what kind of information you can pass through it to influence the form of the final HTML-markup.
7
-
8
- ## Format:
9
-
10
- {% raw %}
11
- `{% picture [preset] (image) [crop] [alternate images & crops] [attributes] %}`
12
- {% endraw %}
13
-
14
- The only required argument is the base image. Line breaks and extra spaces are fine, and you can
15
- use liquid variables anywhere.
16
-
17
- The `preset` determines the actual HTML code that gets written to your files;
18
- it is basically a recipy that takes information that you provide in the
19
- liquid tag and turns it into HTML markup. When the `preset` is omitted
20
- default settings will be used, in the simplest case resulting in an `img`-tag
21
- containing an srcset pointing to your newly generated image sizes. You are
22
- free to override the `default` preset and define your own presets, giving
23
- full flexibility in what JPT will write to your files. See [markup preset]({{
24
- site.baseurl }}/presets#markup-presets) for more information on this.
25
-
26
- ## Examples:
27
-
28
- {% raw %}
29
- `{% picture example.jpg %}`
30
-
31
- `{% picture {{ page.example_liquid_picture_var }} %}`
32
-
33
- `{% picture thumbnail example.jpg 1:1 --alt Example Image %}`
34
-
35
- `{% picture example.jpg 16:9 north --picture class="attribute-demo" %}`
36
-
37
- `{% picture blog_index {{ post.image }} --link {{ post.url }} %}`
38
-
39
- `{% picture "some example.jpg" mobile: other\ example.jpg %}`
40
-
41
- ```md
42
- {% picture
43
- hero
44
- example.jpg 16:9 east
45
- tablet: example_cropped.jpg 3:2 east
46
- mobile: example_cropped_more.jpg 1:1-50+0 east
47
- --alt Happy Puppy
48
- --picture class="hero"
49
- --link /
50
- %}
51
- ```
52
-
53
- {% endraw %}
54
-
55
- ## Argument reference
56
-
57
- Given in order:
58
-
59
- - **Preset**
60
-
61
- Select a [markup preset]({{ site.baseurl }}/presets#markup-presets), or omit to use the `default` preset. Presets
62
- are collections of settings that determine nearly everything about JPT's output, from the image
63
- formats used to the exact format your final HTML-markup will take.
64
-
65
- - **Base Image** (Required)
66
-
67
- Can be any raster image (as long as you have the required ImageMagick delegate). Relative to
68
- jekyll's root directory, or the `source` [setting]({{ site.baseurl }}/global_configuration) if you've configured it.
69
-
70
- For filenames with spaces, either use double quotes (`"my image.jpg"`) or a backslash (`my\ image.jpg`).
71
-
72
- - **Crop**
73
-
74
- **Check the [ installation guide ](installation) before using this feature.**
75
-
76
- Crop an image to a given aspect ratio or size. This argument is given as a `geometry` and
77
- (optionally) a `gravity`, which can appear in either order and are thin wrappers around
78
- ImageMagick's [geometry](http://www.imagemagick.org/script/command-line-processing.php#geometry)
79
- and [gravity](http://www.imagemagick.org/script/command-line-options.php#gravity) settings. The
80
- values given here will override the preset settings (if present), can be given after every image,
81
- and apply only to the preceding image.
82
-
83
- Geometry can take many forms, but most likely you'll want to set an aspect ratio-- given in the
84
- standard `width:height` ratio such as `3:2`. Gravity sets which portion of the image to keep, and
85
- is given in compass directions (`north`, `southeast`, etc) or `center` (default). Cropping happens
86
- before resizing; the preset `widths` setting is a post-crop value.
87
-
88
- If you'd like more fine-grained control, this can be offset by appending `+|-x` and (optionally)
89
- `y` pixel values to the _geometry_ (not the gravity!). Example: `1:1+400 west` means "Crop to a
90
- 1:1 aspect ratio, starting 400 pixels from the left side.", and `north 3:2+0+100` means "Crop to
91
- 3:2, starting 100 pixels from the top." These can get a bit persnickety; there's nothing to stop
92
- you from running off the side of the image. Pay attention.
93
-
94
- For detailed documentation, see ImageMagick's
95
- [crop](http://www.imagemagick.org/script/command-line-options.php#crop) tool.
96
-
97
- _Note:_ If you do a lot of trial and error with these, it's a good idea to manually delete your
98
- generated images folder more often as each change will build a new set of images without removing
99
- the old ones.
100
-
101
- - **Alternate images**
102
-
103
- _Format:_ `(media query preset): (filename) (...)`
104
-
105
- _Example:_ `tablet: img_cropped.jpg mobile: img_cropped_more.jpg`
106
-
107
- Optionally specify any number of alternate base images for given [screen
108
- sizes]({{ site.baseurl }}/presets/#media-presets) (specified in `_data/picture.yml`). This is called [art
109
- direction](http://usecases.responsiveimages.org/#art-direction), and is one of JPT's strongest
110
- features.
111
-
112
- Give your images in order of ascending specificity (The first image is the most general). They will
113
- be provided to the browser in reverse order, and it will select the first one with an applicable
114
- media query.
115
-
116
- - **Attributes**
117
-
118
- Optionally specify any number of HTML attributes, or an href target. These will be added to any
119
- attributes you've set in a preset.
120
-
121
- - **`--link`**
122
-
123
- _Format:_ `--link (some url)`
124
-
125
- _Examples_: `--link https://example.com`, `--link /blog/some_post/`
126
-
127
- Wrap the image in an anchor tag, with the `href` attribute set to whatever value you give it.
128
- This will override automatic source image linking, if you have enabled it.
129
-
130
- **Note**: If you get either mangled HTML or extra {::nomarkdown} tags when using this, read
131
- [here]({{ site.baseurl }}/notes).
132
-
133
- - **`--alt`**
134
-
135
- _Format:_ `--alt (alt text)`
136
-
137
- _Example:_ `--alt Here is my alt text!`
138
-
139
- Convenience shortcut for `--img alt="..."`
140
-
141
- - **`--(element)`**
142
-
143
- _Format:_ `--(picture|img|source|a|parent) (Standard HTML attributes)`
144
-
145
- _Example:_ `--img class="awesome-fade-in" id="coolio" --a data-awesomeness="11"`
146
-
147
- Apply attributes to a given HTML element. Your options are:
148
-
149
- - `picture`
150
- - `img`
151
- - `source`
152
- - `a` (anchor tag)
153
- - `parent`
154
-
155
- `--parent` will be applied to the `<picture>` if present, otherwise the `<img>`; useful when
156
- using an `auto` output format.
157
- **Note:** Attributes that are set in the liquid picture tag, but don't occur in the used `preset` will be ignored (e.g. adding `--picture class="cool-css"` with a preset that does not write a html `<picture>` tag).
@@ -1,52 +0,0 @@
1
- # Why 2 gemspecs?
2
- #
3
- # Originally, this gem was named 'jekyll-picture-tag', and published on rubygems
4
- # under this name. There was a break in development, during which push access to
5
- # rubygems was lost. Development was later resumed, and as a workaround for that
6
- # issue the installation instructions were to source the gem from the Github
7
- # repository.
8
- #
9
- # Ultimately, the decision was made to rename it by switching the dashes for
10
- # underscores, which follows best practice and allows pushing it to rubygems
11
- # under the new name. The drawback of this situation is that everyone who
12
- # followed the installaion instructions previously would see their site
13
- # inexplicably break, as it would be searching for a gemspec that doesn't exist.
14
- # As a workaround (to the old workaround... sigh) this gemspec lets us print a
15
- # warning and then require the new version, which keeps old sites working while
16
- # encouraging people to use rubygems.
17
-
18
- lib = File.expand_path('lib', __dir__)
19
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
- require 'jekyll_picture_tag/version'
21
-
22
- Gem::Specification.new do |spec|
23
- spec.name = 'jekyll-picture-tag'
24
- spec.version = PictureTag::VERSION
25
- spec.authors = ['Robert Wierzbowski', 'Brendan Tobolaski',
26
- 'Robert Buchberger']
27
- spec.email = ['robert@buchberger.cc']
28
-
29
- spec.summary = 'Easy responsive images for Jekyll.'
30
- spec.description = <<~HEREDOC
31
- ____ _ _
32
- | _ \ ___ _ __ _ __ ___ ___ __ _| |_ ___ __| |
33
- | | | |/ _ \ '_ \| '__/ _ \/ __/ _` | __/ _ \/ _` |
34
- | |_| | __/ |_) | | | __/ (_| (_| | || __/ (_| |
35
- |____/ \___| .__/|_| \___|\___\__,_|\__\___|\__,_|
36
- |_|
37
-
38
- This gem has been renamed! Use jekyll_picture_tag instead, which is now
39
- hosted on rubygems.
40
- HEREDOC
41
- spec.homepage = 'https://github.com/rbuchberger/jekyll_picture_tag'
42
- spec.license = 'BSD-3-Clause'
43
- spec.require_paths = ['lib']
44
-
45
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
46
- f.match(%r{^(test|spec|features)/})
47
- end
48
-
49
- spec.required_ruby_version = ['>= 2.5', '< 3']
50
-
51
- spec.add_dependency 'jekyll_picture_tag'
52
- end
@@ -1,25 +0,0 @@
1
- # rubocop:disable Naming/FileName
2
- puts '-' * 80
3
- # rubocop:enable Naming/FileName
4
-
5
- puts <<~HEREDOC
6
- \033[31;1;4m
7
- Important message from Jekyll Picture Tag:
8
- \033[0m
9
- Good news! We're back up on rubygems.
10
- Bad news. You need to update your Gemfile. Remove the following line:
11
-
12
- gem 'jekyll-picture-tag', git: 'https://github.com/robwierzbowski/jekyll-picture-tag/'
13
-
14
- and replace it with something like:
15
-
16
- gem 'jekyll_picture_tag', '~> 1.6'
17
-
18
- Sorry about that. For an explanation, see issue #120:
19
- https://github.com/rbuchberger/jekyll-picture-tag/issues/120
20
-
21
- HEREDOC
22
-
23
- puts '-' * 80
24
-
25
- require 'jekyll_picture_tag'
@@ -1,59 +0,0 @@
1
- require 'json'
2
-
3
- module PictureTag
4
- module Cache
5
- # Basic image information cache functionality
6
- module Base
7
- def initialize(base_name)
8
- @base_name = base_name
9
- end
10
-
11
- def [](key)
12
- data[key]
13
- end
14
-
15
- def []=(key, value)
16
- raise ArgumentError unless template.keys.include? key
17
-
18
- data[key] = value
19
- end
20
-
21
- # Call after updating data.
22
- def write
23
- FileUtils.mkdir_p(File.join(base_directory, sub_directory))
24
-
25
- File.open(filename, 'w+') do |f|
26
- f.write JSON.generate(data)
27
- end
28
- end
29
-
30
- private
31
-
32
- def data
33
- @data ||= if File.exist?(filename)
34
- JSON.parse(File.read(filename)).transform_keys(&:to_sym)
35
- else
36
- template
37
- end
38
- end
39
-
40
- # /home/dave/my_blog/.jekyll-cache/jpt/(cache_dir)/assets/myimage.jpg.json
41
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42
- def base_directory
43
- File.join(PictureTag.site.cache_dir, 'jpt', cache_dir)
44
- end
45
-
46
- # /home/dave/my_blog/.jekyll-cache/jpt/(cache_dir)/assets/myimage.jpg.json
47
- # ^^^^^^^^
48
- def sub_directory
49
- File.dirname(@base_name)
50
- end
51
-
52
- # /home/dave/my_blog/.jekyll-cache/jpt/somefolder/myimage.jpg.json
53
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54
- def filename
55
- File.join(base_directory, @base_name + '.json')
56
- end
57
- end
58
- end
59
- end
@@ -1,20 +0,0 @@
1
- module PictureTag
2
- module Cache
3
- # Caches generated image details, so we can skip expensive operations whenever
4
- # possible.
5
- # Stored width and height are values for the source image, after cropping.
6
- class Generated
7
- include Base
8
-
9
- private
10
-
11
- def cache_dir
12
- 'generated'
13
- end
14
-
15
- def template
16
- { width: nil, height: nil }
17
- end
18
- end
19
- end
20
- end
@@ -1,19 +0,0 @@
1
- module PictureTag
2
- module Cache
3
- # Caches source image details, so we can skip expensive operations whenever
4
- # possible.
5
- class Source
6
- include Base
7
-
8
- private
9
-
10
- def template
11
- { digest: nil, width: nil, height: nil }
12
- end
13
-
14
- def cache_dir
15
- 'source'
16
- end
17
- end
18
- end
19
- end
@@ -1,11 +0,0 @@
1
- # Default settings for _config.yml
2
- picture:
3
- source: ''
4
- output: generated
5
- suppress_warnings: false
6
- relative_url: true
7
- cdn_environments: ['production']
8
- nomarkdown: true
9
- ignore_missing_images: false
10
- disabled: false
11
- fast_build: false
@@ -1,11 +0,0 @@
1
- markup: auto
2
- formats: [original]
3
- widths: [400, 600, 800, 1000]
4
- fallback_width: 800
5
- fallback_format: original
6
- noscript: false
7
- link_source: false
8
- quality: 75
9
- data_sizes: true
10
- gravity: center
11
- dimension_attributes: false
@@ -1,140 +0,0 @@
1
- require 'mini_magick'
2
-
3
- module PictureTag
4
- # Represents a generated image file.
5
- class GeneratedImage
6
- attr_reader :width, :format
7
-
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 ||= "#{@source.base_name}-#{@width}-#{id}.#{@format}"
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
- # Post crop
45
- def source_width
46
- update_cache unless cache[:width]
47
-
48
- cache[:width]
49
- end
50
-
51
- # Post crop
52
- def source_height
53
- update_cache unless cache[:height]
54
-
55
- cache[:height]
56
- end
57
-
58
- private
59
-
60
- # We exclude width and format from the cache name, since it isn't specific to them.
61
- def cache
62
- @cache ||= Cache::Generated.new("#{@source.base_name}-#{id}")
63
- end
64
-
65
- def update_cache
66
- return if @source.missing
67
-
68
- # Ensure it's generated:
69
- image
70
-
71
- cache[:width] = @source_dimensions[:width]
72
- cache[:height] = @source_dimensions[:height]
73
-
74
- cache.write
75
- end
76
-
77
- # Hash all inputs and truncate, so we know when they change without getting too long.
78
- # /home/dave/my_blog/_site/generated/somefolder/myimage-100-1234abcde.jpg
79
- # ^^^^^^^^^
80
- def id
81
- @id ||= Digest::MD5.hexdigest([@source.digest, @crop, @gravity, quality].join)[0..8]
82
- end
83
-
84
- # Post crop, before resizing and reformatting
85
- def image
86
- @image ||= open_image
87
- end
88
-
89
- def open_image
90
- image_base = Image.open(@source.name)
91
- image_base.combine_options do |i|
92
- i.auto_orient
93
- if @crop
94
- i.gravity @gravity
95
- i.crop @crop
96
- end
97
- end
98
-
99
- @source_dimensions = { width: image_base.width, height: image_base.height }
100
-
101
- image_base
102
- end
103
-
104
- def generate_image
105
- puts 'Generating new image file: ' + name
106
- process_image
107
- write_image
108
- end
109
-
110
- def quality
111
- PictureTag.quality(@format)
112
- end
113
-
114
- def process_image
115
- image.combine_options do |i|
116
- i.resize "#{@width}x"
117
- i.strip
118
- end
119
-
120
- image.format @format
121
- image.quality quality
122
- end
123
-
124
- def write_image
125
- FileUtils.mkdir_p(File.dirname(absolute_filename))
126
-
127
- image.write absolute_filename
128
-
129
- FileUtils.chmod(0o644, absolute_filename)
130
- end
131
-
132
- def process_format(format)
133
- if format.casecmp('original').zero?
134
- @source.ext
135
- else
136
- format.downcase
137
- end
138
- end
139
- end
140
- end