lazyload-rails 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: acc10ee27e56b6596896e9cb5875175feea8d785
4
+ data.tar.gz: b07b92855c6db5f0a3b46ea80b9384415e2f0ffc
5
+ SHA512:
6
+ metadata.gz: e5787e4b5f1f6bc45899d45344d0af6714066dee49251c117cfd065b6f05fd92382e83a48e711bcabaa0c3473b4c0c1c6d440645535d4bd8f10073dcb877f272
7
+ data.tar.gz: a4a9ab28ea4bfd036ca3315ee6d740d028fbfa4ef32c45a1afaab581c06428a8a0bfba41dc363301fe81163b8b90241c57533b6643e44b556d08eb126871a10e
data/README.md CHANGED
@@ -17,13 +17,13 @@ See [example](http://backbonejs.org/#examples) (scroll down to see images load)
17
17
 
18
18
  ### Features
19
19
 
20
- * Automatically get Rails `image_tag` helpers to render lazyload-friendly
21
- html img tags.
20
+ * Add `lazy: true` option to Rails `image_tag` helpers to render lazyload-friendly
21
+ -html img tags.
22
22
  * Simple, really. That's pretty much it.
23
23
 
24
24
  ### Example
25
25
 
26
- <%= image_tag "kittenz.png", alt: "OMG a cat!" %>
26
+ <%= image_tag "kittenz.png", alt: "OMG a cat!", lazy: true %>
27
27
 
28
28
  Equals:
29
29
 
@@ -32,15 +32,37 @@ module Lazyload
32
32
  end
33
33
 
34
34
  ActionView::Helpers::AssetTagHelper.module_eval do
35
- alias :x_image_tag :image_tag
35
+ alias :rails_image_tag :image_tag
36
36
 
37
37
  def image_tag(*attrs)
38
- placeholder = Lazyload::Rails.configuration.placeholder
39
- img = Nokogiri::HTML::DocumentFragment.parse(x_image_tag(*attrs)).at_css("img")
40
- src = img["src"]
38
+ options, args = extract_options_and_args(*attrs)
39
+ image_html = rails_image_tag(*args)
40
+
41
+ if options[:lazy]
42
+ to_lazy_image(image_html)
43
+ else
44
+ image_html
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def to_lazy_image(image_html)
51
+ img = Nokogiri::HTML::DocumentFragment.parse(image_html).at_css("img")
52
+
53
+ img["data-original"] = img["src"]
54
+ img["src"] = Lazyload::Rails.configuration.placeholder
41
55
 
42
- img["src"] = placeholder
43
- img["data-original"] = src
44
56
  img.to_s.html_safe
45
57
  end
58
+
59
+ def extract_options_and_args(*attrs)
60
+ options = attrs.last.dup
61
+ args = attrs
62
+
63
+ args.last.delete(:lazy)
64
+
65
+ [options, args]
66
+ end
67
+
46
68
  end
@@ -1,5 +1,5 @@
1
1
  module Lazyload
2
2
  module Rails
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazyload-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Javier Saldana
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-29 00:00:00.000000000 Z
11
+ date: 2014-11-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nokogiri
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.5'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.5'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: actionpack
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '3.1'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '3.1'
46
41
  description: lazyload-rails project integrates jQuery Lazy Load Plugin for Rails image_tag
@@ -50,34 +45,33 @@ executables: []
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  files:
53
- - README.md
54
48
  - MIT-LICENSE
49
+ - README.md
50
+ - lib/lazyload-rails.rb
55
51
  - lib/lazyload-rails/configuration.rb
56
52
  - lib/lazyload-rails/version.rb
57
- - lib/lazyload-rails.rb
58
53
  homepage: https://github.com/jassa/lazyload-rails
59
54
  licenses:
60
55
  - MIT
56
+ metadata: {}
61
57
  post_install_message:
62
58
  rdoc_options: []
63
59
  require_paths:
64
60
  - lib
65
61
  required_ruby_version: !ruby/object:Gem::Requirement
66
- none: false
67
62
  requirements:
68
- - - ! '>='
63
+ - - ">="
69
64
  - !ruby/object:Gem::Version
70
65
  version: '0'
71
66
  required_rubygems_version: !ruby/object:Gem::Requirement
72
- none: false
73
67
  requirements:
74
- - - ! '>='
68
+ - - ">="
75
69
  - !ruby/object:Gem::Version
76
70
  version: '0'
77
71
  requirements: []
78
72
  rubyforge_project:
79
- rubygems_version: 1.8.23
73
+ rubygems_version: 2.2.2
80
74
  signing_key:
81
- specification_version: 3
75
+ specification_version: 4
82
76
  summary: jQuery Lazy Load for Rails image_tag helpers
83
77
  test_files: []