jekyll_picture_tag 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +2 -2
  5. data/Rakefile +28 -0
  6. data/contributing.md +67 -0
  7. data/docs/examples/_config.yml +10 -0
  8. data/{examples → docs/examples}/_data/picture.yml +39 -19
  9. data/docs/examples/post.md +46 -0
  10. data/docs/global_configuration.md +115 -0
  11. data/docs/installation.md +30 -0
  12. data/docs/migration.md +178 -0
  13. data/docs/notes.md +85 -0
  14. data/docs/presets.md +407 -0
  15. data/docs/readme.md +23 -0
  16. data/docs/usage.md +131 -0
  17. data/jekyll-picture-tag.gemspec +3 -12
  18. data/jekyll_picture_tag.gemspec +8 -3
  19. data/lib/jekyll-picture-tag.rb +5 -3
  20. data/lib/jekyll_picture_tag.rb +45 -42
  21. data/lib/jekyll_picture_tag/defaults/global.yml +0 -3
  22. data/lib/jekyll_picture_tag/defaults/presets.yml +1 -0
  23. data/lib/jekyll_picture_tag/generated_image.rb +60 -39
  24. data/lib/jekyll_picture_tag/img_uri.rb +55 -0
  25. data/lib/jekyll_picture_tag/instructions.rb +1 -102
  26. data/lib/jekyll_picture_tag/instructions/configuration.rb +30 -74
  27. data/lib/jekyll_picture_tag/instructions/html_attributes.rb +18 -27
  28. data/lib/jekyll_picture_tag/instructions/preset.rb +14 -3
  29. data/lib/jekyll_picture_tag/instructions/set.rb +61 -0
  30. data/lib/jekyll_picture_tag/instructions/tag_parser.rb +80 -23
  31. data/lib/jekyll_picture_tag/output_formats.rb +1 -1
  32. data/lib/jekyll_picture_tag/output_formats/{basics.rb → basic.rb} +24 -19
  33. data/lib/jekyll_picture_tag/output_formats/data_attributes.rb +2 -2
  34. data/lib/jekyll_picture_tag/output_formats/direct_url.rb +1 -3
  35. data/lib/jekyll_picture_tag/output_formats/img.rb +4 -4
  36. data/lib/jekyll_picture_tag/output_formats/naked_srcset.rb +5 -4
  37. data/lib/jekyll_picture_tag/output_formats/picture.rb +6 -16
  38. data/lib/jekyll_picture_tag/output_formats/readme.md +8 -15
  39. data/lib/jekyll_picture_tag/router.rb +98 -0
  40. data/lib/jekyll_picture_tag/source_image.rb +15 -23
  41. data/lib/jekyll_picture_tag/srcsets.rb +1 -1
  42. data/lib/jekyll_picture_tag/srcsets/{basics.rb → basic.rb} +22 -13
  43. data/lib/jekyll_picture_tag/srcsets/pixel_ratio.rb +6 -11
  44. data/lib/jekyll_picture_tag/srcsets/width.rb +3 -11
  45. data/lib/jekyll_picture_tag/utils.rb +32 -49
  46. data/lib/jekyll_picture_tag/version.rb +1 -1
  47. data/readme.md +70 -70
  48. metadata +97 -16
  49. data/bin/console +0 -14
  50. data/bin/setup +0 -7
  51. data/examples/_config.yml +0 -4
  52. data/examples/post.md +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 938a170ac5a3ee774c6d8b95ac2a34e20a1edad04937acf49c7e7bdd081f3b81
4
- data.tar.gz: 1648ce3bdf88de7acf55c17d675bfab1ce641cf00a1138b3cf32abafc4824e96
3
+ metadata.gz: 02cc9448af17bd0cb2811b4f60beb90bea2b95803b694dae29b5606ea39d9a2a
4
+ data.tar.gz: 58025b92dfeed1607d235cc1ce72195a6f48d722bdf092f8366ab46f7aca74dc
5
5
  SHA512:
