middleman-async-image 0.0.1 → 0.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: b79a5d5c6b42ad27c77b3ff63f5f3432e37e0fde
4
- data.tar.gz: e5539a9e1455be03aa3cf3e9ef0fe86bc7150a65
3
+ metadata.gz: 2695b7fdcd355ab7149c49eba1eb6d8c07f714c8
4
+ data.tar.gz: 4b3fd03f53092eadabf83271543462e507546f93
5
5
  SHA512:
6
- metadata.gz: d241d8f39f5c368b1c57656ff57f043f5d2e135d62d8ce36726dc3478f7a03b7e46744ff9a7ab82dc2faf73500282a0e5483e744b5df1c8ba8de97fd8ac77e5a
7
- data.tar.gz: e583f8da7d4174173b9c947960a8bf66d9111d7fd58dadaaf3a9a331774689cd128d4ecb0a4e74dcc90c80c9de1f98f4f96e2f8515da678e37a621edac76c538
6
+ metadata.gz: e59ccc7fd382cf9a201806d9f99883ec619b6af583bd8f71de8feba6f7a9d738385147df1cd11e5fc87a942cf11da0846f2cae339bf03b6b83fcc1f388ffd065
7
+ data.tar.gz: 3865e1b878b21dc532f16c2e09d511aab6825c0eedf2a86efff0ccfbaab31857440231eb940e224a46c9d87ed47530b1660978e2daf4878dcd8c7473dbfbfc8e
data/README.md CHANGED
@@ -1,14 +1,38 @@
1
1
  # Middleman Async Image
2
2
  Load your images asynchronously with Middleman : like Medium.
3
3
 
4
+ ![demo](demo.gif?raw=true)
5
+
4
6
  ## Why?
5
7
  Because loading images on poor connections is really ugly. Medium as a great image loader so I develop a Gem to make it same as Middleman.
6
8
 
9
+ ## But how exactly it works ?
10
+ This gem detect when you want to load an image asynchronously (when you're using the helper). It going to duplicate it, with really strong compression and scale in a separate folder. Then, a JS function will load the poor quality image firstly, and the HQ image asynchronously. When the great image will be loaded, the other image will disappear.
11
+
12
+ All you need to do, is using the following helper:
13
+ ```
14
+ image_async_tag(path, options)
15
+ ```
16
+ it works exactly as the middleman image_tag default helper.
17
+
18
+ ## Dependencies
19
+ Middleman Async Image need [middleman-sprockets](https://github.com/middleman/middleman-sprockets/).
20
+ Go to your GemFile and set the following line wherever you want:
21
+ ```
22
+ gem "middleman-sprockets"
23
+ ```
24
+ then, set `activate :sprockets` in your config.rb.
25
+
7
26
  ## Configuration
8
27
  You can set the image-dir of your choice (follow the Middleman assets directories configuration).
9
28
 
10
29
  Simple configuration: just add `gem 'middleman-async-image'` to your __Gemfile__ and `activate :async_image` to your __config.rb__. If will work whatever your images dir.
11
30
 
31
+ Then, go to your main CSS file and set `//= require async-image`. Do the same in your JS application'file.
32
+
33
+
34
+ ### Options
35
+
12
36
  By default, compressed images are stored in the *compress* dir in your image folder. If you want to name this dir differently : add the following configuration to your __config.rb__:
13
37
  ```RUBY
14
38
  activate :async_image do |i|
@@ -19,13 +43,11 @@ end
19
43
  By default again, the compression level is *low (15)*. If you want to use a different one, you can configure it as the following:
20
44
  ```RUBY
21
45
  activate :async_image do |i|
22
- i.quality = "medium"
46
+ i.quality = 10
23
47
  end
24
48
  ```
25
- List of options:
26
- - Low: 10
27
- - Medium: 25
28
- - High: 35
49
+
50
+ You can else set the scale as you want, using `i.scale` but we do not recommand to use this parameter if you don't know how to use it. By default it's by *.3*.
29
51
 
30
52
  ## Contributing
31
53
 
Binary file
@@ -21,7 +21,7 @@ class AsyncImage < ::Middleman::Extension
21
21
  end
22
22
 
23
23
  def compress_dir
24
- dir = "source/#{app.config[:images_dir]}/" + AsyncImage.config[:compress_image_path]
24
+ dir = "source/#{app.config[:images_dir]}/" + extensions[:async_image].options[:compress_image_path]
25
25
  unless Dir.exists?(dir)
26
26
  FileUtils.mkdir(dir)
27
27
  end
@@ -34,15 +34,15 @@ class AsyncImage < ::Middleman::Extension
34
34
 
35
35
  helpers do
36
36
  def image_async_tag(path, params={})
37
- complete_path = "source/#{app.config[:images_dir]}/" + AsyncImage.config[:compress_image_path] + '/' + path
37
+ complete_path = "source/#{app.config[:images_dir]}/" + extensions[:async_image].options[:compress_image_path] + '/' + path
38
38
  FileUtils.mkdir_p(complete_path.match(/(.*\/)+(.*$)/)[1])
39
39
 
40
40
  Magick::Image::read("source/#{app.config[:images_dir]}/" + path)[0]
41
- .scale(AsyncImage.config[:scale])
42
- .write(complete_path){|f| f.quality = AsyncImage.config[:quality] }
41
+ .scale(extensions[:async_image].options[:scale])
42
+ .write(complete_path){|f| f.quality = extensions[:async_image].options[:quality] }
43
43
  print(path + ' has been compressed')
44
44
 
45
- params['data-compress'] = image_path(AsyncImage.config[:compress_image_path] + '/' + path)
45
+ params['data-compress'] = image_path(extensions[:async_image].options[:compress_image_path] + '/' + path)
46
46
  begin
47
47
  params[:class] += ' async-image'
48
48
  rescue
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "middleman-async-image"
6
- s.version = "0.0.1"
6
+ s.version = "0.0.2"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Bastien Robert"]
9
9
  # s.email = ["email@example.com"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-async-image
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bastien Robert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-24 00:00:00.000000000 Z
11
+ date: 2017-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -50,6 +50,7 @@ files:
50
50
  - README.md
51
51
  - Rakefile
52
52
  - TODO.md
53
+ - demo.gif
53
54
  - features/support/env.rb
54
55
  - lib/middleman-async-image.rb
55
56
  - lib/middleman-async-image/extension.rb