jekyll-responsive_image 0.18.0 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 662862471c2e0e1b2b48d91dc8fc67eaafe18788
4
- data.tar.gz: aa73b3d89812798ce573bce3cd6ee8ec760e5874
3
+ metadata.gz: 035cab45912f4a42f03cd84441d67ca8b7ceb470
4
+ data.tar.gz: c9bdbe1866f8d64087c6d3d5e93403365469c547
5
5
  SHA512:
6
- metadata.gz: e723ddcb6bc6aad03adb71de1c6c699f3f38cb5757b3dd36b9b8b6b10f860b1bb564ec10c08aa1622e44fe6cf107d0ef3b54482cd3c2649cbe4294b09c5cb8c9
7
- data.tar.gz: 10abe87130f9cd74f36349da4ce9fc5c31a758b078624e8accc6e68f794d42f0813d1045c77b0c6f313f749afb189703c7d5115a91b8c56d612f8af29b793d37
6
+ metadata.gz: 28a085761f120c5f0d9e667cc931d1f51bbacd99fa85a3b6184b2363bdcc564c47c1feafb1b079e8a85b1214d4967f14f92da7dcac7696438324b560544b31ea
7
+ data.tar.gz: 3f4bea2b3ffaad9f0783f309f1850fd655810ce062a2d5e5de4252dfbd5cbd310d4242c6a98bcf9174548349a47920f0177b32235767e8afcc8fa1c2c76ca00c
@@ -1,33 +1,20 @@
1
- module Jekyll
2
- class ResponsiveImage
3
- class Block < Liquid::Block
4
- include Jekyll::ResponsiveImage::Common
5
1
 
6
- def render(context)
7
- attributes = YAML.load(super)
8
2
 
9
- cache_key = attributes.to_s
10
- result = attributes['cache'] ? RenderCache.get(cache_key) : nil
11
3
 
12
- if result.nil?
13
- site = context.registers[:site]
14
- config = make_config(site)
15
4
 
16
- image_template = attributes['template'] || config['template']
17
5
 
18
- image = ImageProcessor.process(attributes['path'], config)
19
- attributes['original'] = image[:original]
20
- attributes['resized'] = image[:resized]
21
6
 
22
- partial = File.read(image_template)
23
- template = Liquid::Template.parse(partial)
24
7
 
25
- result = template.render!(attributes.merge(site.site_payload))
26
8
 
27
- RenderCache.set(cache_key, result)
28
- end
29
9
 
30
- result
10
+ module Jekyll
11
+ class ResponsiveImage
12
+ class Block < Liquid::Block
13
+ include Jekyll::ResponsiveImage::Common
14
+
15
+ def render(context)
16
+ attributes = YAML.load(super)
17
+ render_responsive_image(context, attributes)
31
18
  end
32
19
  end
33
20
  end
@@ -4,15 +4,42 @@ module Jekyll
4
4
  include Jekyll::ResponsiveImage::Utils
5
5
 
6
6
  def make_config(site)
7
- config = ResponsiveImage.defaults.dup.merge(site.config['responsive_image']).merge(:site_dest => site.dest)
7
+ ResponsiveImage.defaults.dup
8
+ .merge(site.config['responsive_image'])
9
+ .merge(:site_source => site.source, :site_dest => site.dest)
10
+ end
11
+
12
+ def keep_resized_image!(site, image)
13
+ keep_dir = File.dirname(image['path'])
14
+ site.config['keep_files'] << keep_dir unless site.config['keep_files'].include?(keep_dir)
15
+ end
16
+
17
+ def render_responsive_image(context, attributes)
18
+ cache_key = attributes.to_s
19
+ result = attributes['cache'] ? RenderCache.get(cache_key) : nil
20
+
21
+ if result.nil?
22
+ site = context.registers[:site]
23
+ config = make_config(site)
24
+
25
+ source_image_path = site.in_source_dir(attributes['path'].to_s)
26
+ image = ImageProcessor.process(source_image_path, config)
27
+ attributes['original'] = image[:original]
28
+ attributes['resized'] = image[:resized]
29
+
30
+ attributes['resized'].each { |resized| keep_resized_image!(site, resized) }
31
+
32
+ image_template = site.in_source_dir(attributes['template'] || config['template'])
33
+ partial = File.read(image_template)
34
+ template = Liquid::Template.parse(partial)
35
+
36
+ result = template.render!(attributes.merge(site.site_payload))
8
37
 
9
- # Not very nice, but this is needed to create a clean path to add to keep_files
10
- output_dir = format_output_path(config['output_path_format'], config['base_path'], '*', '*', '*')
11
- output_dir = "#{File.dirname(output_dir)}/*"
12
38
 