6
- metadata.gz: ce995d57c31dd2beb97c13288a05cca94eaa2ce242e30bcfaf643154dbeec099ce5fa14566b54bd8fc14b21cf8f9da86028fa583f71ad965f368b9db46930ecf
7
- data.tar.gz: 105c64ae46f7a5a92c7a198c3ae48e6d49d16493e619107afd0d7c473f577bde43c3baebdfda0692e927fe915f1743dd86ffe8aad7b09c0b48b6b50136625844
6
+ metadata.gz: 57ae73af226946c529009c7b6af37acaf79596c44e25526ab080b4076c9f1308a09ae694ec4b17eab0c36fa2d92b9f1ab7885188590c63152984cc06cb9bcb60
7
+ data.tar.gz: be56299cc614da19121ed1e41a1f815b448092804f1813f4e5bb93997628dba0056e02c84ce566dda77ce0fc0feb2aa5a39f467bce70119fbf9f2215f9a6a026
@@ -0,0 +1,2 @@
1
+ Style/FrozenStringLiteralComment:
2
+ Enabled: false
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ before_install:
5
+ - sudo apt-get install -y webp
6
+ - gem update --system
7
+ - gem install bundler
8
+
9
+ script:
10
+ - bundle exec rake test
11
+ - bundle exec rake rubocop
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in jekyll-picture-tag.gemspec
4
- gemspec
3
+ # Specify your gem's dependencies in jekyll_picture_tag.gemspec
4
+ gemspec name: 'jekyll_picture_tag'
data/Rakefile CHANGED
@@ -3,3 +3,31 @@
3
3
 
4
4
  require 'bundler/gem_helper'
5
5
  Bundler::GemHelper.install_tasks name: 'jekyll_picture_tag'
