middleman-simple-thumbnailer 1.0.1 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f73765adf97c15fc2ffefd078aac9bae3646122d
4
- data.tar.gz: 7287fbac263dd1b35686eb068f9c5d6718eaa54d
3
+ metadata.gz: a8fcbef0d63780a552248c4a83a2450abdacb456
4
+ data.tar.gz: 0dba15673827e0da8cbe89d9ee4f49dc844d29a6
5
5
  SHA512:
6
- metadata.gz: 9db70c0e818fa2d613e879a6c066a2646b4b15cf6cd3a4969bb40a38c4dfd08846d5337f77c930942be48ebea8aede70383f7eda556b74a89a64443039806eee
7
- data.tar.gz: d6ad8be072908e271bd5490cb0dd6f9246d58a846f2177aa11c998c0d46f45e70596182a7b12666b61cf80daa116743e2f0910dc62ee80ae5dfa68ac3cd6c777
6
+ metadata.gz: dcbfcc6a3f1373bb78c578c522a002fc265971d701dc9fc98efd7c40d9c8cc599be47a4fd05d3cb3463f105769a1134a901448f1c4fd0eec89a0af657bd76bf0
7
+ data.tar.gz: cd5abd6b19674cbab8273324022711d3cda865f70e3cf3df484cfd8273a1a7b51cdeb20d706ce60429b1155111539a478cdeace265f30edb35825108c2e554f7
@@ -20,8 +20,9 @@ Feature: Generate image thumbnails
20
20
  Given a fixture app "basic-app"
21
21
  And a successfully built app at "basic-app"
22
22
  When I cd to "build"
23
- Then the following files should exist:
24
- | images/original.10x10gt.jpg |
25
- | images/original.5x5.jpg |
23
+ Then the following images should exist:
24
+ | filename | dimensions |
25
+ | images/original.10x10gt.jpg | 10x5 |
26
+ | images/original.5x5.jpg | 5x2 |
26
27
  And the file "page-with-images-to-resize.html" should contain '<img class="image-resized-to10x10" src="/images/original.10x10gt.jpg" />'
27
28
  And the file "page-with-images-to-resize.html" should contain '<img class="image-resized-to5x5" src="/images/original.5x5.jpg" />'
@@ -25,3 +25,12 @@ Then(/^I should see base64ed data of the cached thumbnails$/) do
25
25
  step %Q{I should see '#{image10x10}'}
26
26
  step %Q{I should see '#{image5x5}'}
27
27
  end
28
+
29
+ Then(/^the following images should exist:$/) do |table|
30
+ table.hashes.each do |row|
31
+ in_current_dir do
32
+ image = MiniMagick::Image.open(row["filename"])
33
+ expect(image.dimensions).to eq row["dimensions"].split("x").map(&:to_i)
34
+ end
35
+ end
36
+ end
@@ -30,8 +30,7 @@ module MiddlemanSimpleThumbnailer
30
30
  resize_to = options.delete(:resize_to)
31
31
  return super(path, options) unless resize_to
32
32
 
33
- image = MiddlemanSimpleThumbnailer::Image.new(path, self.config)
34
- image.resize!(resize_to)
33
+ image = MiddlemanSimpleThumbnailer::Image.new(path, resize_to, self.config)
35
34
  if environment == :development
36
35
  super("data:#{image.mime_type};base64,#{image.base64_data}", options)
37
36
  else
@@ -1,5 +1,4 @@
1
1
  require "digest"
2
- require 'fileutils'
3
2
 
4
3
  module MiddlemanSimpleThumbnailer
5
4
  class Image
@@ -8,10 +7,11 @@ module MiddlemanSimpleThumbnailer
8
7
 
9
8
  attr_accessor :img_path, :middleman_config, :resize_to
10
9
 
11
- def initialize(img_path, middleman_config)
10
+ def initialize(img_path, resize_to, middleman_config)
12
11
  @@all_objects << self
13
12
 
14
13
  @img_path = img_path
14
+ @resize_to = resize_to
15
15
  @middleman_config = middleman_config
16
16
  end
17
17
 
@@ -24,22 +24,16 @@ module MiddlemanSimpleThumbnailer
24
24
  end
25
25
 
26
26
  def base64_data
27
+ unless cached_thumbnail_available?
28
+ resize!
29
+ save_cached_thumbnail
30
+ end
27
31
  Base64.encode64(File.read(cached_resized_img_abs_path))
28
32
  end
29
33
 
30
- def resize!(resize_to)
31
- self.resize_to = resize_to
32
- return if cached_thumbnail_available?
33
- image.resize(resize_to)
34
- save_cached_thumbnail
35
- end
36
-
37
34
  def save!
38
- if cached_thumbnail_available?
39
- FileUtils.cp cached_resized_img_abs_path, resized_img_abs_path
40
- else
41
- image.write(resized_img_abs_path)
42
- end
35
+ resize!
36
+ image.write(resized_img_abs_path)
43
37
  end
44
38
 
45
39
  def self.all_objects
@@ -52,6 +46,13 @@ module MiddlemanSimpleThumbnailer
52
46
 
53
47
 
54
48
  private
49
+
50
+ def resize!
51
+ unless @already_resized
52
+ image.resize(resize_to)
53
+ @already_resized = true
54
+ end
55
+ end
55
56
 
56
57
  def image
57
58
  @image ||= MiniMagick::Image.open(abs_path)
@@ -67,7 +68,7 @@ module MiddlemanSimpleThumbnailer
67
68
 
68
69
  def resized_image_name
69
70
  image_name.split('.').tap { |a| a.insert(-2, resize_to) }.join('.') # add resize_to sufix
70
- .gsub(/[%@!<>]/, '>' => 'gt', '<' => 'lt') # sanitize file name
71
+ .gsub(/[%@!<>^]/, '>' => 'gt', '<' => 'lt', '^' => 'c') # sanitize file name
71
72
  end
72
73
 
73
74
  def abs_path
@@ -1,3 +1,3 @@
1
1
  module MiddlemanSimpleThumbnailer
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-simple-thumbnailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Niewczas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-06 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core