13
- site.config['keep_files'] << output_dir unless site.config['keep_files'].include?(output_dir)
39
+ RenderCache.set(cache_key, result)
40
+ end
14
41
 
15
- config
42
+ result
16
43
  end
17
44
  end
18
45
  end
@@ -7,7 +7,10 @@ module Jekyll
7
7
  config = make_config(site)
8
8
 
9
9
  config['extra_images'].each do |pathspec|
10
- Dir.glob(pathspec) { |path| ImageProcessor.process(path, config) }
10
+ Dir.glob(site.in_source_dir(pathspec)) do |path|
11
+ result = ImageProcessor.process(path, config)
12
+ result[:resized].each { |image| keep_resized_image!(site, image) }
13
+ end
11
14
  end
12
15
  end
13
16
  end
@@ -4,7 +4,7 @@ module Jekyll
4
4
  include ResponsiveImage::Utils
5
5
 
6
6
  def process(image_path, config)
7
- raise SyntaxError.new("Invalid image path specified: #{image_path}") unless File.exist?(image_path.to_s)
7
+ raise SyntaxError.new("Invalid image path specified: #{image_path}") unless File.file?(image_path)
8
8
 
9
9
  resize_handler = ResizeHandler.new
10
10
  img = Magick::Image::read(image_path).first
@@ -17,22 +17,24 @@ module Jekyll
17
17
  filepath = format_output_path(config['output_path_format'], config['base_path'], image_path, width, height)
18
18
  resized.push(image_hash(config['base_path'], filepath, width, height))
19
19
 
20
+ site_source_filepath = File.expand_path(filepath, config[:site_source])
21
+ site_dest_filepath = File.expand_path(filepath, config[:site_dest])
22
+
20
23
  # Don't resize images more than once
21
- next if File.exist?(filepath)
24
+ next if File.exist?(site_source_filepath)
22
25
 
23
- ensure_output_dir_exists!(File.dirname(filepath))
26
+ ensure_output_dir_exists!(File.dirname(site_source_filepath))
27
+ ensure_output_dir_exists!(File.dirname(site_dest_filepath))
24
28
 
25
29
  Jekyll.logger.info "Generating #{filepath}"
26
30
 
27
31
  i = img.scale(ratio)
28
- i.write(filepath) do |f|
32
+ i.write(site_source_filepath) do |f|
29
33
  f.quality = size['quality'] || config['default_quality']
30
34
  end
31
35
 
32
36
  # Ensure the generated file is copied to the _site directory
33
- site_dest_filepath = File.expand_path(filepath, config[:site_dest])
34
- ensure_output_dir_exists!(File.dirname(site_dest_filepath))
35
- FileUtils.copy(filepath, site_dest_filepath)
37
+ FileUtils.copy_file(site_source_filepath, site_dest_filepath)
36
38
 
37
39
  i.destroy!
38
40
  end
@@ -15,28 +15,7 @@ module Jekyll
15
15
  end
16
16
 
17
17
  def render(context)
18
- cache_key = @attributes.to_s
19
- result = @attributes['cache'] ? RenderCache.get(cache_key) : nil
20
-
21
- if result.nil?
22
- site = context.registers[:site]
23
- config = make_config(site)
24
-
25
- image = ImageProcessor.process(@attributes['path'], config)
26
- @attributes['original'] = image[:original]
27
- @attributes['resized'] = image[:resized]
28
-
29
- image_template = @attributes['template'] || config['template']
30
-
31
- partial = File.read(image_template)
32
- template = Liquid::Template.parse(partial)
33
-
34
- result = template.render!(@attributes.merge(site.site_payload))
35
-
36
- RenderCache.set(cache_key, result)
37
- end
38
-
39
- result
18
+ render_responsive_image(context, @attributes)
40
19
  end
41
20
  end
42
21
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  class ResponsiveImage
3
- VERSION = '0.18.0'.freeze
3
+ VERSION = '1.0.0.pre'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,53 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-responsive_image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Wynn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-02 00:00:00.000000000 Z
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '4.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '2.0'
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '4.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rmagick
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '>='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '2.0'
40
- - - <
40
+ - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '3.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - '>='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '2.0'
50
- - - <
50
+ - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '3.0'
53
53
  description: "\n Jekyll Responsive Images is a Jekyll plugin and utility for automatically
@@ -80,17 +80,17 @@ require_paths:
80
80
  - lib
81
81
  required_ruby_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - '>='
83
+ - - ">="
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ">"
89
89
  - !ruby/object:Gem::Version
90
- version: '0'
90
+ version: 1.3.1
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.0.14.1
93
+ rubygems_version: 2.5.1
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Responsive images for Jekyll via srcset