jekyll_picture_tag 1.12.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) 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/devs/contributing/code.md +14 -4
  9. data/docs/devs/contributing/docs.md +24 -6
  10. data/docs/devs/contributing/setup.md +21 -1
  11. data/docs/devs/contributing/testing.md +19 -37
  12. data/docs/devs/releases.md +45 -4
  13. data/docs/index.md +43 -18
  14. data/docs/logo.png +0 -0
  15. data/docs/logo.svg +880 -0
  16. data/docs/users/configuration/disable.md +1 -1
  17. data/docs/users/configuration/ignore_missing.md +1 -1
  18. data/docs/users/configuration/kramdown_fix.md +1 -1
  19. data/docs/users/configuration/suppress_warnings.md +1 -1
  20. data/docs/users/configuration/urls.md +69 -0
  21. data/docs/users/deployment.md +49 -0
  22. data/docs/users/getting_started.md +55 -0
  23. data/docs/users/installation.md +18 -38
  24. data/docs/users/liquid_tag/argument_reference/crop.md +21 -36
  25. data/docs/users/liquid_tag/examples.md +12 -12
  26. data/docs/users/liquid_tag/index.md +1 -1
  27. data/docs/users/notes/{migration.md → migration_1.md} +1 -1
  28. data/docs/users/notes/migration_2.md +99 -0
  29. data/docs/users/presets/cropping.md +24 -25
  30. data/docs/users/presets/default.md +11 -2
  31. data/docs/users/presets/examples.md +77 -45
  32. data/docs/users/presets/fallback_image.md +1 -1
  33. data/docs/users/presets/html_attributes.md +1 -1
  34. data/docs/users/presets/image_formats.md +3 -3
  35. data/docs/users/presets/image_quality.md +96 -19
  36. data/docs/users/presets/index.md +19 -45
  37. data/docs/users/presets/link_source.md +1 -1
  38. data/docs/users/presets/media_queries.md +1 -1
  39. data/docs/users/presets/nomarkdown_override.md +1 -1
  40. data/docs/users/presets/pixel_ratio_srcsets.md +1 -1
  41. data/docs/users/presets/quality_width_graph.png +0 -0
  42. data/docs/users/presets/width_height_attributes.md +1 -1
  43. data/docs/users/presets/width_srcsets.md +61 -23
  44. data/docs/users/presets/writing_presets.md +65 -0
  45. data/docs/users/tutorial.md +97 -0
  46. data/jekyll_picture_tag.gemspec +38 -23
  47. data/lib/jekyll_picture_tag.rb +11 -10
  48. data/lib/jekyll_picture_tag/cache.rb +64 -3
  49. data/lib/jekyll_picture_tag/defaults/global.rb +18 -0
  50. data/lib/jekyll_picture_tag/defaults/presets.rb +57 -0
  51. data/lib/jekyll_picture_tag/images.rb +4 -0
  52. data/lib/jekyll_picture_tag/images/generated_image.rb +92 -0
  53. data/lib/jekyll_picture_tag/images/image_file.rb +104 -0
  54. data/lib/jekyll_picture_tag/{img_uri.rb → images/img_uri.rb} +3 -10
  55. data/lib/jekyll_picture_tag/{source_image.rb → images/source_image.rb} +44 -9
  56. data/lib/jekyll_picture_tag/instructions.rb +70 -6
  57. data/lib/jekyll_picture_tag/instructions/children/config.rb +128 -0
  58. data/lib/jekyll_picture_tag/instructions/children/context.rb +24 -0
  59. data/lib/jekyll_picture_tag/instructions/children/params.rb +90 -0
  60. data/lib/jekyll_picture_tag/instructions/children/parsers.rb +48 -0
  61. data/lib/jekyll_picture_tag/instructions/children/preset.rb +182 -0
  62. data/lib/jekyll_picture_tag/instructions/parents/conditional_instruction.rb +69 -0
  63. data/lib/jekyll_picture_tag/instructions/parents/env_instruction.rb +29 -0
  64. data/lib/jekyll_picture_tag/output_formats/basic.rb +5 -17
  65. data/lib/jekyll_picture_tag/parsers.rb +6 -0
  66. data/lib/jekyll_picture_tag/{instructions → parsers}/arg_splitter.rb +1 -1
  67. data/lib/jekyll_picture_tag/parsers/configuration.rb +28 -0
  68. data/lib/jekyll_picture_tag/{instructions → parsers}/html_attributes.rb +1 -1
  69. data/lib/jekyll_picture_tag/parsers/image_backend.rb +33 -0
  70. data/lib/jekyll_picture_tag/parsers/preset.rb +43 -0
  71. data/lib/jekyll_picture_tag/{instructions → parsers}/tag_parser.rb +15 -12
  72. data/lib/jekyll_picture_tag/router.rb +35 -93
  73. data/lib/jekyll_picture_tag/srcsets/basic.rb +4 -10
  74. data/lib/jekyll_picture_tag/utils.rb +24 -20
  75. data/lib/jekyll_picture_tag/version.rb +1 -1
  76. data/readme.md +46 -15
  77. metadata +168 -85
  78. data/.travis.yml +0 -8
  79. data/Dockerfile +0 -9
  80. data/docs/users/configuration/cdn.md +0 -35
  81. data/docs/users/configuration/relative_urls.md +0 -15
  82. data/docs/users/notes/input_checking.md +0 -6
  83. data/jekyll-picture-tag.gemspec +0 -52
  84. data/lib/jekyll-picture-tag.rb +0 -25
  85. data/lib/jekyll_picture_tag/cache/base.rb +0 -59
  86. data/lib/jekyll_picture_tag/cache/generated.rb +0 -20
  87. data/lib/jekyll_picture_tag/cache/source.rb +0 -19
  88. data/lib/jekyll_picture_tag/defaults/global.yml +0 -11
  89. data/lib/jekyll_picture_tag/defaults/presets.yml +0 -11
  90. data/lib/jekyll_picture_tag/generated_image.rb +0 -140
  91. data/lib/jekyll_picture_tag/instructions/configuration.rb +0 -121
  92. data/lib/jekyll_picture_tag/instructions/preset.rb +0 -107
  93. data/lib/jekyll_picture_tag/instructions/set.rb +0 -75
