jekyll-srcset-tag 0.1.4 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 194e7fb5c9eb2b7a53422c5ba2ae6a8104f0611a
4
- data.tar.gz: 5f93965bacc7f99a446962d94ffb5eb591b7ae72
3
+ metadata.gz: 12ba6eb88428a7083708074d59638015d0b012d8
4
+ data.tar.gz: 8fd8f97a70a2c21d072adb430ef9a598e4bedab0
5
5
  SHA512:
6
- metadata.gz: 341e7fa5751f78a13664b187ff85263ddd2bb6227686cae831f26c703c083b270a0dc8c69e5968e3fb9227ea073720373a87916be6181a8ae90e21d6b57aa9b6
7
- data.tar.gz: 0420a9375e8944b674d37a3f9afb0ae6ca11eef99a72b0e1b41a0bfaf72edf6f8bd8dba8fc462271a1f6469b4502bb77d2b446949e35925849ab17efb640c400
6
+ metadata.gz: 958b740d170119bb07c50a99809bda0003ce041f4755e789d663301dc177b91e4d041ef049fb08a085ce21507f01d26e55467433f6be3542d73d0fe69aa90946
7
+ data.tar.gz: 93624f3ba0dd3f08dade9097eb058b937fe7296c1027b3fda42598a6e3dc2e34aa2ec2dc5b75e377261cb157f98935e3fca602524898a62a1608fe836ea0b952
@@ -34,7 +34,7 @@ module Jekyll
34
34
 
35
35
  def to_html
36
36
  srcs = image_srcs
37
- src = CGI.escape_html(srcs.last[0])
37
+ src = CGI.escape_html(fallback_src)
38
38
  show_srcset = srcs.length > 1
39
39
  srcset = CGI.escape_html(srcs.map {|path, size| "#{path} #{size}w" }.join(', '))
40
40
  sizes = CGI::escape_html(source_sizes.join(', '))
@@ -65,7 +65,7 @@ module Jekyll
65
65
 
66
66
  def output_image_paths
67
67
  uniq_instances.map { |instance| File.join(output_dir, instance.filename)}
68
- end
68
+ end
69
69
 
70
70
  protected
71
71
 
@@ -79,16 +79,26 @@ module Jekyll
79
79
  Instance.new width: (source.width ? (source.width.to_f * ppi).round : nil),
80
80
  height: (source.height ? (source.height.to_f * ppi).round : nil),
81
81
  extension: File.extname(image_path),
82
- image: original
82
+ image: original,
83
+ fallback: source.fallback
83
84
  end
84
85
  end
85
86
 
86
87
  def image_srcs
87
88
  uniq_instances.map do |instance|
88
- [File.join(web_output_dir, instance.filename), instance.output_width.to_s]
89
+ [instance_path(instance), instance.output_width.to_s]
89
90
  end
90
91
  end
91
92
 
93
+ def instance_path(instance)
94
+ File.join(web_output_dir, instance.filename)
95
+ end
96
+
97
+ def fallback_src
98
+ fallbacks = uniq_instances.select { |instance| instance.fallback }
99
+ fallbacks.empty? ? image_srcs.last[0] : instance_path(fallbacks.last)
100
+ end
101
+
92
102
  def source_sizes
93
103
  sources.map { |source| source.size_string }
94
104
  end
@@ -3,16 +3,17 @@ module Jekyll
3
3
  class Image::Instance
4
4
 
5
5
  attr_reader :width, :height, :image, :extension, :image_width, :image_height, :output_width, :output_height,
6
- :undersized
6
+ :undersized, :fallback
7
7
 
8
- def initialize(width:, height:, extension:, image:)
8
+ def initialize(width:, height:, extension:, image:, fallback:)
9
9
  @width = width
10
10
  @height = height
11
11
  @extension = extension
12
12
  @image = image
13
13
  @image_width = image[:width].to_i
14
14
  @image_height = image[:height].to_i
15
- calculate_output_dimensions!
15
+ @fallback = fallback
16
+ calculate_output_dimensions!
16
17
  end
17
18
 
18
19
  def filename
@@ -2,13 +2,14 @@ module Jekyll
2
2
  module SrcsetTag
3
3
  class Image::Source
4
4
 
5
- attr_reader :media, :size, :width, :height
5
+ attr_reader :media, :size, :width, :height, :fallback
6
6
 
7
- def initialize(width: nil, height: nil, media: nil, size: nil)
7
+ def initialize(width: nil, height: nil, media: nil, size: nil, fallback: nil)
8
8
  @media = media
9
9
  @size = size
10
10
  @width = width
11
11
  @height = height
12
+ @fallback = fallback
12
13
  end
13
14
 
14
15
  def size_string
@@ -38,9 +38,9 @@ module Jekyll
38
38
  Image::Source.new(width: source.attr('width'),
39
39
  height: source.attr('height'),
40
40
  media: source.attr('media'),
41
- size: source.attr('size'))
41
+ size: source.attr('size'),
42
+ fallback: source.attr('fallback') == 'true')
42
43
  end
43
-
44
44
  end
45
45
 
46
46
  def image(source_path, output_path, web_output_path, markup, sources)
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module SrcsetTag
3
- VERSION = '0.1.4'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-srcset-tag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Dew
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2016-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll