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.
- checksums.yaml +4 -4
- data/.envrc +4 -0
- data/.github/workflows/code-checks.yml +33 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +31 -3
- data/.ruby-version +1 -1
- data/docs/.envrc +2 -0
- data/docs/Gemfile +4 -2
- data/docs/Gemfile.lock +14 -12
- data/docs/_config.yml +6 -10
- data/docs/devs/contributing/code.md +54 -0
- data/docs/devs/contributing/docs.md +31 -0
- data/docs/devs/contributing/index.md +15 -0
- data/docs/devs/contributing/setup.md +33 -0
- data/docs/devs/contributing/testing.md +23 -0
- data/docs/devs/index.md +7 -0
- data/docs/devs/releases.md +118 -0
- data/docs/index.md +67 -31
- data/docs/logo.png +0 -0
- data/docs/logo.svg +880 -0
- data/docs/users/configuration/directories.md +34 -0
- data/docs/users/configuration/disable.md +24 -0
- data/docs/users/configuration/fast_build.md +28 -0
- data/docs/users/configuration/ignore_missing.md +23 -0
- data/docs/users/configuration/index.md +29 -0
- data/docs/users/configuration/kramdown_fix.md +20 -0
- data/docs/users/configuration/suppress_warnings.md +16 -0
- data/docs/users/configuration/urls.md +69 -0
- data/docs/users/getting_started.md +55 -0
- data/docs/users/index.md +7 -0
- data/docs/users/installation.md +32 -0
- data/docs/users/liquid_tag/argument_reference/alternate_images.md +18 -0
- data/docs/users/liquid_tag/argument_reference/attributes.md +42 -0
- data/docs/users/liquid_tag/argument_reference/base_image.md +12 -0
- data/docs/users/liquid_tag/argument_reference/crop.md +33 -0
- data/docs/users/liquid_tag/argument_reference/link.md +16 -0
- data/docs/users/liquid_tag/argument_reference/preset.md +17 -0
- data/docs/users/liquid_tag/argument_reference/readme.md +9 -0
- data/docs/users/liquid_tag/examples.md +81 -0
- data/docs/users/liquid_tag/index.md +31 -0
- data/docs/users/notes/git_lfs.md +7 -0
- data/docs/users/notes/github_pages.md +5 -0
- data/docs/users/notes/html_attributes.md +5 -0
- data/docs/users/notes/index.md +6 -0
- data/docs/users/notes/kramdown_bug.md +41 -0
- data/docs/users/notes/managing_images.md +21 -0
- data/docs/{migration.md → users/notes/migration_1.md} +1 -1
- data/docs/users/notes/migration_2.md +99 -0
- data/docs/users/presets/cropping.md +60 -0
- data/docs/users/presets/default.md +32 -0
- data/docs/users/presets/examples.md +111 -0
- data/docs/users/presets/fallback_image.md +28 -0
- data/docs/users/presets/html_attributes.md +26 -0
- data/docs/users/presets/image_formats.md +21 -0
- data/docs/users/presets/image_quality.md +120 -0
- data/docs/users/presets/index.md +75 -0
- data/docs/users/presets/link_source.md +16 -0
- data/docs/users/presets/markup_formats/fragments.md +48 -0
- data/docs/users/presets/markup_formats/javascript_friendly.md +57 -0
- data/docs/users/presets/markup_formats/readme.md +43 -0
- data/docs/users/presets/markup_formats/standard_html.md +25 -0
- data/docs/users/presets/media_queries.md +36 -0
- data/docs/users/presets/nomarkdown_override.md +17 -0
- data/docs/users/presets/pixel_ratio_srcsets.md +32 -0
- data/docs/users/presets/quality_width_graph.png +0 -0
- data/docs/users/presets/width_height_attributes.md +34 -0
- data/docs/users/presets/width_srcsets.md +123 -0
- 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 +11 -10
- 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 +4 -0
- data/lib/jekyll_picture_tag/images/generated_image.rb +92 -0
- data/lib/jekyll_picture_tag/images/image_file.rb +90 -0
- data/lib/jekyll_picture_tag/{img_uri.rb → images/img_uri.rb} +3 -10
- data/lib/jekyll_picture_tag/{source_image.rb → 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 +41 -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 +5 -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/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 +24 -20
- data/lib/jekyll_picture_tag/version.rb +1 -1
- data/readme.md +15 -13
- metadata +215 -93
- data/.travis.yml +0 -8
- data/Dockerfile +0 -9
- data/docs/_layouts/directory.html +0 -32
- data/docs/assets/style.css +0 -31
- data/docs/contributing.md +0 -109
- data/docs/example_presets.md +0 -116
- data/docs/global_configuration.md +0 -173
- data/docs/installation.md +0 -45
- data/docs/notes.md +0 -91
- data/docs/output.md +0 -63
- data/docs/presets.md +0 -391
- data/docs/releases.md +0 -70
- data/docs/usage.md +0 -157
- 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/generated_image.rb +0 -140
- data/lib/jekyll_picture_tag/instructions/configuration.rb +0 -121
- data/lib/jekyll_picture_tag/instructions/preset.rb +0 -103
- 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
|