jekyll_picture_tag 1.10.2 → 2.0.0pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) 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 +32 -0
  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 +113 -0
  18. data/docs/index.md +62 -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 +31 -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 +137 -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/tutorial.md +97 -0
  69. data/jekyll_picture_tag.gemspec +38 -24
  70. data/lib/jekyll_picture_tag.rb +11 -9
  71. data/lib/jekyll_picture_tag/cache.rb +64 -0
  72. data/lib/jekyll_picture_tag/defaults/global.rb +18 -0
  73. data/lib/jekyll_picture_tag/defaults/presets.rb +57 -0
  74. data/lib/jekyll_picture_tag/images.rb +4 -0
  75. data/lib/jekyll_picture_tag/images/generated_image.rb +92 -0
  76. data/lib/jekyll_picture_tag/images/image_file.rb +90 -0
  77. data/lib/jekyll_picture_tag/{img_uri.rb → images/img_uri.rb} +4 -10
  78. data/lib/jekyll_picture_tag/images/source_image.rb +138 -0
  79. data/lib/jekyll_picture_tag/instructions.rb +70 -6
  80. data/lib/jekyll_picture_tag/instructions/children/config.rb +128 -0
  81. data/lib/jekyll_picture_tag/instructions/children/context.rb +24 -0
  82. data/lib/jekyll_picture_tag/instructions/children/params.rb +90 -0
  83. data/lib/jekyll_picture_tag/instructions/children/parsers.rb +41 -0
  84. data/lib/jekyll_picture_tag/instructions/children/preset.rb +182 -0
  85. data/lib/jekyll_picture_tag/instructions/parents/conditional_instruction.rb +69 -0
  86. data/lib/jekyll_picture_tag/instructions/parents/env_instruction.rb +29 -0
  87. data/lib/jekyll_picture_tag/output_formats/basic.rb +11 -21
  88. data/lib/jekyll_picture_tag/output_formats/img.rb +11 -0
  89. data/lib/jekyll_picture_tag/output_formats/picture.rb +22 -0
  90. data/lib/jekyll_picture_tag/parsers.rb +5 -0
  91. data/lib/jekyll_picture_tag/{instructions → parsers}/arg_splitter.rb +4 -3
  92. data/lib/jekyll_picture_tag/parsers/configuration.rb +28 -0
  93. data/lib/jekyll_picture_tag/{instructions → parsers}/html_attributes.rb +1 -1
  94. data/lib/jekyll_picture_tag/parsers/preset.rb +43 -0
  95. data/lib/jekyll_picture_tag/{instructions → parsers}/tag_parser.rb +15 -12
  96. data/lib/jekyll_picture_tag/router.rb +35 -92
  97. data/lib/jekyll_picture_tag/srcsets/basic.rb +11 -8
  98. data/lib/jekyll_picture_tag/utils.rb +24 -20
  99. data/lib/jekyll_picture_tag/version.rb +1 -1
  100. data/readme.md +15 -12
  101. metadata +206 -95
  102. data/.travis.yml +0 -8
  103. data/Dockerfile +0 -9
  104. data/docs/_layouts/directory.html +0 -32
  105. data/docs/assets/style.css +0 -31
  106. data/docs/contributing.md +0 -109
  107. data/docs/example_presets.md +0 -116
  108. data/docs/global_configuration.md +0 -173
  109. data/docs/installation.md +0 -45
  110. data/docs/notes.md +0 -91
  111. data/docs/output.md +0 -63
  112. data/docs/presets.md +0 -361
  113. data/docs/releases.md +0 -65
  114. data/docs/usage.md +0 -143
  115. data/jekyll-picture-tag.gemspec +0 -52
  116. data/lib/jekyll-picture-tag.rb +0 -25
  117. data/lib/jekyll_picture_tag/defaults/global.yml +0 -11
  118. data/lib/jekyll_picture_tag/defaults/presets.yml +0 -10
  119. data/lib/jekyll_picture_tag/generated_image.rb +0 -161
  120. data/lib/jekyll_picture_tag/instructions/configuration.rb +0 -121
  121. data/lib/jekyll_picture_tag/instructions/preset.rb +0 -102
  122. data/lib/jekyll_picture_tag/instructions/set.rb +0 -71
  123. data/lib/jekyll_picture_tag/source_image.rb +0 -87
@@ -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,102 +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
- def initialize(name)
7
- @name = name
8
- @content = build_preset
9
- end
10
-
11
- def [](key)
12
- @content[key]
13
- end
14
-
15
- def formats
16
- @content['formats']
17
- end
18
-
19
- def fallback_format
20
- @content['fallback_format']
21
- end
22
-
23
- def fallback_width
24
- @content['fallback_width']
25
- end
26
-
27
- # Allows a per-preset hard override of the global nomarkdown setting and
28
- # JPT's feeble attempts at auto-detection.
29
- def nomarkdown?
30
- if @content['nomarkdown'].nil?
31
- PictureTag.config.nomarkdown?
32
- else
33
- @content['nomarkdown']
34
- end
35
- end
36
-
37
- # Image widths to generate for a given media query.
38
- def widths(media = nil)
39
- setting_lookup('widths', 'media', media)
40
- end
41
-
42
- # Image quality setting, possibly dependent on format.
43
- def quality(format = nil)
44
- setting_lookup('quality', 'format', format)
45
- end
46
-
47
- # Gravity setting (for imagemagick cropping)
48
- def gravity(media = nil)
49
- setting_lookup('gravity', 'media', media)
50
- end
51
-
52
- # Crop value
53
- def crop(media = nil)
54
- setting_lookup('crop', 'media', media)
55
- end
56
-
57
- private
58
-
59
- # Return arbitrary setting values, taking their defaults into account.
60
- # Ex: quality can be set for all image formats, or individually per
61
- # format. Per-format settings should override the general setting.
62
- def setting_lookup(setting, prefix, lookup)
63
- media_values = @content[prefix + '_' + setting] || {}
64
- media_values.default = @content[setting]
65
-
66
- media_values[lookup]
67
- end
68
-
69
- def build_preset
70
- # The _data/picture.yml file is optional.
71
- picture_data_file = grab_data_file
72
-
73
- default_preset.merge picture_data_file
74
- end
75
-
76
- def default_preset
77
- YAML.safe_load File.read(
78
- File.join(ROOT_PATH, 'jekyll_picture_tag/defaults/presets.yml')
79
- )
80
- end
81
-
82
- def grab_data_file
83
- PictureTag.site
84
- .data
85
- .dig('picture', 'markup_presets', @name) || no_preset
86
- end
87
-
88
- def no_preset
89
- unless @name == 'default'
90
- Utils.warning(
91
- <<~HEREDOC
92
- Preset "#{@name}" not found in {PictureTag.config['data_dir']}/picture.yml
93
- under markup_presets key. Using default values."
94
- HEREDOC
95
- )
96
- end
97
-
98
- {}
99
- end
100
- end
101
- end
102
- 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
@@ -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