6
+ require 'rake/testtask'
7
+ require 'rubocop/rake_task'
8
+
9
+ # Run all tests
10
+ Rake::TestTask.new(:test) do |t|
11
+ t.libs << 'test'
12
+ t.libs << 'lib'
13
+ t.test_files = FileList['test/**/test_*.rb']
14
+ end
15
+
16
+ # Run only unit tests
17
+ Rake::TestTask.new(:unit) do |t|
18
+ t.libs << 'test'
19
+ t.libs << 'lib'
20
+ t.test_files = FileList['test/unit/**/test_*.rb']
21
+ end
22
+
23
+ # Run only integration tests
24
+ Rake::TestTask.new(:integration) do |t|
25
+ t.libs << 'test'
26
+ t.libs << 'lib'
27
+ t.test_files = FileList['test/integration/**/test_*.rb']
28
+ end
29
+
30
+ RuboCop::RakeTask.new
31
+
32
+ # Runs all tests and rubocop
33
+ task default: %i[test rubocop]
@@ -0,0 +1,67 @@
1
+ # Contributing
2
+
3
+ Bug reports, feature requests, and feedback are very welcome, either through github issues or via
4
+ email: robert@buchberger.cc
5
+
6
+ Pull requests are encouraged! I'm happy to answer questions and provide assistance along the way.
7
+ Don't let any of the recommendations/requests in this guide stop you from submitting one.
8
+
9
+ ## Setup
10
+
11
+ Getting up and running is pretty standard-- `git clone`, `cd` into the directory and `bundle
12
+ install`.
13
+
14
+ ## Testing
15
+
16
+ `rake test` runs the test suite (both unit tests and integration tests). Ignore the mini_magick
17
+ `method redefined` warnings (unless you know how to fix them?)
18
+
19
+ `rake unit` runs just the unit tests, while `rake integration` runs the integration tests. The unit
20
+ test coverage isn't stellar, but both unit and integration tests together hit 100%.
21
+
22
+ Speaking of coverage, simplecov is set up -- you'll get a measurement of coverage in the test output
23
+ and a nice report in the `coverage` directory. I'd like to move to mutation based coverage testing,
24
+ but that's a project for another day.
25
+
26
+ The tests do output a few images to the `/tmp/` directory, which I'm pretty sure means it won't work
27
+ on Windows. This is fixable if there is a need, so if that gets in your way just ask.
28
+
29
+ `rake rubocop` checks code formatting, `rake rubocop:auto_correct` will try to fix any rubocop
30
+ issues, if possible.
31
+
32
+ `rake` will run all tests and rubocop.
33
+
34
+ ## Guidelines
35
+
36
+ * Generally, go for straightforward and readable rather than terse and clever.
37
+ I'm not actually a very good programmer; I need simple code that's easy to understand.
38
+
39
+ * Internal refactoring is welcome, especially in the name of the previous point.
40
+
41
+ * I'm very reluctant to introduce breaking changes to configuration settings.
42
+ This rule isn't hard and fast, but I'm not going to do it without a good reason.
43
+
44
+ * The addition of new test cases whenever relevant is certainly appreciated.
45
+ This project went for awhile without any proper tests, but now that we're at 100% coverage it
46
+ would be nice to keep it that way.
47
+
48
+ * I've been using 80 characters for code and 100 characters for documentation.
49
+
50
+ * The code coverage is currently at 100%. I'm not going to make maintaining this a hard and fast
51
+ rule, but I'd really like to see it stay this way.
52
+
53
+ ## Hard rules
54
+
55
+ * Liquid tag syntax can only be extended; no breaking changes. I'm not willing to force
56
+ users to dig through their entire site and change every picture tag in order to update to the
57
+ latest version.
58
+
59
+ * Maintain "no configuration required" - a new user must be able to add jpt to their gemfile, bundle
60
+ install, and start writing picture tags in their site without touching a yml file.
61
+
62
+ * All tests pass, and all rubocop warnings are addressed.
63
+
64
+ ### Thanks!
65
+
66
+ As I said, don't let any of the rules & guidelines scare you away. They're the rules for merging
67
+ into master, not submitting a pull request. I'm thrilled to receive any help at all.
@@ -0,0 +1,10 @@
1
+ # Sample Jekyll Picture Tag settings
2
+ # Note that all of these settings have sensible defaults. Don't just copy-paste
3
+ # this into your _config.yml!
4
+ picture:
5
+ source: assets/images/_fullsize
6
+ output: generated
7
+ suppress_warnings: false
8
+ ignore_missing_images: [development, test]
9
+ cdn_url: cdn.example.com
10
+ cdn_environments: production
@@ -1,7 +1,9 @@
1
- # Example picture presets:
2
- # TODO: change to EMs, because safari sucks.
1
+ # These are example settings. I mostly made them up off the top of my head. You
2
+ # probably don't want to just copy-paste these settings. It's worth your time to
3
+ # learn responsive images, so you'll understand what these settings mean.
4
+ # The full documentation for these settings can be found in docs/presets.md
3
5
 
4
- # Media presets are used in several places:
6
+ # Media presets are just named css media queries, used in several places:
5
7
  # - To specify alternate source images (for art direction)
6
8
  # - To build the 'sizes' attribute
7
9
  # - When given alternate source images, specify which sizes to generate.
@@ -15,13 +17,14 @@ media_presets:
15
17
  # Markup presets allow you to group settings together, and select one of them by name in your jekyll
16
18
  # tag. All settings are optional.
17
19
  markup_presets:
20
+ # If you don't specify a preset in the liquid tag (just say
21
+ # {% picture image.jpg %}), you'll get the 'default' preset:
18
22
  default:
19
-
20
- # Optionally specify a markup type. Your current options are 'picture', 'img', or 'auto'
21
- # (default).
23
+ # What form the output markup should take.
22
24
  markup: auto
23
25
 
24
- # Must be an array, in order of decreasing preference. Defaults to just 'original'.
26
+ # Must be an array, and order matters. Defaults to just 'original', which
27
+ # does what you'd expect.
25
28
  formats: [webp, original]
26
29
 
27
30
  # Must be an array: which image sizes (width in pixels) to generate (unless directed otherwise
