jekyll_picture_tag 1.14.0 → 2.0.0pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +2 -0
  3. data/.github/workflows/code-checks.yml +2 -12
  4. data/.rubocop.yml +2 -0
  5. data/.ruby-version +1 -1
  6. data/docs/devs/contributing/code.md +11 -3
  7. data/docs/devs/contributing/testing.md +0 -11
  8. data/docs/devs/releases.md +20 -0
  9. data/docs/index.md +32 -17
  10. data/docs/logo.png +0 -0
  11. data/docs/logo.svg +880 -0
  12. data/docs/users/getting_started.md +55 -0
  13. data/docs/users/installation.md +17 -38
  14. data/docs/users/liquid_tag/argument_reference/crop.md +21 -36
  15. data/docs/users/liquid_tag/examples.md +13 -25
  16. data/docs/users/liquid_tag/index.md +1 -1
  17. data/docs/users/notes/{migration.md → migration_1.md} +1 -1
  18. data/docs/users/notes/migration_2.md +99 -0
  19. data/docs/users/presets/cropping.md +21 -22
  20. data/docs/users/presets/default.md +11 -3
  21. data/docs/users/presets/examples.md +77 -45
  22. data/docs/users/presets/fallback_image.md +1 -1
  23. data/docs/users/presets/html_attributes.md +1 -1
  24. data/docs/users/presets/image_formats.md +3 -3
  25. data/docs/users/presets/image_quality.md +70 -55
  26. data/docs/users/presets/index.md +78 -42
  27. data/docs/users/presets/link_source.md +1 -1
  28. data/docs/users/presets/media_queries.md +1 -1
  29. data/docs/users/presets/nomarkdown_override.md +1 -1
  30. data/docs/users/presets/pixel_ratio_srcsets.md +1 -1
  31. data/docs/users/presets/width_height_attributes.md +1 -1
  32. data/docs/users/presets/width_srcsets.md +61 -23
  33. data/docs/users/tutorial.md +97 -0
  34. data/jekyll_picture_tag.gemspec +33 -23
  35. data/lib/jekyll_picture_tag.rb +8 -6
  36. data/lib/jekyll_picture_tag/cache.rb +64 -3
  37. data/lib/jekyll_picture_tag/defaults/global.rb +18 -0
  38. data/lib/jekyll_picture_tag/defaults/presets.rb +57 -0
  39. data/lib/jekyll_picture_tag/images.rb +1 -0
  40. data/lib/jekyll_picture_tag/images/generated_image.rb +25 -63
  41. data/lib/jekyll_picture_tag/images/image_file.rb +90 -0
  42. data/lib/jekyll_picture_tag/images/img_uri.rb +3 -12
  43. data/lib/jekyll_picture_tag/images/source_image.rb +44 -9
  44. data/lib/jekyll_picture_tag/instructions.rb +70 -6
  45. data/lib/jekyll_picture_tag/instructions/children/config.rb +128 -0
  46. data/lib/jekyll_picture_tag/instructions/children/context.rb +24 -0
  47. data/lib/jekyll_picture_tag/instructions/children/params.rb +90 -0
  48. data/lib/jekyll_picture_tag/instructions/children/parsers.rb +41 -0
  49. data/lib/jekyll_picture_tag/instructions/children/preset.rb +182 -0
  50. data/lib/jekyll_picture_tag/instructions/parents/conditional_instruction.rb +69 -0
  51. data/lib/jekyll_picture_tag/instructions/parents/env_instruction.rb +29 -0
  52. data/lib/jekyll_picture_tag/output_formats/basic.rb +5 -17
  53. data/lib/jekyll_picture_tag/parsers.rb +5 -0
  54. data/lib/jekyll_picture_tag/{instructions → parsers}/arg_splitter.rb +1 -1
  55. data/lib/jekyll_picture_tag/parsers/configuration.rb +28 -0
  56. data/lib/jekyll_picture_tag/{instructions → parsers}/html_attributes.rb +1 -1
  57. data/lib/jekyll_picture_tag/parsers/preset.rb +43 -0
  58. data/lib/jekyll_picture_tag/{instructions → parsers}/tag_parser.rb +15 -12
  59. data/lib/jekyll_picture_tag/router.rb +35 -93
  60. data/lib/jekyll_picture_tag/srcsets/basic.rb +4 -10
  61. data/lib/jekyll_picture_tag/utils.rb +10 -20
  62. data/lib/jekyll_picture_tag/version.rb +1 -1
  63. data/readme.md +2 -0
  64. metadata +124 -106
  65. data/Dockerfile +0 -9
  66. data/docs/users/notes/input_checking.md +0 -6
  67. data/docs/users/presets/strip_metadata.md +0 -13
  68. data/install_imagemagick.sh +0 -23
  69. data/jekyll-picture-tag.gemspec +0 -52
  70. data/lib/jekyll-picture-tag.rb +0 -25
  71. data/lib/jekyll_picture_tag/cache/base.rb +0 -61
  72. data/lib/jekyll_picture_tag/cache/generated.rb +0 -20
  73. data/lib/jekyll_picture_tag/cache/source.rb +0 -19
  74. data/lib/jekyll_picture_tag/defaults/global.yml +0 -13
  75. data/lib/jekyll_picture_tag/defaults/presets.yml +0 -12
  76. data/lib/jekyll_picture_tag/instructions/configuration.rb +0 -121
  77. data/lib/jekyll_picture_tag/instructions/preset.rb +0 -122
  78. data/lib/jekyll_picture_tag/instructions/set.rb +0 -75