@@ -1,107 +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, possibly dependent on format.
44
- def quality(format = nil)
45
- setting_lookup('quality', 'format', format)
46
- end
47
-
48
- # Gravity setting (for imagemagick cropping)
49
- def gravity(media = nil)
50
- setting_lookup('gravity', 'media', media)
51
- end
52
-
53
- # Crop value
54
- def crop(media = nil)
55
- setting_lookup('crop', 'media', media)
56
- end
57
-
58
- private
59
-
60
- # Return arbitrary setting values, taking their defaults into account.
61
- # Ex: quality can be set for all image formats, or individually per
62
- # format. Per-format settings should override the general setting.
63
- def setting_lookup(setting, prefix, lookup)
64
- media_values = @content[prefix + '_' + setting] || {}
65
- media_values.default = @content[setting]
66
-
67
- media_values[lookup]
68
- end
69
-
70
- def build_preset
71
- # The _data/picture.yml file is optional.
72
- picture_data_file = grab_data_file
73
-
74
- default_preset.merge picture_data_file
75
- end
76
-
77
- def default_preset
78
- YAML.safe_load File.read(
79
- File.join(ROOT_PATH, 'jekyll_picture_tag/defaults/presets.yml')
80
- )
81
- end
82
-
83
- def grab_data_file
84
- search_data('presets') || search_data('markup_presets') || no_preset
85
- end
86
-
87
- def search_data(key)
88
- PictureTag.site
89
- .data
90
- .dig('picture', key, @name)
91
- end
92
-
93
- def no_preset
94
- unless @name == 'default'
95
- Utils.warning(
96
- <<~HEREDOC
97
- Preset "#{@name}" not found in {PictureTag.config['data_dir']}/picture.yml
98
- under markup_presets key. Using default values."
99
- HEREDOC
100
- )
101
- end
102
-
103
- {}
104
- end
105
- end
106
- end
107
- end
@@ -1,75 +0,0 @@
1
- module PictureTag
2
- module Instructions
3
- # Supervisor class, which manages all input handling and high level decision
4
- # making which depends on it.
5
- class Set
6
- def initialize(raw_tag_params)
7
- @raw_tag_params = raw_tag_params
8
- end
9
-
10
- def config
11
- @config ||= Configuration.new
12
- end
13
-
14
- def params
15
- @params ||= TagParser.new @raw_tag_params
16
- end
17
-
18
- def preset
19
- @preset ||= Preset.new params.preset_name
20
- end
21
-
22
- def html_attributes
23
- # Depends on both the preset and tag params.
24
- @html_attributes ||= HTMLAttributeSet.new params.leftovers
25
- end
26
-
27
- # These are our Media Query presets. It's really just a hash, and there
28
- # are no default values, so extracting this to its own class is overkill.
29
- def media_presets
30
- search_data('media_queries') || search_data('media_presets') || {}
31
- end
32
-
33
- def source_images
34
- @source_images ||= build_source_images
35
- end
36
-
37
- def crop(media = nil)
38
- params.geometries[media] || preset.crop(media)
39
- end
40
-
41
- def gravity(media = nil)
42
- params.gravities[media] || preset.gravity(media)
43
- end
44
-
45
- # Returns a class constant for the selected output format, which is used
46
- # to dynamically instantiate it.
47
- def output_class
48
- Object.const_get(
49
- 'PictureTag::OutputFormats::' + Utils.titleize(preset['markup'])
50
- )
51
- end
52
-
53
- private
54
-
55
- def search_data(key)
56
- PictureTag.site.data.dig('picture', key)
57
- end
58
-
59
- def build_source_images
60
- source_names = params.source_names
61
- media_presets = params.media_presets
62
-
63
- sources = [SourceImage.new(source_names.shift)]
64
-
65
- while params.source_names.any?
66
- sources << SourceImage.new(
67
- source_names.shift, media_presets.shift
68
- )
69
- end
70
-
71
- sources
72
- end
73
- end
74
- end
75
- end