jekyll_picture_tag 1.13.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.envrc +4 -0
- data/.github/workflows/code-checks.yml +33 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +29 -76
- data/.ruby-version +1 -1
- data/docs/.envrc +2 -0
- data/docs/devs/contributing/code.md +14 -4
- data/docs/devs/contributing/docs.md +24 -6
- data/docs/devs/contributing/setup.md +21 -1
- data/docs/devs/contributing/testing.md +19 -37
- data/docs/devs/releases.md +45 -4
- data/docs/index.md +43 -18
- data/docs/logo.png +0 -0
- data/docs/logo.svg +880 -0
- data/docs/users/configuration/disable.md +1 -1
- data/docs/users/configuration/ignore_missing.md +1 -1
- data/docs/users/configuration/kramdown_fix.md +1 -1
- data/docs/users/configuration/suppress_warnings.md +1 -1
- data/docs/users/configuration/urls.md +69 -0
- data/docs/users/deployment.md +49 -0
- data/docs/users/getting_started.md +55 -0
- data/docs/users/installation.md +18 -38
- data/docs/users/liquid_tag/argument_reference/crop.md +21 -36
- data/docs/users/liquid_tag/examples.md +13 -25
- data/docs/users/liquid_tag/index.md +1 -1
- data/docs/users/notes/{migration.md → migration_1.md} +1 -1
- data/docs/users/notes/migration_2.md +99 -0
- data/docs/users/presets/cropping.md +21 -22
- data/docs/users/presets/default.md +11 -2
- data/docs/users/presets/examples.md +77 -45
- data/docs/users/presets/fallback_image.md +1 -1
- data/docs/users/presets/html_attributes.md +1 -1
- data/docs/users/presets/image_formats.md +3 -3
- data/docs/users/presets/image_quality.md +71 -56
- data/docs/users/presets/index.md +19 -45
- data/docs/users/presets/link_source.md +1 -1
- data/docs/users/presets/media_queries.md +1 -1
- data/docs/users/presets/nomarkdown_override.md +1 -1
- data/docs/users/presets/pixel_ratio_srcsets.md +1 -1
- data/docs/users/presets/width_height_attributes.md +1 -1
- data/docs/users/presets/width_srcsets.md +61 -23
- data/docs/users/presets/writing_presets.md +65 -0
- data/docs/users/tutorial.md +97 -0
- data/jekyll_picture_tag.gemspec +38 -23
- data/lib/jekyll_picture_tag.rb +8 -5
- data/lib/jekyll_picture_tag/cache.rb +64 -3
- data/lib/jekyll_picture_tag/defaults/global.rb +18 -0
- data/lib/jekyll_picture_tag/defaults/presets.rb +57 -0
- data/lib/jekyll_picture_tag/images.rb +1 -0
- data/lib/jekyll_picture_tag/images/generated_image.rb +25 -60
- data/lib/jekyll_picture_tag/images/image_file.rb +105 -0
- data/lib/jekyll_picture_tag/images/img_uri.rb +3 -10
- data/lib/jekyll_picture_tag/images/source_image.rb +44 -9
- data/lib/jekyll_picture_tag/instructions.rb +70 -6
- data/lib/jekyll_picture_tag/instructions/children/config.rb +128 -0
- data/lib/jekyll_picture_tag/instructions/children/context.rb +24 -0
- data/lib/jekyll_picture_tag/instructions/children/params.rb +90 -0
- data/lib/jekyll_picture_tag/instructions/children/parsers.rb +48 -0
- data/lib/jekyll_picture_tag/instructions/children/preset.rb +182 -0
- data/lib/jekyll_picture_tag/instructions/parents/conditional_instruction.rb +69 -0
- data/lib/jekyll_picture_tag/instructions/parents/env_instruction.rb +29 -0
- data/lib/jekyll_picture_tag/output_formats/basic.rb +5 -17
- data/lib/jekyll_picture_tag/parsers.rb +6 -0
- data/lib/jekyll_picture_tag/{instructions → parsers}/arg_splitter.rb +1 -1
- data/lib/jekyll_picture_tag/parsers/configuration.rb +28 -0
- data/lib/jekyll_picture_tag/{instructions → parsers}/html_attributes.rb +1 -1
- data/lib/jekyll_picture_tag/parsers/image_backend.rb +33 -0
- data/lib/jekyll_picture_tag/parsers/preset.rb +43 -0
- data/lib/jekyll_picture_tag/{instructions → parsers}/tag_parser.rb +15 -12
- data/lib/jekyll_picture_tag/router.rb +35 -93
- data/lib/jekyll_picture_tag/srcsets/basic.rb +4 -10
- data/lib/jekyll_picture_tag/utils.rb +10 -20
- data/lib/jekyll_picture_tag/version.rb +1 -1
- data/readme.md +48 -9
- metadata +161 -80
- data/.travis.yml +0 -8
- data/Dockerfile +0 -9
- data/docs/users/configuration/cdn.md +0 -35
- data/docs/users/configuration/relative_urls.md +0 -15
- data/docs/users/notes/input_checking.md +0 -6
- data/jekyll-picture-tag.gemspec +0 -52
- data/lib/jekyll-picture-tag.rb +0 -25
- data/lib/jekyll_picture_tag/cache/base.rb +0 -59
- data/lib/jekyll_picture_tag/cache/generated.rb +0 -20
- data/lib/jekyll_picture_tag/cache/source.rb +0 -19
- data/lib/jekyll_picture_tag/defaults/global.yml +0 -11
- data/lib/jekyll_picture_tag/defaults/presets.yml +0 -11
- data/lib/jekyll_picture_tag/instructions/configuration.rb +0 -121
- data/lib/jekyll_picture_tag/instructions/preset.rb +0 -122
- data/lib/jekyll_picture_tag/instructions/set.rb +0 -75
data/.travis.yml
DELETED
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,35 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sort: 5
|
3
|
-
---
|
4
|
-
|
5
|
-
# CDN
|
6
|
-
|
7
|
-
Use for images that are hosted at a different domain or subdomain than the
|
8
|
-
Jekyll site root. Overrides `relative_url`.
|
9
|
-
|
10
|
-
## URL
|
11
|
-
|
12
|
-
*Format:* `cdn_url: (url)`
|
13
|
-
|
14
|
-
*Example:* `cdn_url: https://cdn.example.com`
|
15
|
-
|
16
|
-
*Default*: none
|
17
|
-
|
18
|
-
## Environments
|
19
|
-
|
20
|
-
It's likely that if you're using a CDN, you may not want to use it in your local
|
21
|
-
development environment. This allows you to build a site with local images while
|
22
|
-
in development, and still push to a CDN when you build for production by
|
23
|
-
specifying a different
|
24
|
-
[environment](https://jekyllrb.com/docs/configuration/environments/).
|
25
|
-
|
26
|
-
*Format:* `cdn_environments: (array of strings)`
|
27
|
-
|
28
|
-
*Example:* `cdn_environments: ['production', 'staging']`
|
29
|
-
|
30
|
-
*Default*: `['production']`
|
31
|
-
|
32
|
-
**Note that the default jekyll environment is `development`**, meaning that if
|
33
|
-
you only set `cdn_url` and run `jekyll serve` or `jekyll build`, nothing will
|
34
|
-
change. Either run `JEKYLL_ENV=production bundle exec jekyll build`, or add
|
35
|
-
`development` to this setting.
|
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sort: 6
|
3
|
-
---
|
4
|
-
|
5
|
-
# Use Relative Urls
|
6
|
-
|
7
|
-
*Format:* `relative_url: (true|false)`
|
8
|
-
|
9
|
-
*Example:* `relative_url: false`
|
10
|
-
|
11
|
-
*Default*: `true`
|
12
|
-
|
13
|
-
Whether to use relative (`/generated/test(...).jpg`) or absolute
|
14
|
-
(`https://example.com/generated/test(...).jpg`) urls in your src and srcset
|
15
|
-
attributes.
|
@@ -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
|
-
|
data/jekyll-picture-tag.gemspec
DELETED
@@ -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
|
data/lib/jekyll-picture-tag.rb
DELETED
@@ -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,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
|