data/Dockerfile DELETED
@@ -1,9 +0,0 @@
1
- FROM ruby:alpine
2
- WORKDIR /root/jekyll_picture_tag
3
- # Dependencies for nokogiri, eventmachine, and JPT
4
- RUN apk add git imagemagick g++ musl-dev make libstdc++ zlib build-base
5
- COPY Gemfile* jekyll_picture_tag.gemspec ./
6
- COPY lib/jekyll_picture_tag/version.rb ./lib/jekyll_picture_tag/version.rb
7
- RUN bundle install
8
- COPY . .
9
- CMD rake
@@ -1,6 +0,0 @@
1
- # Getting cryptic build errors?
2
-
3
- Jekyll Picture Tag is very trusting. It doesn't do much checking of your inputs, and it does not
4
- fail gracefully if you for example pass it a string when it expects an array. It's on the to-do
5
- list, but for now if you get cryptic errors then double-check your settings and tag arguments.
6
-
@@ -1,13 +0,0 @@
1
- ---
2
- sort: 12
3
- ---
4
-
5
- # Strip Metadata
6
-
7
- _Format:_ `strip_metadata: (true|false)`
8
-
9
- _Example:_ `strip_metadata: false`
10
-
11
- _Default:_ `true`
12
-
13
- Remove EXIF data, which can save a few tens of kilobytes per image.
@@ -1,23 +0,0 @@
1
- # Configure and install imagemagick; detects if cached compiled version exists.
2
-
3
- check_cached() {
4
- [ "$(find . -name '*.o')" ]
5
- }
6
-
7
- build_im() {
8
- git clone 'https://github.com/ImageMagick/ImageMagick' ./ \
9
- --branch "$imagemagick_version"
10
-
11
- rm -rf '.git'
12
-
13
- ./configure
14
- make
15
- }
16
-
17
- [ -d 'imagemagick' ] || mkdir imagemagick
18
- cd imagemagick
19
-
20
- check_cached || build_im
21
-
22
- sudo make install
23
- sudo ldconfig /usr/local/lib
@@ -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,61 +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
- return if PictureTag.site.config['disable_disk_cache']
24
-
25
- FileUtils.mkdir_p(File.join(base_directory, sub_directory))
26
-
27
- File.open(filename, 'w+') do |f|
28
- f.write JSON.generate(data)
29
- end
30
- end
31
-
32
- private
33
-
34
- def data
35
- @data ||= if File.exist?(filename)
36
- JSON.parse(File.read(filename)).transform_keys(&:to_sym)
37
- else
38
- template
39
- end
40
- end
41
-
42
- # /home/dave/my_blog/.jekyll-cache/jpt/(cache_dir)/assets/myimage.jpg.json
43
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44
- def base_directory
45
- File.join(PictureTag.site.cache_dir, 'jpt', cache_dir)
46
- end
47
-
48
- # /home/dave/my_blog/.jekyll-cache/jpt/(cache_dir)/assets/myimage.jpg.json
49
- # ^^^^^^^^
50
- def sub_directory
51
- File.dirname(@base_name)
52
- end
53
-
54
- # /home/dave/my_blog/.jekyll-cache/jpt/somefolder/myimage.jpg.json
55
- # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56
- def filename
57
- File.join(base_directory, @base_name + '.json')
58
- end
59
- end
60
- end
61
- 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,13 +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
12
- ignore_baseurl: false
13
- baseurl_key: 'baseurl'
@@ -1,12 +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
12
- strip_metadata: true
@@ -1,121 +0,0 @@
1
- module PictureTag
2
- module Instructions
3
- # Global config (big picture). loads jekyll data/config files, and the j-p-t
4
- # defaults from included yml files.
5
- class Configuration
6
- # returns jekyll's configuration (picture is a subset)
7
- def [](key)
8
- content[key]
9
- end
10
-
11
- # picturetag specific configuration
12
- def pconfig
13
- content['picture']
14
- end
15
-
16
- # Digs into jekyll context, returns current environment
17
- def jekyll_env
18
- # It would be really great if the jekyll devs actually documented
19
- # the context object.
20
- PictureTag.context.environments.first['jekyll']['environment']
21
- end
22
-
23
- # Site.source is the master jekyll source directory
24
- # Source dir is the jekyll-picture-tag source directory.
25
- def source_dir
26
- File.join PictureTag.site.source, pconfig['source']
27
- end
28
-
29
- # site.dest is the master jekyll destination directory
30
- # source_dest is the jekyll-picture-tag destination directory. (generated
31
- # file location setting.)
32
- def dest_dir
33
- File.join PictureTag.site.config['destination'], pconfig['output']
34
- end
35
-
36
- def nomarkdown?
37
- Utils.markdown_page? && pconfig['nomarkdown']
38
- end
39
-
40
- def continue_on_missing?
41
- env_check pconfig['ignore_missing_images']
42
- rescue ArgumentError
43
- raise ArgumentError,
44
- <<~HEREDOC
45
- continue_on_missing setting invalid. Must be either a boolean
46
- (true/false), an environment name, or an array of environment
47
- names.
48
- HEREDOC
49
- end
50
-
51
- def cdn?
52
- pconfig['cdn_url'] && pconfig['cdn_environments'].include?(jekyll_env)
53
- end
54
-
55
- def disabled?
56
- env_check pconfig['disabled']
57
- rescue ArgumentError
58
- raise ArgumentError,
59
- <<~HEREDOC
60
- "disabled" setting invalid. Must be either a boolean
61
- (true/false), an environment name, or an array of environment
62
- names.
63
- HEREDOC
64
- end
65
-
66
- def fast_build?
67
- env_check pconfig['fast_build']
68
- rescue ArgumentError
69
- raise ArgumentError,
70
- <<~HEREDOC
71
- "fast_build" setting invalid. Must be either a boolean
72
- (true/false), an environment name, or an array of environment
73
- names.
74
- HEREDOC
75
- end
76
-
77
- private
78
-
79
- def content
80
- @content ||= setting_merge(defaults, PictureTag.site.config)
81
- end
82
-
83
- # There are a few config settings which can either be booleans,
84
- # environment names, or arrays of environment names. This method works it
85
- # out and returns a boolean.
86
- def env_check(setting)
87
- if setting.is_a? Array
88
- setting.include? jekyll_env
89
- elsif setting.is_a? String
90
- setting == jekyll_env
91
- elsif [true, false].include? setting
92
- setting
93
- else
94
- raise ArgumentError,
95
- "#{setting} must either be a string, an array, or a boolean."
96
- end
97
- end
98
-
99
- def setting_merge(default, jekyll)
100
- jekyll.merge default do |_key, config_setting, default_setting|
101
- if default_setting.respond_to? :merge
102
- setting_merge(default_setting, config_setting)
103
- else
104
- config_setting
105
- end
106
- end
107
- end
108
-
109
- def defaults
110
- # Jekyll Picture Tag Default settings
111
- YAML.safe_load(
112
- File.read(
113
- File.join(
114
- ROOT_PATH, 'jekyll_picture_tag/defaults/global.yml'
115
- )
116
- )
117
- )
118
- end
119
- end
120
- end
121
- end
@@ -1,122 +0,0 @@
1
- module PictureTag
2
- module Instructions
3
- # Handles the specific tag image set to construct.
4
- class Preset
5
- attr_reader :name
6
-
7
- def initialize(name)
8
- @name = name
9
- @content = build_preset
10
- end
11
-
12
- def [](key)
13
- @content[key]
14
- end
15
-
16
- def formats
17
- @content['formats']
18
- end
19
-
20
- def fallback_format
21
- @content['fallback_format']
22
- end
23
-
24
- def fallback_width
25
- @content['fallback_width']
26
- end
27
-
28
- # Allows a per-preset hard override of the global nomarkdown setting and
29
- # JPT's feeble attempts at auto-detection.
30
- def nomarkdown?
31
- if @content['nomarkdown'].nil?
32
- PictureTag.config.nomarkdown?
33
- else
34
- @content['nomarkdown']
35
- end
36
- end
37
-
38
- # Image widths to generate for a given media query.
39
- def widths(media = nil)
40
- setting_lookup('widths', 'media', media)
41
- end
42
-
43
- # Image quality setting. Surprisingly complicated; can depend on both format and width.
44
- def quality(format = nil, width = nil)
45
- setting = setting_lookup('quality', 'format', format)
46
-
47
- return setting unless setting.is_a? Hash
48
-
49
- parse_quality_hash(setting, width)
50
- end
51
-
52
- def parse_quality_hash(points, width)
53
- # The points can be given in any order.
54
- low, high = *points.keys.map(&:to_i).sort
55
-
56
- case width
57
- when 0..low then points[low]
58
- when low..high then Utils.interpolate(points.keys, points.values, width)
59
- when high..999_999 then points[high]
60
- end
61
- end
62
-
63
- # Gravity setting (for imagemagick cropping)
64
- def gravity(media = nil)
65
- setting_lookup('gravity', 'media', media)
66
- end
67
-
68
- # Crop value
69
- def crop(media = nil)
70
- setting_lookup('crop', 'media', media)
71
- end
72
-
73
- private
74
-
75
- # Return arbitrary setting values, taking their defaults into account.
76
- # Ex: quality can be set for all image formats, or individually per
77
- # format. Per-format settings should override the general setting.
78
- def setting_lookup(setting, prefix, lookup)
79
- media_values = @content[prefix + '_' + setting] || {}
80
- media_values.default = @content[setting]
81
-
82
- media_values[lookup]
83
- end
84
-
85
- def build_preset
86
- # The _data/picture.yml file is optional.
87
- picture_data_file = grab_data_file
88
-
89
- default_preset.merge picture_data_file
90
- end
91
-
92
- def default_preset
93
- YAML.safe_load File.read(
94
- File.join(ROOT_PATH, 'jekyll_picture_tag/defaults/presets.yml')
95
- )
96
- end
97
-
98
- def grab_data_file
99
- search_data('presets') || search_data('markup_presets') || no_preset
100
- end
101
-
102
- def search_data(key)
103
- PictureTag.site
104
- .data
105
- .dig('picture', key, @name)
106
- end
107
-
108
- def no_preset
109
- unless @name == 'default'
110
- Utils.warning(
111
- <<~HEREDOC
112
- Preset "#{@name}" not found in {PictureTag.config['data_dir']}/picture.yml
113
- under markup_presets key. Using default values."
114
- HEREDOC
115
- )
116
- end
117
-
118
- {}
119
- end
120
- end
121
- end
122
- end