@@ -30,38 +33,48 @@ markup_presets:
30
33
 
31
34
  # Alternate source images (for art direction) are associated with media query presets. Here, you
32
35
  # can optionally specify a different set of sizes to generate for those alternate source images.
33
- # This is how you avoid generating a 1800 pixel wide image that's only shown on narrow screens.
36
+ # This is how you avoid generating a 1600 pixel wide image that's only shown on narrow screens.
34
37
  # Must be arrays.
35
38
  media_widths:
36
39
  mobile: [200, 400, 600]
37
40
  tablet: [400, 600, 800]
38
41
 
39
- # Specifies an optional, unconditional size attribute. Can be given alone, or if specified in
40
- # combination with 'sizes' below, will be given last (when no media queries apply).
41
- size: 800px
42
-
43
42
  # For building the 'sizes' attribute on img and source tags. specifies how wide the image will
44
43
  # be when a given media query is true. Note that every source in a given <picture> tag will have
45
44
  # the same associated sizes attribute.
46
45
  sizes:
47
46
  mobile: 100vw
48
- desktop: 60vw
47
+ tablet: 80vw
48
+
49
+ # Specifies an optional, unconditional size attribute. Can be given alone, or if specified in
50
+ # combination with 'sizes' below, will be given last (when no media queries apply).
51
+ size: 800px
49
52
 
50
53
  # Specify the properties of the fallback image. If not specified, will return a 900 pixel
51
54
  # wide image in the original format.
52
55
  fallback_width: 800
53
56
  fallback_format: original
54
57
 
55
- # Attributes can be added to each HTML element, by type:
58
+ # Add HTML attributes. 'parent' will go to the <picture> tag if it's there,
59
+ # otherwise the 'img' tag.
56
60
  attributes:
61
+ parent: 'data-downloadable="true"'
57
62
  picture: 'class="awesome" data-volume="11"'
58
63
  img: 'class="some-other-class"'
64
+ a: 'class="image-link"'
59
65
 
60
- # This is an example of how you would create a 'multiplier' based srcset; useful when an image
61
- # will always be the same size on all screens, but you'd like to supply higher resolution images
62
- # to devices with higher pixel ratios.
66
+ # This will wrap images in a link to the original source image. Obviously
67
+ # your source images will need to be part of the deployed site for this to
68
+ # work. If you have issues such as mangled HTML or extra {::nomarkdown}
69
+ # tags floating around, see docs/notes.md
70
+ link-source: true
71
+
72
+ # This is an example of how you would create a 'multiplier' based srcset;
73
+ # useful when an image will always be the same size on all screens (icons,
74
+ # graphics, thumbnails, etc), but you'd like to supply higher resolution
75
+ # images to devices with higher pixel ratios.
63
76
  icon:
64
- base_width: 20
77
+ base_width: 20 # How wide the 1x image should be
65
78
  pixel_ratios: [1, 1.5, 2]
66
79
  fallback_width: 20
67
80
  attributes:
@@ -71,10 +84,12 @@ markup_presets:
71
84
  # lazyload:
72
85
  # https://github.com/verlok/lazyload
73
86
  lazy:
87
+ # data_auto gives you data-src, data-srcset, and data-sizes instead of src,
88
+ # srcset, and sizes:
74
89
  markup: data_auto
75
90
  formats: [webp, original]
76
91
  widths: [200, 400, 600, 800]
77
- noscript: true # Default: false
92
+ noscript: true # add a fallback image inside a <noscript> tag.
78
93
  attributes:
79
94
  img: class="lazy"
80
95
 
@@ -83,3 +98,8 @@ markup_presets:
83
98
  markup: direct_url
84
99
  fallback_format: webp # Default original
85
100
  fallback_width: 600 # Default 800
