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
@@ -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,103 +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
- PictureTag.site
85
- .data
86
- .dig('picture', 'markup_presets', @name) || no_preset
87
- end
88
-
89
- def no_preset
90
- unless @name == 'default'
91
- Utils.warning(
92
- <<~HEREDOC
93
- Preset "#{@name}" not found in {PictureTag.config['data_dir']}/picture.yml
94
- under markup_presets key. Using default values."
95
- HEREDOC
96
- )
97
- end
98
-
99
- {}
100
- end
101
- end
102
- end
103
- end
@@ -1,71 +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
- PictureTag.site.data.dig('picture', '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 build_source_images
56
- source_names = params.source_names
57
- media_presets = params.media_presets
58
-
59
- sources = [SourceImage.new(source_names.shift)]
60
-
61
- while params.source_names.any?
62
- sources << SourceImage.new(
63
- source_names.shift, media_presets.shift
64
- )
65
- end
66
-
67
- sources
68
- end
69
- end
70
- end
71
- end