middleman-simple-thumbnailer 1.2.1 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +68 -18
- data/features/generate_new_data_file.feature +21 -0
- data/features/given_data_file.feature +30 -0
- data/features/support/image_thumbnails_steps.rb +17 -0
- data/fixtures/basic-app-data-file-generate/config.rb +1 -0
- data/fixtures/basic-app-data-file-generate/source/images/original.jpg +0 -0
- data/fixtures/basic-app-data-file-generate/source/page-with-images-to-resize.html.erb +10 -0
- data/fixtures/basic-app-data-file-generate/source/page-with-untouched-image.html.erb +9 -0
- data/fixtures/basic-app-data-file/config.rb +1 -0
- data/fixtures/basic-app-data-file/data/simple_thumbnailer.yml +5 -0
- data/fixtures/basic-app-data-file/source/images/original.jpg +0 -0
- data/fixtures/basic-app-data-file/source/page-with-images-to-resize.html.erb +10 -0
- data/fixtures/basic-app-data-file/source/page-with-untouched-image.html.erb +9 -0
- data/fixtures/basic-app-data-file/source/sitemap.html.erb +5 -0
- data/lib/middleman-simple-thumbnailer.rb +1 -0
- data/lib/middleman-simple-thumbnailer/extension.rb +102 -7
- data/lib/middleman-simple-thumbnailer/image.rb +24 -19
- data/lib/middleman-simple-thumbnailer/resource.rb +19 -0
- data/lib/middleman-simple-thumbnailer/version.rb +1 -1
- data/middleman-simple-thumbnailer.gemspec +1 -1
- metadata +28 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f738be722cfd75602105485c2d54b3b4ff3b20d2
|
4
|
+
data.tar.gz: 6ac6bd63e0f0edca8da22098fd592a9561815830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79a5a651236dbb42beb6ebeb1eb0d121ab37f58436b2c830a943d49f55ed07ebf20288e28cb38955a964e3b678cc0ae6bd3df4ca960841b812995261974829c3
|
7
|
+
data.tar.gz: 9f136cefaf74ed148b79cd1e8e7de2347d10e8eeb6b60e7f22e682ed5faee63b8ee2b72e442cd0223b1a65793a95f7eb03348deedf8ddf4ef73e665578a044fc
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -4,17 +4,19 @@ Middleman Simple Thumbnailer [![Build Status](https://travis-ci.org/kubenstein/m
|
|
4
4
|
Middleman Simple Thumbnailer is a [Middleman](http://middlemanapp.com/) extension that allows you to create image thumbnails by providing `resize_to` option to image_tag helper.
|
5
5
|
|
6
6
|
|
7
|
-
Installation
|
8
|
-
|
7
|
+
## Installation
|
8
|
+
|
9
9
|
Put this line into your `Gemfile`:
|
10
10
|
```
|
11
11
|
gem 'middleman-simple-thumbnailer'
|
12
12
|
```
|
13
13
|
|
14
|
-
Usage
|
15
|
-
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
### All mode
|
17
|
+
|
16
18
|
Enable the extension in `config.rb`:
|
17
|
-
```
|
19
|
+
```ruby
|
18
20
|
activate :middleman_simple_thumbnailer
|
19
21
|
```
|
20
22
|
|
@@ -24,9 +26,9 @@ And modify your `image_tag`'s by adding `resize_to` parameter:
|
|
24
26
|
```
|
25
27
|
|
26
28
|
You can also use the `image_path` helper the same way in place where you need only the path of the resized image:
|
27
|
-
```
|
29
|
+
```html
|
28
30
|
<picture>
|
29
|
-
<source srcset="<%= image_path
|
31
|
+
<source srcset="<%= image_path 'original.jpg', resize_to: 1200 %>" media="(min-width: 900px)">
|
30
32
|
<%= image_tag "original.jpg", resize_to: "400%", class: 'the-image-class' %>
|
31
33
|
</picture>
|
32
34
|
```
|
@@ -34,19 +36,67 @@ You can also use the `image_path` helper the same way in place where you need on
|
|
34
36
|
This extension use ImageMagick (via mini_magick) to resize the images.
|
35
37
|
The `resize_to` format is therefore the one defined ny ImageMagick. The documentation can be found [there](http://www.imagemagick.org/script/command-line-processing.php#geometry).
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
+
### Dynamic mode
|
40
|
+
|
41
|
+
This mode is the default operating mode for this extension.
|
42
|
+
The images are generated according to their declaration in the helpers.
|
43
|
+
See the [known limitations](#known-limitation) paragraph below for known limitation in this mode.
|
44
|
+
|
45
|
+
### Declarative mode
|
46
|
+
|
47
|
+
In this mode, the resized file are declared. They are then added to the sitemap and generated at the same time than the other files.
|
48
|
+
|
49
|
+
To activate this new mode, the option `:use_specs` must be used when activating the extension.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
activate :middleman_simple_thumbnailer, use_specs: true
|
53
|
+
```
|
54
|
+
|
55
|
+
Then the resizing specifications must be declared in a special [Middleman data file](https://middlemanapp.com/advanced/data-files/). By default the extension will look for `data/simple_thumbnailer.yaml`.
|
56
|
+
|
57
|
+
This file must contains a list of mappings with the following keys:
|
58
|
+
- `path`: the relative path of the image file in the `source\images` folder. This can be a glob pattern (https://ruby-doc.org/core/Dir.html#method-c-glob) (still relative to the `source\images` folder).
|
59
|
+
- `resize_to`: the [ImageMagix resize](http://www.imagemagick.org/script/command-line-processing.php#geometry) parameter
|
60
|
+
|
61
|
+
example (in yaml, file `data/simple_thumbnailer.yaml`):
|
62
|
+
|
63
|
+
```yaml
|
64
|
+
---
|
65
|
+
- path: original.jpg
|
66
|
+
resize_to: 10x10
|
67
|
+
- path: "*.jpg"
|
68
|
+
resize_to: 5x5
|
69
|
+
```
|
70
|
+
|
71
|
+
The use of the `image_tag` and `image_path` helpers stay the same.
|
72
|
+
|
73
|
+
In this mode if a resizing specification found in an `image_tag` or `image_path` helper is not declared in the specification data file, a warning is emitted and the data file is rewritten to include the resizing specification. If the specification file doesn't exist, it is created (this behavior can be configured).
|
74
|
+
|
75
|
+
|
76
|
+
### options
|
77
|
+
|
78
|
+
Option | default value | Description
|
79
|
+
------------------------------|----------------------------------|-------------
|
80
|
+
:cache_dir | `'tmp/simple-thumbnailer-cache'` | Directory (relative to project root) for cached thumbnails.
|
81
|
+
:use_specs | `false` | Wether or not use resize specfication data file
|
82
|
+
:specs\_data | `'simple_thumbnailer'` | name of the specification data file. It must follow the Middleman data file name convention.
|
83
|
+
:specs\_data\_default\_format | `'yaml'` | defaut specification format (and extension). Can be 'yml', 'yaml', 'json'
|
84
|
+
:specs\_data\_save\_old | `true` | save previous specification data file
|
85
|
+
:update\_specs | `true` | Warn about missing image files in the specification file and add them to it. The spécification file will be overwritten.
|
86
|
+
|
87
|
+
|
88
|
+
## Known limitation
|
89
|
+
|
90
|
+
In the dynamic mode, this extension is unable to update the [sitemap](https://middlemanapp.com/advanced/sitemap/). Some extensions (like [middleman-s3_sync](https://github.com/fredjean/middleman-s3_sync)) uses the content of the sitemap to do their work. Therefore, the generated resized images will not be seen by such extensions, even if they are corectly generated.
|
91
|
+
|
92
|
+
|
93
|
+
## Build/Development modes
|
94
|
+
|
95
|
+
During development thumbnails will be created on fly and presented as a base64 strings.
|
39
96
|
|
40
|
-
|
97
|
+
During build thumbnails will be created as normal files and stored in same dir as their originals.
|
41
98
|
|
42
|
-
This issue [#13](https://github.com/kubenstein/middleman-simple-thumbnailer/issues/13) has been opened to describe the problem and discuss the possible solutions to this limitation.
|
43
99
|
|
44
|
-
|
45
|
-
-----
|
46
|
-
During development thumbnails will be created on fly and presented as a base64 strings.
|
47
|
-
During build thumbnails will be created as normal files and stored in same dir as their originals.
|
48
|
-
|
100
|
+
## LICENSE
|
49
101
|
|
50
|
-
LICENSE
|
51
|
-
-----
|
52
102
|
MIT
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: Generate data file
|
2
|
+
|
3
|
+
Scenario: Check images
|
4
|
+
Given a fixture app "basic-app-data-file-generate"
|
5
|
+
And a successfully built app at "basic-app-data-file"
|
6
|
+
When I cd to "build"
|
7
|
+
Then the following images should exist:
|
8
|
+
| filename | dimensions |
|
9
|
+
| images/original.10x10gt.jpg | 10x5 |
|
10
|
+
| images/original.5x5.jpg | 5x2 |
|
11
|
+
|
12
|
+
Scenario: Check generated data file content
|
13
|
+
Given a fixture app "basic-app-data-file-generate"
|
14
|
+
And a successfully built app at "basic-app-data-file-generate"
|
15
|
+
When I cd to "data"
|
16
|
+
Then a file named "simple_thumbnailer.yaml" should exist
|
17
|
+
And file "simple_thumbnailer.yaml" should contain the following data:
|
18
|
+
| path | resize_to |
|
19
|
+
| original.jpg | 5x5 |
|
20
|
+
| original.jpg | 10x10> |
|
21
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Feature: Use data file
|
2
|
+
|
3
|
+
Scenario: Check images from data file
|
4
|
+
Given a fixture app "basic-app-data-file"
|
5
|
+
And a successfully built app at "basic-app-data-file"
|
6
|
+
When I cd to "build"
|
7
|
+
Then the following images should exist:
|
8
|
+
| filename | dimensions |
|
9
|
+
| images/original.10x10.jpg | 10x5 |
|
10
|
+
| images/original.10x10gt.jpg | 10x5 |
|
11
|
+
| images/original.5x5.jpg | 5x2 |
|
12
|
+
|
13
|
+
Scenario: Check data file content
|
14
|
+
Given a fixture app "basic-app-data-file"
|
15
|
+
And a successfully built app at "basic-app-data-file"
|
16
|
+
When I cd to "data"
|
17
|
+
Then a file named "simple_thumbnailer.yml" should exist
|
18
|
+
And file "simple_thumbnailer.yml" should contain the following data:
|
19
|
+
| path | resize_to |
|
20
|
+
| original.jpg | 10x10 |
|
21
|
+
| *.jpg | 5x5 |
|
22
|
+
| original.jpg | 10x10> |
|
23
|
+
|
24
|
+
Scenario: Check sitemap file
|
25
|
+
Given a successfully built app at "basic-app-data-file"
|
26
|
+
When I cd to "build"
|
27
|
+
Then a file named "sitemap.html" should exist
|
28
|
+
And the file "sitemap.html" should contain '<li><a href="/images/original.10x10.jpg">/images/original.10x10.jpg</a></li>'
|
29
|
+
And the file "sitemap.html" should contain '<li><a href="/images/original.5x5.jpg">/images/original.5x5.jpg</a></li>'
|
30
|
+
And the file "sitemap.html" should not contain '<li><a href="/images/original.10x10gt.jpg">/images/original.10x10gt.jpg</a></li>'
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'base64'
|
2
|
+
require 'yaml'
|
3
|
+
|
2
4
|
def calculate_resized_image_b64(resize_str)
|
3
5
|
base_image = MiniMagick::Image.open(File.expand_path("../../fixtures/basic-app/source/images/original.jpg", __dir__))
|
4
6
|
base_image.resize(resize_str)
|
@@ -74,3 +76,18 @@ Then(/^the following images should exist:$/) do |table|
|
|
74
76
|
end
|
75
77
|
end
|
76
78
|
end
|
79
|
+
|
80
|
+
Then(/^file "([^"]+)" should contain the following data:$/) do |file, data|
|
81
|
+
expect(file).to be_an_existing_file
|
82
|
+
cd('.') do
|
83
|
+
specs = YAML.load_file(file)
|
84
|
+
expect(specs.length).to eq(data.hashes.length)
|
85
|
+
data.hashes.each do |hash|
|
86
|
+
expect(specs).to include(hash)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
Then(/^the file "([^"]*)" should not contain '([^']*)'$/) do |file, partial_content|
|
92
|
+
expect(file).not_to have_file_content(Regexp.new(Regexp.escape(partial_content)), true)
|
93
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :middleman_simple_thumbnailer, use_specs: true
|
Binary file
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Hello World</title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<%= image_tag 'original.jpg', resize_to: '10x10>', class: 'image-resized-to10x10' %>
|
8
|
+
<%= image_tag 'original.jpg', resize_to: '5x5', class: 'image-resized-to5x5' %>
|
9
|
+
</body>
|
10
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :middleman_simple_thumbnailer, use_specs: true
|
Binary file
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Hello World</title>
|
5
|
+
</head>
|
6
|
+
<body>
|
7
|
+
<%= image_tag 'original.jpg', resize_to: '10x10>', class: 'image-resized-to10x10gt' %>
|
8
|
+
<%= image_tag 'original.jpg', resize_to: '5x5', class: 'image-resized-to5x5' %>
|
9
|
+
</body>
|
10
|
+
</html>
|
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'tmpdir'
|
2
|
+
require 'yaml'
|
3
|
+
require 'json'
|
4
|
+
require 'tempfile'
|
2
5
|
# add resize_to param to image_tag to create thumbnails
|
3
6
|
#
|
4
7
|
#
|
@@ -9,39 +12,131 @@ module MiddlemanSimpleThumbnailer
|
|
9
12
|
class Extension < Middleman::Extension
|
10
13
|
|
11
14
|
option :cache_dir, 'tmp/simple-thumbnailer-cache', 'Directory (relative to project root) for cached thumbnails.'
|
15
|
+
option :use_specs, false, 'Wether or not use the specification data file'
|
16
|
+
option :specs_data, 'simple_thumbnailer', 'name of the specification data file. Must follow middleman data file name convention'
|
17
|
+
option :specs_data_default_format, 'yaml', 'defaut specification file format (and extension). Can be yaml, yml or json'
|
18
|
+
option :specs_data_save_old, true, 'save previous specification data file '
|
19
|
+
option :update_specs, true, 'Warn about missing image file in specification and add them to teh spec file'
|
12
20
|
|
13
21
|
def initialize(app, options_hash={}, &block)
|
14
22
|
super
|
15
23
|
@images_store = MiddlemanSimpleThumbnailer::ImageStore.new
|
24
|
+
@resize_specs = app.data[options.specs_data] || []
|
25
|
+
if @resize_specs.length == 0
|
26
|
+
@resize_specs = []
|
27
|
+
end
|
28
|
+
if !%w(yaml yml json).include?(options.specs_data_default_format)
|
29
|
+
raise "value assigned to option specs_data_default_format is not correct. should be one of json, yaml, or yml"
|
30
|
+
end
|
16
31
|
end
|
17
32
|
|
18
33
|
def store_resized_image(img_path, resize_to)
|
19
34
|
@images_store.store(img_path, resize_to)
|
20
35
|
end
|
21
36
|
|
22
|
-
def after_configuration
|
23
|
-
|
37
|
+
# def after_configuration
|
38
|
+
# MiddlemanSimpleThumbnailer::Image.options = options
|
39
|
+
# end
|
40
|
+
|
41
|
+
def check_image_in_specs(img_path, resize_to)
|
42
|
+
@resize_specs.each do |resize_spec|
|
43
|
+
if resize_to == resize_spec.resize_to && File.fnmatch(resize_spec.path, img_path)
|
44
|
+
return true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
return false
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# def source_dir
|
52
|
+
# File.absolute_path(app.config[:source], app.root)
|
53
|
+
# end
|
54
|
+
|
55
|
+
|
56
|
+
def manipulate_resource_list(resources)
|
57
|
+
return resources unless options.use_specs
|
58
|
+
resources + @resize_specs.reduce([]) do |res, resize_spec|
|
59
|
+
Dir.chdir(File.absolute_path(File.join(app.root, app.config[:source], app.config[:images_dir]))) do
|
60
|
+
Dir.glob(resize_spec.path) do |image_file|
|
61
|
+
store_resized_image(image_file, resize_spec.resize_to)
|
62
|
+
img = MiddlemanSimpleThumbnailer::Image.new(image_file, resize_spec.resize_to, app, options).tap do |i|
|
63
|
+
i.prepare_thumbnail
|
64
|
+
end
|
65
|
+
resized_image_path = File.join(app.config[:images_dir],img.resized_img_path)
|
66
|
+
new_resource = MiddlemanSimpleThumbnailer::Resource.new(
|
67
|
+
app.sitemap,
|
68
|
+
resized_image_path,
|
69
|
+
img.cached_resized_img_abs_path,
|
70
|
+
)
|
71
|
+
res.push(new_resource)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
res
|
75
|
+
end
|
24
76
|
end
|
25
77
|
|
26
78
|
def after_build(builder)
|
79
|
+
resize_specs_modified = false
|
27
80
|
@images_store.each do |img_path, resize_to|
|
28
|
-
|
29
|
-
|
30
|
-
|
81
|
+
if options.use_specs && options.update_specs && !check_image_in_specs(img_path, resize_to)
|
82
|
+
builder.thor.say_status :warning, "#{img_path}:#{resize_to} not in resize spec", :yellow
|
83
|
+
@resize_specs.push(Middleman::Util::EnhancedHash.new({'path': img_path, 'resize_to': resize_to}))
|
84
|
+
resize_specs_modified = true
|
85
|
+
end
|
86
|
+
img = MiddlemanSimpleThumbnailer::Image.new(img_path, resize_to, builder.app, options)
|
87
|
+
if !File.exists?(img.resized_img_abs_path)
|
88
|
+
builder.thor.say_status :create, "#{img.resized_img_abs_path}"
|
89
|
+
img.save!
|
90
|
+
end
|
31
91
|
end
|
32
92
|
@images_store.delete
|
93
|
+
if options.update_specs && resize_specs_modified
|
94
|
+
builder.thor.say_status :warning, "Resize specs modified, rewrite", :yellow
|
95
|
+
write_specs_file
|
96
|
+
end
|
33
97
|
end
|
34
98
|
|
99
|
+
def get_data_file_path_ext
|
100
|
+
specs_data_list = Dir.glob(File.absolute_path(File.join(app.root, app.config[:data_dir],"#{options.specs_data}.{json,yml,yaml}")))
|
101
|
+
if specs_data_list.length > 0
|
102
|
+
return specs_data_list[0], File.extname(specs_data_list[0])[1..-1]
|
103
|
+
else
|
104
|
+
return File.absolute_path(File.join(app.root, app.config[:data_dir],"#{options.specs_data}.#{options.specs_data_default_format}")), options.specs_data_default_format
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def write_specs_file
|
109
|
+
data_file, ext = get_data_file_path_ext
|
110
|
+
FileUtils.mkdir_p File::dirname(data_file)
|
111
|
+
if File.exists?(data_file) && options.specs_data_save_old
|
112
|
+
i = 1
|
113
|
+
old_data_file = "#{data_file}.#{i}"
|
114
|
+
while File.exists?(old_data_file) && (i+=1) < ((2**16)-1)
|
115
|
+
old_data_file = "#{data_file}.#{i}"
|
116
|
+
end
|
117
|
+
raise "Middleman-simple-thumbnailer : could not find a filename for saving the data file " if i == ((2**16)-1)
|
118
|
+
FileUtils.cp(data_file, old_data_file)
|
119
|
+
end
|
120
|
+
new_specs = @resize_specs.map do |resize_spec|
|
121
|
+
resize_spec.to_hash
|
122
|
+
end
|
123
|
+
File.open(data_file, 'w') {|f| f.write ((%w(yaml yml).include?(ext))?new_specs.to_yaml():JSON.pretty_generate(new_specs)) }
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
private :check_image_in_specs, :get_data_file_path_ext, :write_specs_file
|
128
|
+
|
35
129
|
helpers do
|
36
130
|
|
37
131
|
def resized_image_path(path, resize_to=nil)
|
38
132
|
return path unless resize_to
|
39
133
|
|
40
|
-
|
134
|
+
ext = app.extensions[:middleman_simple_thumbnailer]
|
135
|
+
|
136
|
+
image = MiddlemanSimpleThumbnailer::Image.new(path, resize_to, app, ext.options)
|
41
137
|
if app.development?
|
42
138
|
"data:#{image.mime_type};base64,#{image.base64_data}"
|
43
139
|
else
|
44
|
-
ext = app.extensions[:middleman_simple_thumbnailer]
|
45
140
|
ext.store_resized_image(path, resize_to)
|
46
141
|
image.resized_img_path
|
47
142
|
end
|
@@ -3,15 +3,15 @@ require 'base64'
|
|
3
3
|
|
4
4
|
module MiddlemanSimpleThumbnailer
|
5
5
|
class Image
|
6
|
-
@@options = nil
|
7
6
|
|
8
7
|
attr_accessor :img_path, :middleman_config, :resize_to
|
9
8
|
|
10
|
-
def initialize(img_path, resize_to, app)
|
9
|
+
def initialize(img_path, resize_to, app, options_hash)
|
11
10
|
@img_path = img_path
|
12
11
|
@resize_to = resize_to
|
13
12
|
@middleman_config = app.config
|
14
13
|
@app = app
|
14
|
+
@options = options_hash
|
15
15
|
end
|
16
16
|
|
17
17
|
def mime_type
|
@@ -22,26 +22,32 @@ module MiddlemanSimpleThumbnailer
|
|
22
22
|
img_path.gsub(image_name, resized_image_name)
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def prepare_thumbnail
|
26
26
|
unless cached_thumbnail_available?
|
27
27
|
resize!
|
28
28
|
save_cached_thumbnail
|
29
29
|
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def base64_data
|
33
|
+
prepare_thumbnail
|
30
34
|
Base64.strict_encode64(File.read(cached_resized_img_abs_path))
|
31
35
|
end
|
32
36
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
def render
|
38
|
+
prepare_thumbnail
|
39
|
+
File.read(cached_resized_img_abs_path)
|
40
|
+
end
|
41
|
+
|
38
42
|
|
43
|
+
def save!
|
44
|
+
prepare_thumbnail
|
39
45
|
FileUtils.copy_file(cached_resized_img_abs_path, resized_img_abs_path)
|
40
46
|
end
|
41
47
|
|
42
|
-
def self.options=(options)
|
43
|
-
|
44
|
-
end
|
48
|
+
# def self.options=(options)
|
49
|
+
# @@options = options
|
50
|
+
# end
|
45
51
|
|
46
52
|
def resized_img_abs_path
|
47
53
|
File.join(build_dir, middleman_abs_path).gsub(image_name, resized_image_name)
|
@@ -55,6 +61,11 @@ module MiddlemanSimpleThumbnailer
|
|
55
61
|
img_path.start_with?('/') ? img_path : File.join(images_dir, img_path)
|
56
62
|
end
|
57
63
|
|
64
|
+
def cached_resized_img_abs_path
|
65
|
+
File.join(cache_dir, middleman_abs_path).gsub(image_name, resized_image_name).split('.').tap { |a|
|
66
|
+
a.insert(-2, image_checksum)
|
67
|
+
}.join('.')
|
68
|
+
end
|
58
69
|
|
59
70
|
private
|
60
71
|
|
@@ -79,19 +90,13 @@ module MiddlemanSimpleThumbnailer
|
|
79
90
|
|
80
91
|
def resized_image_name
|
81
92
|
image_name.split('.').tap { |a| a.insert(-2, resize_to) }.join('.') # add resize_to sufix
|
82
|
-
.gsub(/[%@!<>^]/, '>' => 'gt', '<' => 'lt', '^' => 'c')
|
93
|
+
.gsub(/[%@!<>^]/, '>' => 'gt', '<' => 'lt', '^' => 'c') # sanitize file name
|
83
94
|
end
|
84
95
|
|
85
96
|
def abs_path
|
86
97
|
File.join(source_dir, middleman_abs_path)
|
87
98
|
end
|
88
99
|
|
89
|
-
def cached_resized_img_abs_path
|
90
|
-
File.join(cache_dir, middleman_abs_path).gsub(image_name, resized_image_name).split('.').tap { |a|
|
91
|
-
a.insert(-2, image_checksum)
|
92
|
-
}.join('.')
|
93
|
-
end
|
94
|
-
|
95
100
|
def cached_thumbnail_available?
|
96
101
|
File.exist?(cached_resized_img_abs_path)
|
97
102
|
end
|
@@ -114,7 +119,7 @@ module MiddlemanSimpleThumbnailer
|
|
114
119
|
end
|
115
120
|
|
116
121
|
def cache_dir
|
117
|
-
File.absolute_path(
|
122
|
+
File.absolute_path(@options.cache_dir, @app.root)
|
118
123
|
end
|
119
124
|
end
|
120
125
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MiddlemanSimpleThumbnailer
|
2
|
+
class Resource < ::Middleman::Sitemap::Resource
|
3
|
+
def initialize(store, path, source)
|
4
|
+
super(store, path, source)
|
5
|
+
end
|
6
|
+
|
7
|
+
def ignored?
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
def template?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
def binary?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ['niewczas.jakub@gmail.com']
|
10
10
|
s.homepage = 'https://github.com/kubenstein/middleman-simple-thumbnailer'
|
11
11
|
s.license = 'MIT'
|
12
|
-
s.summary = %q{Middleman extension that allows you to create image thumbnails
|
12
|
+
s.summary = %q{Middleman extension that allows you to create image thumbnails}
|
13
13
|
s.description = %q{Middleman extension that allows you to create image thumbnails by providing resize_to option to image_tag helper}
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
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.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Niewczas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -126,8 +126,20 @@ files:
|
|
126
126
|
- features/generate_image_thumbnails.feature
|
127
127
|
- features/generate_image_thumbnails_image_path.feature
|
128
128
|
- features/generate_image_thumbnails_relative_assets.feature
|
129
|
+
- features/generate_new_data_file.feature
|
130
|
+
- features/given_data_file.feature
|
129
131
|
- features/support/env.rb
|
130
132
|
- features/support/image_thumbnails_steps.rb
|
133
|
+
- fixtures/basic-app-data-file-generate/config.rb
|
134
|
+
- fixtures/basic-app-data-file-generate/source/images/original.jpg
|
135
|
+
- fixtures/basic-app-data-file-generate/source/page-with-images-to-resize.html.erb
|
136
|
+
- fixtures/basic-app-data-file-generate/source/page-with-untouched-image.html.erb
|
137
|
+
- fixtures/basic-app-data-file/config.rb
|
138
|
+
- fixtures/basic-app-data-file/data/simple_thumbnailer.yml
|
139
|
+
- fixtures/basic-app-data-file/source/images/original.jpg
|
140
|
+
- fixtures/basic-app-data-file/source/page-with-images-to-resize.html.erb
|
141
|
+
- fixtures/basic-app-data-file/source/page-with-untouched-image.html.erb
|
142
|
+
- fixtures/basic-app-data-file/source/sitemap.html.erb
|
131
143
|
- fixtures/basic-app-image-path/config.rb
|
132
144
|
- fixtures/basic-app-image-path/source/images/original.jpg
|
133
145
|
- fixtures/basic-app-image-path/source/page-with-images-to-resize.html.erb
|
@@ -159,6 +171,7 @@ files:
|
|
159
171
|
- lib/middleman-simple-thumbnailer/extension.rb
|
160
172
|
- lib/middleman-simple-thumbnailer/image.rb
|
161
173
|
- lib/middleman-simple-thumbnailer/image_store.rb
|
174
|
+
- lib/middleman-simple-thumbnailer/resource.rb
|
162
175
|
- lib/middleman-simple-thumbnailer/version.rb
|
163
176
|
- middleman-simple-thumbnailer.gemspec
|
164
177
|
homepage: https://github.com/kubenstein/middleman-simple-thumbnailer
|
@@ -184,15 +197,26 @@ rubyforge_project:
|
|
184
197
|
rubygems_version: 2.6.8
|
185
198
|
signing_key:
|
186
199
|
specification_version: 4
|
187
|
-
summary: Middleman extension that allows you to create image thumbnails
|
188
|
-
resize_to option to image_tag helper
|
200
|
+
summary: Middleman extension that allows you to create image thumbnails
|
189
201
|
test_files:
|
190
202
|
- features/caching_thumbnails_in_development.feature
|
191
203
|
- features/generate_image_thumbnails.feature
|
192
204
|
- features/generate_image_thumbnails_image_path.feature
|
193
205
|
- features/generate_image_thumbnails_relative_assets.feature
|
206
|
+
- features/generate_new_data_file.feature
|
207
|
+
- features/given_data_file.feature
|
194
208
|
- features/support/env.rb
|
195
209
|
- features/support/image_thumbnails_steps.rb
|
210
|
+
- fixtures/basic-app-data-file-generate/config.rb
|
211
|
+
- fixtures/basic-app-data-file-generate/source/images/original.jpg
|
212
|
+
- fixtures/basic-app-data-file-generate/source/page-with-images-to-resize.html.erb
|
213
|
+
- fixtures/basic-app-data-file-generate/source/page-with-untouched-image.html.erb
|
214
|
+
- fixtures/basic-app-data-file/config.rb
|
215
|
+
- fixtures/basic-app-data-file/data/simple_thumbnailer.yml
|
216
|
+
- fixtures/basic-app-data-file/source/images/original.jpg
|
217
|
+
- fixtures/basic-app-data-file/source/page-with-images-to-resize.html.erb
|
218
|
+
- fixtures/basic-app-data-file/source/page-with-untouched-image.html.erb
|
219
|
+
- fixtures/basic-app-data-file/source/sitemap.html.erb
|
196
220
|
- fixtures/basic-app-image-path/config.rb
|
197
221
|
- fixtures/basic-app-image-path/source/images/original.jpg
|
198
222
|
- fixtures/basic-app-image-path/source/page-with-images-to-resize.html.erb
|