101
+
102
+ # Here's a naked srcset. Doesn't even give you the surrounding quotes.
103
+ srcset:
104
+ markup: naked_srcset
105
+ formats: [webp] # must be an array, even if it only has one item
@@ -0,0 +1,46 @@
1
+ ```
2
+ ---
3
+ layout: post
4
+ title: Tag examples
5
+ image: img.jpg
6
+ ---
7
+ ```
8
+
9
+ - Standard image, default preset, with alt text:
10
+
11
+ `{% picture portrait.jpg --alt An unsual picture %}`
12
+
13
+ - Select the `gallery` `markup_preset` (which you must define!):
14
+
15
+ `{% picture gallery portrait.jpg %} `
16
+
17
+ - Specify html attributes:
18
+
19
+ `{% picture portrait.jpg --picture class="some classes" data-downloadable="true" %}`
20
+
21
+ - Provide multiple source images for different screen sizes: (note that you must
22
+ define the mobile `media_preset`):
23
+
24
+ `{% picture portrait.jpg mobile: portrait-cropped.jpg %}`
25
+
26
+ - Wrap picture in a link to something:
27
+
28
+ `{% picture portrait.jpg --link /profile.html %}`
29
+
30
+ - Use liquid variables:
31
+
32
+ `{% picture {{ post.image }} %}`
33
+
34
+ - Line breaks and indentation are fine:
35
+
36
+ ```
37
+ {%
38
+ picture
39
+ gallery
40
+ portrait.jpg
41
+ mobile: portrait-cropped.jpg
42
+ --picture class="portrait" data-downloadable="true"
43
+ --img data-awesomeness="11"
44
+ --alt Ugly Mug
45
+ %}
46
+ ```
@@ -0,0 +1,115 @@
1
+ # Global Configuration
2
+
3
+ **All configuration is optional**. If you are happy with the defaults, you don't have to touch a
4
+ single yaml file.
5
+
6
+ Global settings are stored under the `picture:` key in `/_config.yml`.
7
+
8
+ **Example config:**
9
+
10
+ ```yml
11
+ picture:
12
+ source: "assets/images/fullsize"
13
+ output: "assets/images/generated"
14
+ ```
15
+
16
+ * **Source Image Directory**
17
+
18
+ *Format:* `source: (directory)`
19
+
20
+ *Example:* `source: images/`
21
+
22
+ *Default:* Jekyll site root.
23
+
24
+ To make writing tags easier you can specify a source directory for your assets. Base images in the
25
+ tag will be relative to the `source` directory, which is relative to the Jekyll site root.
26
+
27
+ For example, if `source` is set to `assets/images/_fullsize`, the tag
28
+ `{% picture enishte/portrait.jpg --alt An unsual picture %}` will look for a file at
29
+ `assets/images/_fullsize/enishte/portrait.jpg`.
30
+
31
+ * **Destination Image Directory**
32
+
33
+ *Format:* `output: (directory)`
34
+
35
+ *Example:* `output: resized_images/`
36
+
37
+ *Default*: `generated/`
38
+
39
+ Jekyll Picture Tag saves resized, reformatted images to the `output` directory in your compiled
40
+ site. The organization of your `source` directory is maintained.
41
+
42
+ This setting is relative to your compiled site, which means `_site` unless you've changed it.
43
+
44
+ * **Suppress Warnings**
45
+
46
+ *Format:* `suppress_warnings: (true|false)`
47
+
48
+ *Example:* `suppress_warnings: true`
49
+
50
+ *Default*: `false`
51
+
52
+ Jekyll Picture Tag will warn you in a few different scenarios, such as when your base image is
53
+ smaller than one of the sizes in your preset. (Note that Jekyll Picture Tag will never resize an
54
+ image to be larger than its source). Set this value to `true`, and these warnings will not be shown.
55
+
56
+ * **Continue build with missing source images**
57
+
58
+ *Format:* `ignore_missing_images: (boolean|environment name|array of environments)`
59
+
60
+ *Example:* `ignore_missing_images: [development, testing]`
61
+
62
+ *Default:* `false`
63
+
64
+ Normally, JPT will raise an error if a source image is missing, causing the entire site build to fail. This setting allows you to bypass this behavior and continue the build, either for certain build environments or all the time. I highly encourage you to set this to `development`, and set the jekyll build environment to `production` when you build for production so you don't shoot yourself in the foot (publish a site with broken images). You can read more about Jekyll environments [here](https://jekyllrb.com/docs/configuration/environments/).
65
+
66
+ * **Use Relative Urls**
67
+
68
+ *Format:* `relative_url: (true|false)`
69
+
70
+ *Example:* `relative_url: false`
71
+
72
+ *Default*: `true`
73
+
74
+ Whether to use relative (`/generated/test(...).jpg`) or absolute
75
+ (`https://example.com/generated/test(...).jpg`) urls in your src and srcset attributes.
76
+
77
+ * **Use a CDN Url**
78
+
79
+ *Format:* `cdn_url: (url)`
80
+
81
+ *Example:* `cdn_url: https://cdn.example.com`
82
+
83
+ *Default*: none
84
+
85
+ Use for images that are hosted at a different domain or subdomain than the Jekyll site root. Overrides
86
+ `relative_url`. Keep reading, the next option is important.
87
+
88
+ * **CDN build environments**
89
+
90
+ *Format:* `cdn_environments: (array of strings)`
91
+
92
+ *Example:* `cdn_environments: ['production', 'staging']`
93
+
94
+ *Default*: `['production']`
95
+
96
+ It's likely that if you're using a CDN, you may not want to use it in your local development environment. This
97
+ allows you to build a site with local images while in development, and still push to a CDN when you build for
98
+ production by specifying a different [environment](https://jekyllrb.com/docs/configuration/environments/).
99
+
100
+ **Note that the default jekyll environment is `development`**, meaning that if you only set `cdn_url` and run
101
+ `jekyll serve` or `jekyll build`, nothing will change. You'll either need to run `JEKYLL_ENV=production bundle exec
102
+ jekyll build`, or add `development` to this setting.
103
+
104
+ * **Kramdown nomarkdown fix**
105
+
106
+ *Format:* `nomarkdown: (true|false)`
107
+
108
+ *Example:* `nomarkdown: false`
109
+
110
+ *Default*: `true`
111
+
112
+ Whether or not to surround j-p-t's output with a `{::nomarkdown}..{:/nomarkdown}` block when called
113
+ from within a markdown file.
114
+
115
+ This setting is overridden by the same setting in a preset. See [this wiki page](https://github.com/rbuchberger/jekyll_picture_tag/wiki/Extra-%7B::nomarkdown%7D-tags-or-mangled-html%3F) for more detailed information.
@@ -0,0 +1,30 @@
1
+ # Installation
2
+
3
+ 1. Add `jekyll_picture_tag` to your Gemfile in the `:jekyll_plugins` group:
4
+
5
+ ```ruby
6
+ group :jekyll_plugins do
7
+ gem 'jekyll_picture_tag'
8
+ end
9
+ ```
10
+
11
+ 2. `bundle install`
12
+
13
+ 3. Verify you have ImageMagick (Good chance you do) by entering the following into a terminal:
14
+
15
+ ```
16
+ $ convert --version
17
+ ```
18
+ You should see something like this:
19
+
20
+ chronos@localhost ~ $ convert --version
21
+ Version: ImageMagick 7.0.8-14 Q16 x86_64 2018-10-31 https://imagemagick.org
22
+ Copyright: © 1999-2018 ImageMagick Studio LLC
23
+ License: https://imagemagick.org/script/license.php
24
+ Features: Cipher DPC HDRI OpenMP
25
+ Delegates (built-in): bzlib fontconfig freetype jng jp2 jpeg lcms lzma pangocairo png tiff webp xml zlib
26
+
27
+ **Note webp under delegates.** This is required if you want to generate webp files.
28
+
29
+ If you get a 'command not found' error, you'll need to install it. Most package managers
30
+ know about it, otherwise it can be downloaded [here](https://imagemagick.org/script/download.php).